Skip to content

Commit

Permalink
Change CUDA tests to use print_memref.
Browse files Browse the repository at this point in the history
Swap dimensions in all-reduce-op test.

PiperOrigin-RevId: 281791744
  • Loading branch information
chsigg authored and tensorflower-gardener committed Nov 21, 2019
1 parent c621e64 commit d7c1719
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 31 deletions.
18 changes: 9 additions & 9 deletions mlir/test/mlir-cuda-runner/all-reduce-op.mlir
@@ -1,13 +1,13 @@
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext --entry-point-result=void | FileCheck %s
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s

// CHECK: [5.356000e+03, 5.356000e+03, {{.*}}, 5.356000e+03, 5.356000e+03]
// CHECK-COUNT-8: [{{(5356, ){12}5356}}]
func @main() {
%arg = alloc() : memref<13x4x2xf32>
%dst = memref_cast %arg : memref<13x4x2xf32> to memref<?x?x?xf32>
%arg = alloc() : memref<2x4x13xf32>
%dst = memref_cast %arg : memref<2x4x13xf32> to memref<?x?x?xf32>
%one = constant 1 : index
%sx = dim %dst, 0 : memref<?x?x?xf32>
%sx = dim %dst, 2 : memref<?x?x?xf32>
%sy = dim %dst, 1 : memref<?x?x?xf32>
%sz = dim %dst, 2 : memref<?x?x?xf32>
%sz = dim %dst, 0 : memref<?x?x?xf32>
call @mcuMemHostRegisterMemRef3dFloat(%dst) : (memref<?x?x?xf32>) -> ()
gpu.launch blocks(%bx, %by, %bz) in (%grid_x = %one, %grid_y = %one, %grid_z = %one)
threads(%tx, %ty, %tz) in (%block_x = %sx, %block_y = %sy, %block_z = %sz)
Expand All @@ -19,12 +19,12 @@ func @main() {
%t3 = index_cast %idx : index to i32
%val = sitofp %t3 : i32 to f32
%sum = "gpu.all_reduce"(%val) ({}) { op = "add" } : (f32) -> (f32)
store %sum, %kernel_dst[%tx, %ty, %tz] : memref<?x?x?xf32>
store %sum, %kernel_dst[%tz, %ty, %tx] : memref<?x?x?xf32>
gpu.return
}
call @mcuPrintFloat(%dst) : (memref<?x?x?xf32>) -> ()
call @print_memref_3d_f32(%dst) : (memref<?x?x?xf32>) -> ()
return
}

func @mcuMemHostRegisterMemRef3dFloat(%ptr : memref<?x?x?xf32>)
func @mcuPrintFloat(%ptr : memref<?x?x?xf32>)
func @print_memref_3d_f32(%ptr : memref<?x?x?xf32>)
8 changes: 4 additions & 4 deletions mlir/test/mlir-cuda-runner/all-reduce-region.mlir
@@ -1,6 +1,6 @@
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext --entry-point-result=void | FileCheck %s
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s

// CHECK: [3.500000e+01, 3.500000e+01, {{.*}}, 3.500000e+01, 3.500000e+01]
// CHECK: [{{(35, ){34}35}}]
func @main() {
%arg = alloc() : memref<35xf32>
%dst = memref_cast %arg : memref<35xf32> to memref<?xf32>
Expand All @@ -20,9 +20,9 @@ func @main() {
store %res, %kernel_dst[%tx] : memref<?xf32>
gpu.return
}
call @mcuPrintFloat(%dst) : (memref<?xf32>) -> ()
call @print_memref_1d_f32(%dst) : (memref<?xf32>) -> ()
return
}

func @mcuMemHostRegisterMemRef1dFloat(%ptr : memref<?xf32>)
func @mcuPrintFloat(%ptr : memref<?xf32>)
func @print_memref_1d_f32(memref<?xf32>)
10 changes: 5 additions & 5 deletions mlir/test/mlir-cuda-runner/gpu-to-cubin.mlir
@@ -1,4 +1,4 @@
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext --entry-point-result=void | FileCheck %s
// RUN: mlir-cuda-runner %s --shared-libs=%cuda_wrapper_library_dir/libcuda-runtime-wrappers%shlibext,%linalg_test_lib_dir/libmlir_runner_utils%shlibext --entry-point-result=void | FileCheck %s

func @other_func(%arg0 : f32, %arg1 : memref<?xf32>) {
%cst = constant 1 : index
Expand All @@ -12,18 +12,18 @@ func @other_func(%arg0 : f32, %arg1 : memref<?xf32>) {
return
}

// CHECK: [1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00, 1.000000e+00]
// CHECK: [1, 1, 1, 1, 1]
func @main() {
%arg0 = alloc() : memref<5xf32>
%21 = constant 5 : i32
%22 = memref_cast %arg0 : memref<5xf32> to memref<?xf32>
call @mcuMemHostRegisterMemRef1dFloat(%22) : (memref<?xf32>) -> ()
call @mcuPrintFloat(%22) : (memref<?xf32>) -> ()
call @print_memref_1d_f32(%22) : (memref<?xf32>) -> ()
%24 = constant 1.0 : f32
call @other_func(%24, %22) : (f32, memref<?xf32>) -> ()
call @mcuPrintFloat(%22) : (memref<?xf32>) -> ()
call @print_memref_1d_f32(%22) : (memref<?xf32>) -> ()
return
}

func @mcuMemHostRegisterMemRef1dFloat(%ptr : memref<?xf32>)
func @mcuPrintFloat(%ptr : memref<?xf32>)
func @print_memref_1d_f32(memref<?xf32>)
13 changes: 0 additions & 13 deletions mlir/tools/mlir-cuda-runner/cuda-runtime-wrappers.cpp
Expand Up @@ -113,16 +113,3 @@ extern "C" void
mcuMemHostRegisterMemRef3dFloat(const MemRefType<float, 3> *arg) {
mcuMemHostRegisterMemRef(arg, 1.23f);
}

/// Prints the given float array to stderr.
extern "C" void mcuPrintFloat(const MemRefType<float, 1> *arg) {
if (arg->sizes[0] == 0) {
llvm::outs() << "[]\n";
return;
}
llvm::outs() << "[" << arg->data[0];
for (int pos = 1; pos < arg->sizes[0]; pos++) {
llvm::outs() << ", " << arg->data[pos];
}
llvm::outs() << "]\n";
}

0 comments on commit d7c1719

Please sign in to comment.