0

I have a problem compiling the method below. It compiles fine if the CUDA is selected as target, however if the OpenCL is selected that it throws error.

[Cudafy]
unsafe static void MyKernelMethod(
    GThread thread, 
    [CudafyAddressSpace(eCudafyAddressSpace.Constant)] int[] a)
{
    // fix our array to a ptr 
    fixed (int* aPtr = a)
    {
        // get a new array pointing to some offset of the original array
        int* aPtr_Offset = aPtr + thread.blockIdx.x;
        // use it for something
        aPtr_Offset[thread.threadIdx.x] = 2;

        // some more code...
    }
}

The error:

error: illegal implicit conversion between two pointers with different address spaces

I do not have enough knowledge how to correct this (I am just starting GPGPU programming).

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
dajuric
  • 2,373
  • 2
  • 20
  • 43
  • 1
    `a` is not of type `int*`, it's either `local int*` or `global int*`. – Baiz Nov 11 '14 at 00:23
  • OK, how can I write that in C# using Cudafy.NET ? – dajuric Nov 11 '14 at 12:47
  • I've never used cudafy, but it looks like a is of type `[CudafyAddressSpace(eCudafyAddressSpace.Constant)] int[]`, which means it's read-only and you wont be able to create a non-const pointer from it. Of course I could be very wrong about all that since I have zero experience with cudafy :/ – Baiz Nov 11 '14 at 12:57
  • I also set Global, Local, Priivate and Shared and none of them works. – dajuric Nov 11 '14 at 13:54
  • What happens when you leave out `[CudafyAddressSpace(eCudafyAddressSpace.Constant)]` and just write `int[] a` as parameter? Also see [this example](https://cudafy.codeplex.com/discussions/402785) – Baiz Nov 11 '14 at 14:04
  • The same error. That is why I tried to add this attribute, but it did not work. – dajuric Nov 12 '14 at 13:03

0 Answers0