Is anyone ever acces to complex64 value in rawkernel

12 views
Skip to first unread message

sim Bec

unread,
Apr 5, 2023, 8:19:27 AM4/5/23
to CuPy User Group
Hello everyone,
It's the first time I use this group.
I'm a frenche engeneer in a university laboratory.
I've already developped a soft for analysing hologram in C++/CUDA.
For researcher and student I'm developping a new code in Python/CUPY

I've already quite translating all the functions needed but I have some problem when I want to access imaginary and real part of some complex cupy array in a rawkernel.
Here is my functions and the related error:

@jit.rawkernel()
def clean_plan_cplx_device(d_plan_cplx, size_x, size_y, posX, posY, clean_radius_pix, replace_cplx_value):
    index = jit.blockIdx.x * jit.blockDim.x + jit.threadIdx.x
    sizeXY = size_x * size_y
    jj = cp.int32(index) // cp.int32(size_x)
    ii = cp.int32(index) - cp.int32(jj * size_x)

    if (ii < size_x and jj < size_y):   #calcul distance
        distance = cp.sqrt((posX - ii)**2 + (posY - jj)**2)
        cplx = cp.complex64(d_plan_cplx[ii, jj])
        mod = cp.sqrt(cp.real(cplx)**2 + cp.imag(cplx)**2)

    if (distance < clean_radius_pix):
        d_plan_cplx[ii, jj] = 0.0+0j
    else:
        d_plan_cplx[ii, jj] = mod + 0j

def clean_plan_cplx(d_plan_cplx, size_x, size_y, posX, posY, clean_radius_pix, replace_value):
    nthread = 1024
    nBlock = math.ceil(size_x * size_y // nthread)
    clean_plan_cplx_device[nBlock, nthread](d_plan_cplx, size_x, size_y, posX, posY, clean_radius_pix, replace_value)

TypeError: Invalid function call 'real'.

Is there a way to acces real and imaginary part in this kernel?

Thank you for your help
Best regards

Simon
Reply all
Reply to author
Forward
0 new messages