# Using templated struct as argument in OpenCL kernel

**URL:** <https://community.khronos.org/t/using-templated-struct-as-argument-in-opencl-kernel/110425>\
**Category:** OpenCL\
**Created:** [January 6, 2024, 1:54pm UTC](https://community.khronos.org/t/using-templated-struct-as-argument-in-opencl-kernel/110425 "2024-01-06T13:54:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikulcak](https://community.khronos.org/letter_avatar_proxy/v4/letter/m/bc8723/32.png) [@mikulcak](https://community.khronos.org/u/mikulcak)\
**Post date:** [January 6, 2024, 1:54pm UTC](https://community.khronos.org/t/using-templated-struct-as-argument-in-opencl-kernel/110425/1 "2024-01-06T13:54:25Z")

</div>

Hi everybody,

I am running into a problem for which I would be incredibly grateful if you could help me a solution.

I am trying to compile the code snippet seen below using `clang-17`, but get the error:

```auto
openclTemplateTest.hpp:12:68: error: ' __global MyTemplatedTestStructWithSize *__ private' (aka ' __global MyTemplatedTestStruct<32> *__ private') cannot be used as the type of a kernel parameter
   12 | kernel void myTestFunction(__global MyTemplatedTestStructWithSize* myArgument)
      | ^
1 error generated.

```

The complete list of `clang` arguments is as follows:

```auto
/usr/lib/llvm-17/bin/clang++ -c -cl-std=clc++ -target spir64 -emit-llvm -fcolor-diagnostics -Xclang -finclude-default-header [some header includes for OpenCL-C++ using -I] openclTemplateTest.hpp -o bitcode_out.bc

```

The first guess is that OpenCL kernels do not support arrays of templated structs as arguments, but that’s not true, is it? If they are allowed in general, what am I doing wrong?

Thank you very much in advance!

The code in question:

```auto
template<unsigned int NUM_BLOCKS>
struct MyTemplatedTestStruct
{
    int blocks[NUM_BLOCKS];
};

typedef MyTemplatedTestStruct<32> MyTemplatedTestStructWithSize;

kernel void myTestFunction(__global MyTemplatedTestStructWithSize* myArgument)
{
    for (unsigned int i = 0; i < 5; ++i)
    {
        myArgument->blocks[i] = 42; // completely nonsensical, just for testing purposes
    }
}

```

---

<div class="post-metadata">

**Author:** ![system](https://community.khronos.org/uploads/default/original/2X/b/ba89cb49313a0e869198c8be354afde8bcae027e.png) [@system](https://community.khronos.org/u/system)\
**Post date:** [July 7, 2024, 1:54pm UTC](https://community.khronos.org/t/using-templated-struct-as-argument-in-opencl-kernel/110425/2 "2024-07-07T13:54:47Z")

</div>

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.
