Skip to content

Generated SPIR-V (non-linalg) fails with incorrect results on real nvidia device #1259

Closed

Description

@benvanik

Running this on Windows + 2080ti + latest whql drivers.
Scott confirms he can reproduce with a similar configuration.

The compare.mlir compare_tensor_odd_length fails (while the rest in that file succeed):

iree/test/e2e/xla/compare.mlir:125:11: error: CHECK: expected string not found in input
// CHECK: 3xi8=0 1 0
          ^
<stdin>:18:1: note: scanning from here
3xi8=0 0 0

Attached is a renderdoc capture. The buffers look correct (have the right values, are bound to the right bind points). Should be openable on RenderDoc 1.7 on Windows/Linux:
spirv_compare_tensor_odd_length_capture_nvidia.zip

I suspect this has to do with i8 handling. This may go away when using the linalg path, and maybe if linalg can support this we switch to that and call it closed. It would be good to understand why it's failing, though, to ensure we aren't doing something undefined.

Disassembled SPIR-V:

; SPIR-V
; Version: 1.0
; Generator: Khronos; 22
; Bound: 88
; Schema: 0
               OpCapability Shader
               OpExtension "SPV_KHR_storage_buffer_storage_class"
               OpMemoryModel Logical GLSL450
               OpEntryPoint GLCompute %compare_tensor_odd_length_ex_dispatch_0 "compare_tensor_odd_length_ex_dispatch_0" %__builtin_var_GlobalInvocationId__ %__builtin_var_NumWorkgroups__
               OpExecutionMode %compare_tensor_odd_length_ex_dispatch_0 LocalSize 32 1 1
               OpName %__builtin_var_NumWorkgroups__ "__builtin_var_NumWorkgroups__"
               OpName %__builtin_var_GlobalInvocationId__ "__builtin_var_GlobalInvocationId__"
               OpName %compare_tensor_odd_length_ex_dispatch_0_arg_0 "compare_tensor_odd_length_ex_dispatch_0_arg_0"
               OpName %compare_tensor_odd_length_ex_dispatch_0_arg_1 "compare_tensor_odd_length_ex_dispatch_0_arg_1"
               OpName %compare_tensor_odd_length_ex_dispatch_0_arg_2 "compare_tensor_odd_length_ex_dispatch_0_arg_2"
               OpName %compare_tensor_odd_length_ex_dispatch_0_arg_3 "compare_tensor_odd_length_ex_dispatch_0_arg_3"
               OpName %compare_tensor_odd_length_ex_dispatch_0_arg_4 "compare_tensor_odd_length_ex_dispatch_0_arg_4"
               OpName %compare_tensor_odd_length_ex_dispatch_0 "compare_tensor_odd_length_ex_dispatch_0"
               OpDecorate %__builtin_var_NumWorkgroups__ BuiltIn NumWorkgroups
               OpDecorate %__builtin_var_GlobalInvocationId__ BuiltIn GlobalInvocationId
               OpDecorate %_arr_uint_uint_3 ArrayStride 4
               OpMemberDecorate %_struct_7 0 Offset 0
               OpDecorate %_struct_7 Block
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_0 Binding 0
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_0 DescriptorSet 0
               OpDecorate %_struct_7 Block
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_1 Binding 1
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_1 DescriptorSet 0
               OpDecorate %_struct_7 Block
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_2 Binding 2
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_2 DescriptorSet 0
               OpDecorate %_struct_7 Block
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_3 Binding 3
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_3 DescriptorSet 0
               OpDecorate %_struct_7 Block
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_4 Binding 4
               OpDecorate %compare_tensor_odd_length_ex_dispatch_0_arg_4 DescriptorSet 0
       %uint = OpTypeInt 32 0
     %v3uint = OpTypeVector %uint 3
%_ptr_Input_v3uint = OpTypePointer Input %v3uint
%__builtin_var_NumWorkgroups__ = OpVariable %_ptr_Input_v3uint Input
%__builtin_var_GlobalInvocationId__ = OpVariable %_ptr_Input_v3uint Input
     %uint_3 = OpConstant %uint 3
%_arr_uint_uint_3 = OpTypeArray %uint %uint_3
  %_struct_7 = OpTypeStruct %_arr_uint_uint_3
