pyccel / pyccel-cuda

Cuda extension to pyccel
MIT License
1 stars 0 forks source link

Improve `CudaInternalVar` #16

Open EmilyBourne opened 1 year ago

EmilyBourne commented 1 year ago

The CudaInternalVar object is a class which describes a function which takes a literal integer as an argument and returns a cuda property in the requested dimension. E.g. the subclass CudaThreadIdx returns the 1st, 2nd or 3rd thread index. I think that this is a sub-optimal solution as the resulting code is quite different from the syntax that users may be familiar with. Furthermore the use of an argument will encourage users to pass variables instead of literals so we will need robust error messages to explain why this is not possible.

I therefore recommend replacing CudaInternalVar by a class type similar to:

CudaInternalVar = ClassDef('CudaInternalVar',
                           variables = [Variable('int', 'x'),
                                        Variable('int', 'y'),
                                        Variable('int', 'z')])

and replacing the subclasses by simple variables. E.g:

CudaThreadIdx = Variable(CudaInternalVar, 'CudaThreadIdx')

This would allow the user to write the code as:

from pyccel.cuda import CudaThreadIdx

print(CudaThreadIdx.x)
EmilyBourne commented 3 weeks ago

Related to an old branch