Skip to content

OpenCL: Excessive kernel arguments #535

Open
@linehill

Description

@linehill

clGetKernelInfo() incorrectly reports that the saxpy kernel, as shown in the following SPIR-V listing, has eight kernel arguments instead of four - the original amount.

; A test case that triggers an issues in Intel's OpenCL.
;
;  * With Intel Compute Runtime version 21.49.21786 the 'saxpy' kernel appears
;    in a different name (e.g. to "saxpy.1").
;
;  * With Intel Compute Runtime version 22.16.22992 the 'saxpy' appears to have
;    eight kernel arguments instead of four.
;
; The issue disappears in both versions if both the 'OpName %saxpy "saxpy"' and
; 'OpDecorate %saxpy LinkageAttributes "saxpy" Export' instructions are removed.
;
; Generated originally from OpenCL:
;
;   kernel void saxpy(global float *z, global const float *x,
;                     global const float *y, float a) {
;     size_t id = get_global_id(0);
;     z[id] = a * x[id] + y[id];
;   }
;
; Assemble with command:
;
;  spirv-as --target-env opencl2.0 saxpy-kernel.spt -o saxpy-kernel.spv
;
               OpCapability Addresses
               OpCapability Linkage
               OpCapability Kernel
               OpCapability Int64
          %1 = OpExtInstImport "OpenCL.std"
               OpMemoryModel Physical64 OpenCL
               OpEntryPoint Kernel %24 "saxpy" %__spirv_BuiltInGlobalInvocationId
               OpSource OpenCL_C 200000
               OpName %__spirv_BuiltInGlobalInvocationId "__spirv_BuiltInGlobalInvocationId"
               OpName %saxpy "saxpy"
               OpName %z "z"
               OpName %x "x"
               OpName %y "y"
               OpName %a "a"
               OpName %entry "entry"
               OpName %call "call"
               OpName %arrayidx "arrayidx"
               OpName %arrayidx1 "arrayidx1"
               OpName %arrayidx2 "arrayidx2"
               OpName %z_0 "z"
               OpName %x_0 "x"
               OpName %y_0 "y"
               OpName %a_0 "a"
               OpDecorate %__spirv_BuiltInGlobalInvocationId LinkageAttributes "__spirv_BuiltInGlobalInvocationId" Import
               OpDecorate %__spirv_BuiltInGlobalInvocationId Constant
               OpDecorate %__spirv_BuiltInGlobalInvocationId BuiltIn GlobalInvocationId
               OpDecorate %saxpy LinkageAttributes "saxpy" Export
               OpDecorate %z FuncParamAttr NoCapture
               OpDecorate %x FuncParamAttr NoCapture
               OpDecorate %x FuncParamAttr NoWrite
               OpDecorate %y FuncParamAttr NoCapture
               OpDecorate %y FuncParamAttr NoWrite
               OpDecorate %z_0 FuncParamAttr NoCapture
               OpDecorate %x_0 FuncParamAttr NoCapture
               OpDecorate %x_0 FuncParamAttr NoWrite
               OpDecorate %y_0 FuncParamAttr NoCapture
               OpDecorate %y_0 FuncParamAttr NoWrite
      %ulong = OpTypeInt 64 0
    %v3ulong = OpTypeVector %ulong 3
%_ptr_Input_v3ulong = OpTypePointer Input %v3ulong
       %void = OpTypeVoid
      %float = OpTypeFloat 32
%_ptr_CrossWorkgroup_float = OpTypePointer CrossWorkgroup %float
          %9 = OpTypeFunction %void %_ptr_CrossWorkgroup_float %_ptr_CrossWorkgroup_float %_ptr_CrossWorkgroup_float %float
%__spirv_BuiltInGlobalInvocationId = OpVariable %_ptr_Input_v3ulong Input
      %saxpy = OpFunction %void None %9
          %z = OpFunctionParameter %_ptr_CrossWorkgroup_float
          %x = OpFunctionParameter %_ptr_CrossWorkgroup_float
          %y = OpFunctionParameter %_ptr_CrossWorkgroup_float
          %a = OpFunctionParameter %float
      %entry = OpLabel
         %16 = OpLoad %v3ulong %__spirv_BuiltInGlobalInvocationId Aligned 32
       %call = OpCompositeExtract %ulong %16 0
   %arrayidx = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %x %call
         %19 = OpLoad %float %arrayidx Aligned 4
  %arrayidx1 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %y %call
         %21 = OpLoad %float %arrayidx1 Aligned 4
         %22 = OpExtInst %float %1 mad %a %19 %21
  %arrayidx2 = OpInBoundsPtrAccessChain %_ptr_CrossWorkgroup_float %z %call
               OpStore %arrayidx2 %22 Aligned 4
               OpReturn
               OpFunctionEnd
         %24 = OpFunction %void None %9
        %z_0 = OpFunctionParameter %_ptr_CrossWorkgroup_float
        %x_0 = OpFunctionParameter %_ptr_CrossWorkgroup_float
        %y_0 = OpFunctionParameter %_ptr_CrossWorkgroup_float
        %a_0 = OpFunctionParameter %float
         %29 = OpLabel
         %30 = OpFunctionCall %void %saxpy %z_0 %x_0 %y_0 %a_0
               OpReturn
               OpFunctionEnd

Attempting to launch the kernel with the original amount of arguments fails too.

The code was originally generated by the latest llvm-spirv tool from the llvm_release_140. The issue disappears if both the OpName %saxpy "saxpy" and “OpDecorate %saxpy LinkageAttributes "saxpy" Export” lines are removed from the code.

Test environment:
OS: Ubuntu 20.04.4 LTS
Intel Compute Runtime: 22.16.22992.
Device: Intel(R) HD Graphics 530 [0x1912].

Metadata

Metadata

Assignees

No one assigned

    Labels

    IGCIssue related to IGC

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions