Thread overview
Dcompute OpenCL problem: invalidKernelName
May 29, 2023
unDEFER
May 29, 2023
unDEFER
May 29, 2023
Nicholas Wilson
May 29, 2023
unDEFER
May 29, 2023
unDEFER
May 29, 2023
unDEFER
May 29, 2023

Hello!

I'm trying to make working OpenCL test example in dcompute ~master branch.
All is good, but I get invalidKernelName error.

When I add debug to program.c:59:

writefln("%s", name);

I see mangled name of saxpy function:

_D12dummykernels5saxpyFS3ldc8dcompute__T7PointerVEQBaQz9AddrSpacei1TfZQBefQBzQCcmZv

And if I run

$ spirv-dis .dub/obj/kernels_ocl220_64.spv | grep "_D12dummykernels5saxpyFS3ldc8dcompute__T7PointerVEQBaQz9AddrSpacei1TfZQBefQBzQCcmZv"

I see two definitions of this symbol:

  • as OpEntryPoint
    and
  • as opFunction

In https://github.com/bashbaug/SimpleOpenCLSamples I found good 05_spirvkernelfromfile example and there are building logs. If I run

$ ./spirvkernelfromfile -p 1 --file /home/undefer/MyFiles/Projects/TEST/D/gpu/.dub/obj/kernels_ocl220_64.spv

I see the next line:

Kernel <_D12dummykernels5saxpyFS3ldc8dcompute__T7PointerVEQBaQz9AddrSpacei1TfZQBefQBzQCcmZv.1> was successfully vectorized (8)

I.e. the kernel is loaded but by name with suffix ".1". And if I add this suffix to program.c:59 like:

name = name ~ ".1"

The example is working. The sample_kernel64.spv of 05_spirvkernelfromfile loads good without any suffixes to "Test" kernel name. But if I self try compile

$ clang -c -target spir64 -emit-llvm -o sample_kernel.bc sample_kernel.cl
$ llvm-spirv -o sample_kernel.spv sample_kernel.bc

I get the same problem and kernel "Test.1" loads. If I manually remove two lines from assembly version which defines "OpFunction Test" and assembly again:

$ spirv-dis sample_kernel.spv > 2.asm
$ vim 2.asm
$ spirv-as --target-env opencl2.1 -o 2.spv 2.asm

I get working spv-module.

I can't understand if it is problem of ldc2/clang/llvm-spirv and I must go to their bugtracker or it is feature and there exists option to compiler which will stop adding second kernel declaration as function and then I must create pull request to dcompute.

May 29, 2023

On Monday, 29 May 2023 at 10:31:12 UTC, unDEFER wrote:

>

Hello!

I'm trying to make working OpenCL test example in dcompute ~master branch.
All is good, but I get invalidKernelName error.

When I add debug to program.c:59:

Sorry, I mistyped. program.d:59 of dcompute I mean.

And also I forgot add that I'm on Gentoo. ldc2 version:

$ ldc2 --version
LDC - the LLVM D compiler (1.29.0):
  based on DMD v2.099.1 and LLVM 14.0.6
  built with LDC - the LLVM D compiler (1.29.0)
  Default target: x86_64-pc-linux-gnu
  Host CPU: broadwell
  http://dlang.org - http://wiki.dlang.org/LDC
May 29, 2023

On Monday, 29 May 2023 at 10:31:12 UTC, unDEFER wrote:

>

Hello!

I'm trying to make working OpenCL test example in dcompute ~master branch.
All is good, but I get invalidKernelName error.

[...]

That is very strange indeed. I suspect LLVM might be to blame here, (e.g. https://github.com/ldc-developers/ldc/blob/89cbc4cceb77cfb58419a117d06aa704afa7f6d1/gen/abi/x86.cpp#L65 for other cases where we need to force LLVM to do things properly) and we simply haven't taken that into account.

Could you try with an older version of LDC, one released against a prior release of LLVM and see if you still get the same behaviour?

May 29, 2023

On Monday, 29 May 2023 at 14:41:59 UTC, Nicholas Wilson wrote:

>

That is very strange indeed. I suspect LLVM might be to blame here, (e.g. https://github.com/ldc-developers/ldc/blob/89cbc4cceb77cfb58419a117d06aa704afa7f6d1/gen/abi/x86.cpp#L65 for other cases where we need to force LLVM to do things properly) and we simply haven't taken that into account.

Could you try with an older version of LDC, one released against a prior release of LLVM and see if you still get the same behaviour?

Thank you, Nicholas! Seems I have found commit in LLVM - SPIR V translator which broke it.

https://github.com/KhronosGroup/SPIRV-LLVM-Translator/commit/85815e725ce5bdc970b812b4bbff73d4b2a44046

I'm going to compile 2 versions before and after this commit to check.

May 29, 2023

On Monday, 29 May 2023 at 16:50:54 UTC, unDEFER wrote:

>

Thank you, Nicholas! Seems I have found commit in LLVM - SPIR V translator which broke it.

https://github.com/KhronosGroup/SPIRV-LLVM-Translator/commit/85815e725ce5bdc970b812b4bbff73d4b2a44046

I'm going to compile 2 versions before and after this commit to check.

Yes, it is really problem commit. It remains only to understand how to fix it.

May 29, 2023

On Monday, 29 May 2023 at 18:20:43 UTC, unDEFER wrote:

>

Yes, it is really problem commit. It remains only to understand how to fix it.

I have added an issue to the issue-tracker:

https://github.com/KhronosGroup/SPIRV-LLVM-Translator/issues/2029