pyccel / pyccel-cuda

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

Add Python translation support for `pyccel.cuda.host_empty` and `pyccel.cuda.device_empty` #58

Open EmilyBourne opened 2 weeks ago

EmilyBourne commented 2 weeks ago

Relevant Discussion

https://github.com/pyccel/pyccel-cuda/discussions/55 and discussion in the meeting on 13/6/2024

Describe the feature

I would like to be able to explicitly allocate memory on the CPU or GPU. After #56 and #57 the Python code that describes this should be working. In this issue we want to add syntactic/semantic. In order to test this we will ensure that we can translate from Python to Python.

Test Code

Provide code which does not currently work but which should do when this issue is fixed:

import pyccel.cuda as cuda

if __name__ == '__main__':
     n = 100
     a = cuda.host_empty(n)
     b = cuda.device_empty(n)
     for i in range(n):
        a[i] = i
     print(a)

Proposed Solution

A class PyccelCudaEmpty should be created in pyccel.ast.cudaext. It should describe the objects cuda.host_empty and cuda.device_empty. The implementation of this type is left to the developer. It will either be similar to NumpyEmpty or may be able to inherit from NumpyEmpty.

A Module should be created to describe pyccel.cuda and should map host_empty and device_empty to this class or to subclasses (subclasses may be useful to ensure the correct prototype).

The class type of a and b will need to be defined. This should be done in a file pyccel.ast.cudatypes. The new type must satisfy the following criteria:

The __add__ and __and__ operators should ensure that it is not possible to mix CPU and GPU memory in the same operation (e.g. not possible to do device_array[i] + host_array[i])

Additional Information

This issue is blocked by #56 and #57