intel / llvm

Intel staging area for llvm.org contribution. Home for Intel LLVM-based projects.
Other
1.21k stars 723 forks source link

Using `OpTypeBool` for kernel parameters is invalid according to OpenCL SPIR-V Env specification #11531

Open karolherbst opened 10 months ago

karolherbst commented 10 months ago

Describe the bug With some SyCL-CTS tests I'm seeing SPIR-V declaring OpTypeBool as Kernel function parameters, e.g. test_spec_constants. It might not be the best test to dig into this problem as it executes a lot of spirvs.

               OpEntryPoint Kernel %1337 "_ZTSN33specialization_constants_external6kernelIbLi1EEE" %__spirv_BuiltInWorkgroupId %__spirv_BuiltInGlobalLinearId %__spirv_BuiltInWorkgroupSize
...
       %bool = OpTypeBool
...
        %218 = OpTypeFunction %void %_ptr_CrossWorkgroup_uchar %_ptr_Function_class_sycl___V1__id %bool
...
       %1337 = OpFunction %void None %218
...
%_arg_ref_43 = OpFunctionParameter %bool

The OpenCL SPIR-V env specification states:

An OpFunctionParameter for an OpFunction that is identified with OpEntryPoint defines an OpenCL kernel argument. Allowed types for OpenCL kernel arguments are:

  • OpTypeInt
  • OpTypeFloat
  • OpTypeStruct
  • OpTypeVector
  • OpTypePointer
  • OpTypeSampler
  • OpTypeImage
  • OpTypePipe
  • OpTypeQueue

The problem with using OpTypeBool or bool in OpenCL C is, that its size is not defined by the OpenCL specification and hence calls to clSetKernelArg on arguments with a OpTypeBool parameter is undefined.

I suspect that just using OpTypeInt 8 0 might be a good alternative here.

To Reproduce Run SyCL-CTS test_spec_constants

Environment (please complete the following information):

maksimsab commented 10 months ago

@MrSidims @LU-JOHN FYI.

LU-JOHN commented 1 month ago

Reproduced issue with:

#include <sycl/sycl.hpp>

using namespace sycl;

class Test;

void do_test() {
  queue q;
  bool arg=false;
  uint8_t *Output = (uint8_t *)malloc_shared(sizeof(uint8_t), q.get_device(),
                                       q.get_context());

  q.submit([=](handler &cgh) {
    cgh.single_task<Test>([=]() {
      if (arg) Output[0]=75;
    });
  });
  q.wait();
}

SPIR-V kernel with TypeBool parm seen when compiling with:

clang++ -fsycl bool_parm.cpp -fsycl-device-only
llvm-spirv bool_parm-sycl-spir64-unknown-unknown.bc
llvm-spirv -to-text bool_parm-sycl-spir64-unknown-unknown.spv