%_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
%compare_tensor_odd_length_ex_dispatch_0_arg_0 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
%compare_tensor_odd_length_ex_dispatch_0_arg_1 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
%compare_tensor_odd_length_ex_dispatch_0_arg_2 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
%compare_tensor_odd_length_ex_dispatch_0_arg_3 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
%compare_tensor_odd_length_ex_dispatch_0_arg_4 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
       %void = OpTypeVoid
         %15 = OpTypeFunction %void
     %uint_1 = OpConstant %uint 1
    %uint_32 = OpConstant %uint 32
     %uint_0 = OpConstant %uint 0
     %uint_8 = OpConstant %uint 8
   %uint_255 = OpConstant %uint 255
     %uint_4 = OpConstant %uint 4
       %bool = OpTypeBool
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%compare_tensor_odd_length_ex_dispatch_0 = OpFunction %void None %15
         %18 = OpLabel
         %25 = OpLoad %v3uint %__builtin_var_GlobalInvocationId__
         %26 = OpCompositeExtract %uint %25 2
         %27 = OpLoad %v3uint %__builtin_var_NumWorkgroups__
         %28 = OpCompositeExtract %uint %27 2
               OpBranch %29
         %29 = OpLabel
         %32 = OpPhi %uint %26 %18 %87 %33
         %35 = OpSLessThan %bool %32 %uint_1
               OpLoopMerge %31 %30 None
               OpBranchConditional %35 %30 %31
         %30 = OpLabel
         %36 = OpLoad %v3uint %__builtin_var_GlobalInvocationId__
         %37 = OpCompositeExtract %uint %36 1
         %38 = OpLoad %v3uint %__builtin_var_NumWorkgroups__
         %39 = OpCompositeExtract %uint %38 1
               OpBranch %40
         %40 = OpLabel
         %42 = OpPhi %uint %37 %30 %86 %43
         %44 = OpSLessThan %bool %42 %uint_1
               OpLoopMerge %33 %41 None
               OpBranchConditional %44 %41 %33
         %41 = OpLabel
         %45 = OpLoad %v3uint %__builtin_var_GlobalInvocationId__
         %46 = OpCompositeExtract %uint %45 0
         %47 = OpLoad %v3uint %__builtin_var_NumWorkgroups__
         %48 = OpCompositeExtract %uint %47 0
         %49 = OpIMul %uint %48 %uint_32
               OpBranch %50
         %50 = OpLabel
         %52 = OpPhi %uint %46 %41 %85 %51
         %53 = OpSLessThan %bool %52 %uint_3
               OpLoopMerge %43 %51 None
               OpBranchConditional %53 %51 %43
         %51 = OpLabel
         %55 = OpAccessChain %_ptr_StorageBuffer_uint %compare_tensor_odd_length_ex_dispatch_0_arg_0 %uint_0 %52
         %56 = OpLoad %uint %55
         %57 = OpAccessChain %_ptr_StorageBuffer_uint %compare_tensor_odd_length_ex_dispatch_0_arg_1 %uint_0 %52
         %58 = OpLoad %uint %57
         %59 = OpSDiv %uint %52 %uint_4
         %60 = OpAccessChain %_ptr_StorageBuffer_uint %compare_tensor_odd_length_ex_dispatch_0_arg_2 %uint_0 %59
         %61 = OpLoad %uint %60
         %62 = OpSMod %uint %52 %uint_4
         %63 = OpIMul %uint %62 %uint_8
         %64 = OpShiftRightArithmetic %uint %61 %63
         %65 = OpBitwiseAnd %uint %64 %uint_255
         %66 = OpSDiv %uint %52 %uint_4
         %67 = OpAccessChain %_ptr_StorageBuffer_uint %compare_tensor_odd_length_ex_dispatch_0_arg_3 %uint_0 %66
         %68 = OpLoad %uint %67
         %69 = OpSMod %uint %52 %uint_4
         %70 = OpIMul %uint %69 %uint_8
         %71 = OpShiftRightArithmetic %uint %68 %70
         %72 = OpBitwiseAnd %uint %71 %uint_255
         %73 = OpIEqual %bool %56 %58
         %74 = OpSelect %uint %73 %65 %72
         %75 = OpSMod %uint %52 %uint_4
         %76 = OpIMul %uint %75 %uint_8
         %77 = OpShiftLeftLogical %uint %uint_255 %76
         %78 = OpNot %uint %77
         %79 = OpBitwiseAnd %uint %74 %uint_255
         %80 = OpShiftLeftLogical %uint %79 %76
         %81 = OpSDiv %uint %52 %uint_4
         %82 = OpAccessChain %_ptr_StorageBuffer_uint %compare_tensor_odd_length_ex_dispatch_0_arg_4 %uint_0 %81
         %83 = OpAtomicAnd %uint %82 %uint_1 %uint_8 %78
         %84 = OpAtomicOr %uint %82 %uint_1 %uint_8 %80
         %85 = OpIAdd %uint %52 %49
               OpBranch %50
         %43 = OpLabel
         %86 = OpIAdd %uint %42 %39
               OpBranch %40
         %33 = OpLabel
         %87 = OpIAdd %uint %32 %28
               OpBranch %29
         %31 = OpLabel
               OpReturn
               OpFunctionEnd

Decompiled GLSL:

#version 450
layout(local_size_x = 32, local_size_y = 1, local_size_z = 1) in;

layout(set = 0, binding = 0, std430) buffer compare_tensor_odd_length_ex_dispatch_0_arg_0
{
    uint _m0[3];
} compare_tensor_odd_length_ex_dispatch_0_arg_0_1;

