Skip to content

Commit

Permalink
Fix enqueue_kernel translation
Browse files Browse the repository at this point in the history
Set HasEvents to true if event_ret is not NULL.
  • Loading branch information
wenju-he authored and svenvh committed Sep 23, 2019
1 parent e49a539 commit bfcb738
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/SPIRV/SPIRVReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2086,10 +2086,14 @@ Instruction *SPIRVToLLVM::transEnqueueKernelBI(SPIRVInstruction *BI,
auto Ops = BI->getOperands();
bool HasVaargs = Ops.size() > 10;
bool HasEvents = true;
SPIRVValue *NumEvents = Ops[3];
if (NumEvents->getOpCode() == OpConstant) {
SPIRVConstant *NE = static_cast<SPIRVConstant *>(NumEvents);
HasEvents = NE->getZExtIntValue() != 0;
SPIRVValue *EventRet = Ops[5];
if (EventRet->getOpCode() == OpConstantNull) {
SPIRVValue *NumEvents = Ops[3];
if (NumEvents->getOpCode() == OpConstant) {
SPIRVConstant *NE = static_cast<SPIRVConstant *>(NumEvents);
HasEvents = NE->getZExtIntValue() != 0;
} else if (NumEvents->getOpCode() == OpConstantNull)
HasEvents = false;
}

std::string FName = "";
Expand Down
22 changes: 22 additions & 0 deletions test/transcoding/enqueue_kernel.cl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// CHECK-SPIRV: EntryPoint {{[0-9]+}} [[BlockKer2:[0-9]+]] "__device_side_enqueue_block_invoke_2_kernel"
// CHECK-SPIRV: EntryPoint {{[0-9]+}} [[BlockKer3:[0-9]+]] "__device_side_enqueue_block_invoke_3_kernel"
// CHECK-SPIRV: EntryPoint {{[0-9]+}} [[BlockKer4:[0-9]+]] "__device_side_enqueue_block_invoke_4_kernel"
// CHECK-SPIRV: EntryPoint {{[0-9]+}} [[BlockKer5:[0-9]+]] "__device_side_enqueue_block_invoke_5_kernel"
// CHECK-SPIRV: Name [[BlockGlb1:[0-9]+]] "__block_literal_global"
// CHECK-SPIRV: Name [[BlockGlb2:[0-9]+]] "__block_literal_global.1"

Expand Down Expand Up @@ -41,6 +42,7 @@
// CHECK-LLVM: @__block_literal_global.1 = internal addrspace(1) constant [[BlockTy1]] { i32 12, i32 4, i8 addrspace(4)* addrspacecast (i8* null to i8 addrspace(4)*) }, align 4

typedef struct {int a;} ndrange_t;
#define NULL ((void*)0)

kernel void device_side_enqueue(global int *a, global int *b, int i, char c0) {
queue_t default_queue;
Expand Down Expand Up @@ -127,14 +129,34 @@ kernel void device_side_enqueue(global int *a, global int *b, int i, char c0) {
return;
},
1, 2, 4);

// Emits block literal on stack and block kernel.

// CHECK-SPIRV: PtrCastToGeneric [[EventPtrTy]] [[Event1:[0-9]+]]

// CHECK-SPIRV: PtrCastToGeneric [[Int8PtrGenTy]] [[BlockLit2:[0-9]+]]
// CHECK-SPIRV: EnqueueKernel [[Int32Ty]] {{[0-9]+}} {{[0-9]+}} {{[0-9]+}} {{[0-9]+}}
// [[ConstInt0]] [[EventNull]] [[Event1]]
// [[BlockKer5]] [[BlockLit5]] [[ConstInt20]] [[ConstInt8]]

// CHECK-LLVM: [[Block5:%[0-9]+]] = bitcast [[BlockTy3]]* %block14 to %struct.__opencl_block_literal_generic*
// CHECK-LLVM: [[Block5Ptr:%[0-9]+]] = addrspacecast %struct.__opencl_block_literal_generic* [[Block5]] to i8 addrspace(4)
// CHECK-LLVM: [[BlockInv5:%[0-9]+]] = addrspacecast void (i8 addrspace(4)*)* @__device_side_enqueue_block_invoke_5_kernel to i8 addrspace(4)*
// CHECK-LLVM: call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* {{.*}}, i32 {{.*}}, %struct.ndrange_t* {{.*}}, i32 0, %opencl.clk_event_t* addrspace(4)* null, %opencl.clk_event_t* addrspace(4)* {{.*}}, i8 addrspace(4)* [[BlockInv5]], i8 addrspace(4)* [[Block5Ptr]])
enqueue_kernel(default_queue, flags, ndrange, 0, NULL, &clk_event,
^(void) {
a[i] = b[i];
});
}

// CHECK-SPIRV-DAG: Function [[VoidTy]] [[BlockKer1]] 0 [[BlockTy1]]
// CHECK-SPIRV-DAG: Function [[VoidTy]] [[BlockKer2]] 0 [[BlockTy1]]
// CHECK-SPIRV-DAG: Function [[VoidTy]] [[BlockKer3]] 0 [[BlockTy2]]
// CHECK-SPIRV-DAG: Function [[VoidTy]] [[BlockKer4]] 0 [[BlockTy3]]
// CHECK-SPIRV-DAG: Function [[VoidTy]] [[BlockKer5]] 0 [[BlockTy1]]

// CHECK-LLVM-DAG: define spir_kernel void @__device_side_enqueue_block_invoke_kernel(i8 addrspace(4)*{{.*}})
// CHECK-LLVM-DAG: define spir_kernel void @__device_side_enqueue_block_invoke_2_kernel(i8 addrspace(4)*{{.*}})
// CHECK-LLVM-DAG: define spir_kernel void @__device_side_enqueue_block_invoke_3_kernel(i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}})
// CHECK-LLVM-DAG: define spir_kernel void @__device_side_enqueue_block_invoke_4_kernel(i8 addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}}, i8 addrspace(3)*{{.*}}, i8 addrspace(3)*{{.*}})
// CHECK-LLVM-DAG: define spir_kernel void @__device_side_enqueue_block_invoke_5_kernel(i8 addrspace(4)*{{.*}})

0 comments on commit bfcb738

Please sign in to comment.