brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.1 KiB · c61640c Raw
200 lines · plain
1// RUN: mlir-opt %s -convert-math-to-xevm \2// RUN:   | FileCheck %s -check-prefixes='CHECK,CHECK-ARITH' 3// RUN: mlir-opt %s -convert-math-to-xevm='convert-arith=false' \4// RUN:   | FileCheck %s -check-prefixes='CHECK,CHECK-NO-ARITH'5 6// RUN: mlir-opt --pass-pipeline="builtin.module(convert-math-to-xevm)" %s \7// RUN:   | FileCheck %s -check-prefixes='CHECK-MODULE,CHECK-ENTIRE-MODULE'8// RUN: mlir-opt --pass-pipeline="builtin.module(gpu.module(convert-math-to-xevm))" %s \9// RUN:   | FileCheck %s -check-prefixes='CHECK-MODULE,CHECK-ONLY-GPU'10 11// This test:12// - check that MathToXeVM converts fastmath math/arith ops properly;13// - check that MathToXeVM handles nested modules while respecting pass manager.14 15module @test_module {16  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDh(f16) -> f1617  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f3218  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expd(f64) -> f6419  //20  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDv2_d(vector<2xf64>) -> vector<2xf64>21  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDv3_d(vector<3xf64>) -> vector<3xf64>22  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDv4_d(vector<4xf64>) -> vector<4xf64>23  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDv8_d(vector<8xf64>) -> vector<8xf64>24  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDv16_d(vector<16xf64>) -> vector<16xf64>25  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDv16_f(vector<16xf32>) -> vector<16xf32>26  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_expDv4_Dh(vector<4xf16>) -> vector<4xf16>27  //28  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_cosDh(f16) -> f1629  // CHECK-DAG: llvm.func @_Z23__spirv_ocl_native_exp2f(f32) -> f3230  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_logDh(f16) -> f1631  // CHECK-DAG: llvm.func @_Z23__spirv_ocl_native_log2f(f32) -> f3232  // CHECK-DAG: llvm.func @_Z24__spirv_ocl_native_log10d(f64) -> f6433  // CHECK-DAG: llvm.func @_Z23__spirv_ocl_native_powrDhDh(f16, f16) -> f1634  // CHECK-DAG: llvm.func @_Z24__spirv_ocl_native_rsqrtd(f64) -> f6435  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_sinDh(f16) -> f1636  // CHECK-DAG: llvm.func @_Z23__spirv_ocl_native_sqrtf(f32) -> f3237  // CHECK-DAG: llvm.func @_Z22__spirv_ocl_native_tand(f64) -> f6438  // CHECK-ARITH-DAG: llvm.func @_Z25__spirv_ocl_native_divideff(f32, f32) -> f3239 40  // CHECK-LABEL: func @math_ops41  func.func @math_ops() {42 43    %c1_f16 = arith.constant 1. : f1644    %c1_f32 = arith.constant 1. : f3245    %c1_f64 = arith.constant 1. : f6446 47    // CHECK: math.exp48    %exp_normal_f16 = math.exp %c1_f16 : f1649    // CHECK: math.exp50    %exp_normal_f32 = math.exp %c1_f32 : f3251    // CHECK: math.exp52    %exp_normal_f64 = math.exp %c1_f64 : f6453 54    // Check float operations are converted properly:55 56    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDh(%{{.*}}) {fastmathFlags = #llvm.fastmath<fast>} : (f16) -> f1657    %exp_fast_f16 = math.exp %c1_f16 fastmath<fast> : f1658    // CHECK: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<fast>} : (f32) -> f3259    %exp_fast_f32 = math.exp %c1_f32 fastmath<fast> : f3260    // CHECK: llvm.call @_Z22__spirv_ocl_native_expd(%{{.*}}) {fastmathFlags = #llvm.fastmath<fast>} : (f64) -> f6461    %exp_fast_f64 = math.exp %c1_f64 fastmath<fast> : f6462    63    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDh(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f16) -> f1664    %exp_afn_f16 = math.exp %c1_f16 fastmath<afn> : f1665    // CHECK: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f3266    %exp_afn_f32 = math.exp %c1_f32 fastmath<afn> : f3267    // CHECK: llvm.call @_Z22__spirv_ocl_native_expd(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f64) -> f6468    %exp_afn_f64 = math.exp %c1_f64 fastmath<afn> : f6469 70    // CHECK: math.exp71    %exp_none_f16 = math.exp %c1_f16 fastmath<none> : f1672    // CHECK: math.exp73    %exp_none_f32 = math.exp %c1_f32 fastmath<none> : f3274    // CHECK: math.exp75    %exp_none_f64 = math.exp %c1_f64 fastmath<none> : f6476 77    // Check vector operations:78 79    %v2_c1_f64 = arith.constant dense<1.> : vector<2xf64>80    %v3_c1_f64 = arith.constant dense<1.> : vector<3xf64>81    %v4_c1_f64 = arith.constant dense<1.> : vector<4xf64>82    %v8_c1_f64 = arith.constant dense<1.> : vector<8xf64>83    %v16_c1_f64 = arith.constant dense<1.> : vector<16xf64>84 85    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDv2_d(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (vector<2xf64>) -> vector<2xf64>86    %exp_v2_f64 = math.exp %v2_c1_f64 fastmath<afn> : vector<2xf64>87    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDv3_d(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (vector<3xf64>) -> vector<3xf64>88    %exp_v3_f64 = math.exp %v3_c1_f64 fastmath<afn> : vector<3xf64>89    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDv4_d(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (vector<4xf64>) -> vector<4xf64>90    %exp_v4_f64 = math.exp %v4_c1_f64 fastmath<afn> : vector<4xf64>91    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDv8_d(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (vector<8xf64>) -> vector<8xf64>92    %exp_v8_f64 = math.exp %v8_c1_f64 fastmath<afn> : vector<8xf64>93    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDv16_d(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (vector<16xf64>) -> vector<16xf64>94    %exp_v16_f64 = math.exp %v16_c1_f64 fastmath<afn> : vector<16xf64>95 96    %v16_c1_f32 = arith.constant dense<1.> : vector<16xf32>97    %v4_c1_f16 = arith.constant dense<1.> : vector<4xf16>98 99    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDv16_f(%{{.*}}) {fastmathFlags = #llvm.fastmath<fast>} : (vector<16xf32>) -> vector<16xf32>100    %exp_v16_f32 = math.exp %v16_c1_f32 fastmath<fast> : vector<16xf32>101    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDv4_Dh(%{{.*}}) {fastmathFlags = #llvm.fastmath<fast>} : (vector<4xf16>) -> vector<4xf16>102    %exp_v4_f16 = math.exp %v4_c1_f16 fastmath<fast> : vector<4xf16>103 104    // Check unsupported vector sizes are not converted:105 106    %v5_c1_f64 = arith.constant dense<1.> : vector<5xf64>107    %v32_c1_f64 = arith.constant dense<1.> : vector<32xf64>108 109    // CHECK: math.exp110    %exp_v5_f64 = math.exp %v5_c1_f64 fastmath<afn> : vector<5xf64>111    // CHECK: math.exp112    %exp_v32_f64 = math.exp %v32_c1_f64 fastmath<afn> : vector<32xf64>113 114    // Check fastmath flags propagate properly:115 116    // CHECK: llvm.call @_Z22__spirv_ocl_native_expDh(%{{.*}}) {fastmathFlags = #llvm.fastmath<fast>} : (f16) -> f16117    %exp_fastmath_all_f16 = math.exp %c1_f16 fastmath<reassoc,nnan,ninf,nsz,arcp,contract,afn> : f16118    // CHECK: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<nnan, ninf, nsz, arcp, contract, afn>} : (f32) -> f32119    %exp_fastmath_most_f32 = math.exp %c1_f32 fastmath<nnan,ninf,nsz,arcp,contract,afn> : f32120    // CHECK: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<nnan, afn, reassoc>} : (f32) -> f32121    %exp_afn_reassoc_nnan_f32 = math.exp %c1_f32 fastmath<afn,reassoc,nnan> : f32122 123    // Check all other math operations:124 125    // CHECK: llvm.call @_Z22__spirv_ocl_native_cosDh(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f16) -> f16126    %cos_afn_f16 = math.cos %c1_f16 fastmath<afn> : f16127 128    // CHECK: llvm.call @_Z23__spirv_ocl_native_exp2f(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32129    %exp2_afn_f32 = math.exp2 %c1_f32 fastmath<afn> : f32130 131    // CHECK: llvm.call @_Z22__spirv_ocl_native_logDh(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f16) -> f16132    %log_afn_f16 = math.log %c1_f16 fastmath<afn> : f16133 134    // CHECK: llvm.call @_Z23__spirv_ocl_native_log2f(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32135    %log2_afn_f32 = math.log2 %c1_f32 fastmath<afn> : f32136 137    // CHECK: llvm.call @_Z24__spirv_ocl_native_log10d(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f64) -> f64138    %log10_afn_f64 = math.log10 %c1_f64 fastmath<afn> : f64139 140    // CHECK: llvm.call @_Z23__spirv_ocl_native_powrDhDh(%{{.*}}, %{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f16, f16) -> f16141    %powr_afn_f16 = math.powf %c1_f16, %c1_f16 fastmath<afn> : f16142 143    // CHECK: llvm.call @_Z24__spirv_ocl_native_rsqrtd(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f64) -> f64144    %rsqrt_afn_f64 = math.rsqrt %c1_f64 fastmath<afn> : f64145 146    // CHECK: llvm.call @_Z22__spirv_ocl_native_sinDh(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f16) -> f16147    %sin_afn_f16 = math.sin %c1_f16 fastmath<afn> : f16148 149    // CHECK: llvm.call @_Z23__spirv_ocl_native_sqrtf(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32150    %sqrt_afn_f32 = math.sqrt %c1_f32 fastmath<afn> : f32151 152    // CHECK: llvm.call @_Z22__spirv_ocl_native_tand(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f64) -> f64153    %tan_afn_f64 = math.tan %c1_f64 fastmath<afn> : f64154 155    %c6_9_f32 = arith.constant 6.9 : f32156    %c7_f32 = arith.constant 7. : f32157 158    // CHECK-ARITH: llvm.call @_Z25__spirv_ocl_native_divideff(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32, f32) -> f32159    // CHECK-NO-ARITH: arith.divf160    %divf_afn_f32 = arith.divf %c6_9_f32, %c7_f32 fastmath<afn> : f32161 162    return163  }164 165  // Check that MathToXeVM handles nested modules while respecting pass manager:166 167  // CHECK-ENTIRE-MODULE: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32168  // CHECK-ONLY-GPU-NOT: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32169  170  // CHECK-MODULE-LABEL: @test_gpu171  gpu.module @test_gpu {172    // CHECK-MODULE: llvm.func @_Z22__spirv_ocl_native_expf(f32) -> f32173    gpu.func @exp_gpu() {174      %c1_f32 = arith.constant 1. : f32175 176      // CHECK-MODULE: math.exp177      %exp_normal_f32 = math.exp %c1_f32 : f32178 179      // CHECK-MODULE: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32180      %exp_fast_f32 = math.exp %c1_f32 fastmath<afn> : f32181 182      gpu.return183    }184  }185 186  // CHECK-MODULE-LABEL: @exp_func187  func.func @exp_func() {188    %c1_f32 = arith.constant 1. : f32189 190    // CHECK-MODULE: math.exp191    %exp_normal_f32 = math.exp %c1_f32 : f32192 193    // CHECK-ENTIRE-MODULE: llvm.call @_Z22__spirv_ocl_native_expf(%{{.*}}) {fastmathFlags = #llvm.fastmath<afn>} : (f32) -> f32194    // CHECK-ONLY-GPU: math.exp195    %exp_fast_f32 = math.exp %c1_f32 fastmath<afn> : f32196 197    return198  }199}200