layout(set = 0, binding = 1, std430) buffer compare_tensor_odd_length_ex_dispatch_0_arg_1
{
    uint _m0[3];
} compare_tensor_odd_length_ex_dispatch_0_arg_1_1;

layout(set = 0, binding = 2, std430) buffer compare_tensor_odd_length_ex_dispatch_0_arg_2
{
    uint _m0[3];
} compare_tensor_odd_length_ex_dispatch_0_arg_2_1;

layout(set = 0, binding = 3, std430) buffer compare_tensor_odd_length_ex_dispatch_0_arg_3
{
    uint _m0[3];
} compare_tensor_odd_length_ex_dispatch_0_arg_3_1;

layout(set = 0, binding = 4, std430) buffer compare_tensor_odd_length_ex_dispatch_0_arg_4
{
    uint _m0[3];
} compare_tensor_odd_length_ex_dispatch_0_arg_4_1;

void main()
{
    uint _32;
    _32 = gl_GlobalInvocationID.z;
    uint _39;
    uint _42;
    for (;;)
    {
        if (int(_32) < int(1u))
        {
            _39 = gl_NumWorkGroups.y;
            _42 = gl_GlobalInvocationID.y;
            uint _49;
            uint _52;
            for (;;)
            {
                if (int(_42) < int(1u))
                {
                    _49 = gl_NumWorkGroups.x * 32u;
                    _52 = gl_GlobalInvocationID.x;
                    for (; int(_52) < int(3u); )
                    {
                        uint _56 = compare_tensor_odd_length_ex_dispatch_0_arg_0_1._m0[_52];
                        uint _58 = compare_tensor_odd_length_ex_dispatch_0_arg_1_1._m0[_52];
                        uint _61 = compare_tensor_odd_length_ex_dispatch_0_arg_2_1._m0[uint(int(_52) / int(4u))];
                        uint _68 = compare_tensor_odd_length_ex_dispatch_0_arg_3_1._m0[uint(int(_52) / int(4u))];
                        uint _76 = uint(int(_52) % int(4u)) * 8u;
                        uint _81 = uint(int(_52) / int(4u));
                        uint _83 = atomicAnd(compare_tensor_odd_length_ex_dispatch_0_arg_4_1._m0[_81], ~(255u << _76));
                        uint _84 = atomicOr(compare_tensor_odd_length_ex_dispatch_0_arg_4_1._m0[_81], (((_56 == _58) ? (uint(int(_61) >> int(uint(int(_52) % int(4u)) * 8u)) & 255u) : (uint(int(_68) >> int(uint(int(_52) % int(4u)) * 8u)) & 255u)) & 255u) << _76);
                        _52 += _49;
                        continue;
                    }
                    _42 += _39;
                    continue;
                }
                else
                {
                    break;
                }
            }
            _32 += gl_NumWorkGroups.z;
            continue;
        }
        else
        {
            break;
        }
    }
}

Activity

  1. added
    bug 🐞
    codegen
    on Mar 26, 2020
  2. MaheshRavishankar commented on Mar 31, 2020

    @MaheshRavishankar
    Collaborator

    cc-ing Hanhan on this. Might be an issue with the bitwidth pass

    @hanhanW

  3. MaheshRavishankar commented on Apr 1, 2020

    @MaheshRavishankar
    Collaborator

    Still trying to repro this on my end (on a linux machine). Having issues getting the extension layer for timeline semaphore hooked in. So will update once I have the figured out locally.

  4. self-assigned this
    on Apr 7, 2020
  5. hanhanW commented on May 4, 2020

    @hanhanW
    Contributor

    A quick update. We already deprecated the legacy path, now the test will re-enable on the new GPU (Linalg) compilation path in #1766. I'll try to test if this is still an issue in the new path.

  6. hanhanW commented on May 8, 2020

    @hanhanW
    Contributor

    @antiagainst The test now is enabled in #1688 , could you take a look at if the issue is still opening in structured op path?

  7. antiagainst commented on May 8, 2020

    @antiagainst
    Member

    This issue still persists on real GPU: the test fails when running on NVIDIA Quadro P1000.

  8. MaheshRavishankar commented on May 8, 2020

    @MaheshRavishankar
    Collaborator

    Just looking through the GLSL again, the array seems to be of type uint[3]. It should be uint[1]. The type of the interface global variables seems off.

    %uint = OpTypeInt 32 0
    %uint_3 = OpConstant %uint 3
    %_arr_uint_uint_3 = OpTypeArray %uint %uint_3
    
  9. hanhanW commented on May 21, 2020

    @hanhanW
    Contributor

    Tested locally, and the test is passing on my workstation.

    $ ctest -V -R iree/test/e2e/xla_ops:check_vulkan-spirv_vulkan_compare.mlir

    log:

    102: I ../iree/hal/vulkan/vulkan_driver.cc:295] Created Vulkan Device: Quadro P1000
    ...
    102: [  PASSED  ] 15 tests.
    

    Closing the issue. Feel free to reopen it if it still persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug 🐞codegen

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions