CHIP-SPV / chipStar

chipStar is a tool for compiling and running HIP/CUDA on SPIR-V via OpenCL or Level Zero APIs.
Other
219 stars 32 forks source link

Why we don't account the tail padding when compute a arg'size? #860

Closed joyongzhu closed 4 months ago

joyongzhu commented 4 months ago

I came across a problem and was very confused:

I got an incorrect arg‘s size in this code because it didn't take into account the tail filling , I would like to know why this is done?

src/spirv.cc:439

        // Compute actual size as in spv::Op::OpTypeArray branch
        // except don't account the tail padding. C analogy as
        // example: 'struct { char a; int b; char c}' takes 9 bytes.
        size_t MemberAlignment = Type->alignment();
        TotalSize = roundUp(TotalSize, MemberAlignment);
        TotalSize += Type->size();
        if (MemberAlignment > MaxAlignment)
          MaxAlignment = MemberAlignment;
linehill commented 4 months ago

I would like to know why this is done?

I recall, it's for the same reason: getting kernel argument sizes correct. Accounting the tail padding on structs caused errors on kernel setter calls. Perhaps, this is a driver specific issue?

Could you post more details about your environment and the program (chipStar backend used, driver being used, debug logs)? Could you post us a HIP source (preferably a reduced one) that triggers the issue?

joyongzhu commented 4 months ago

I recall, it's for the same reason: getting kernel argument sizes correct. Accounting the tail padding on structs caused errors on kernel setter calls. Perhaps, this is a driver specific issue?

It can be know, the current code is fine on the Intel platform, so I suspect it has something to do with the GPU driver.

For some special reasons, I can't provide more details about this undisclosed GPU.

But your response has been a huge help to me, and if I feel that my changes will benefit the current project, I will try to submit some optimizations to the project.