Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic support for Custom Device function. #41

Closed
Tracked by #25
bauom opened this issue Jan 31, 2024 · 0 comments · Fixed by #61
Closed
Tracked by #25

Basic support for Custom Device function. #41

bauom opened this issue Jan 31, 2024 · 0 comments · Fixed by #61
Assignees

Comments

@bauom
Copy link
Collaborator

bauom commented Jan 31, 2024

Description:

Implement support for defining and using custom device functions in Pyccel, analogous to Numba's device functions. This feature will allow functions to be executed on the GPU, callable from kernels or other device functions but not from host code.

Implementation Steps:

  1. Introduce @device decorator for device function definition.
  2. Modify compiler to handle device function calls in the AST, translating them to CUDA code.
  3. Ensure device functions compile to CUDA device functions with correct call semantics.

Read more:
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html?highlight=__device__#device

Example Usage:

Pyccel Code:

from pyccel.decorators import kernel, device
from pyccel.internals import cuda

@device
def add_one(x):
    return x + 1

@kernel
def increment_array(an_array):
    tx = cuda.threadIdx(0)
    ty = cuda.blockIdx(0)
    pos = tx + ty * cuda.blockDim(0)
    if pos < an_array.size:
        an_array[pos] = add_one(an_array[pos])

Expected CUDA Code:

__device__ int add_one(int x) {
    return x + 1;
}

__global__ void increment_array(int* an_array, int array_size) {
    int tx = threadIdx.x;
    int ty = blockIdx.x;
    int pos = tx + ty * blockDim.x;
    if (pos < array_size) {
        an_array[pos] = add_one(an_array[pos]);
    }
}
@bauom bauom mentioned this issue Jan 31, 2024
22 tasks
@smazouz42 smazouz42 assigned smazouz42 and unassigned smazouz42 Feb 7, 2024
@smazouz42 smazouz42 self-assigned this Mar 1, 2024
@smazouz42 smazouz42 linked a pull request Jun 3, 2024 that will close this issue
This was referenced Jun 28, 2024
@smazouz42 smazouz42 linked a pull request Jun 28, 2024 that will close this issue
EmilyBourne added a commit that referenced this issue Jul 3, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
EmilyBourne added a commit that referenced this issue Jul 11, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
EmilyBourne added a commit that referenced this issue Jul 15, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
EmilyBourne added a commit that referenced this issue Jul 17, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
EmilyBourne added a commit that referenced this issue Jul 19, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
EmilyBourne added a commit that referenced this issue Jul 26, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
EmilyBourne added a commit that referenced this issue Aug 29, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
EmilyBourne added a commit that referenced this issue Sep 3, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
EmilyBourne added a commit that referenced this issue Sep 25, 2024
This pull request addresses issue
#41 by implementing a new
feature in Pyccel that allows users to define a custom device

**Commit Summary**

- Adding handler for custom device and its code generation.
- Adding test

---------

Co-authored-by: EmilyBourne <louise.bourne@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants