forked from pyccel/pyccel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request addresses issue #28 by implementing a new feature in Pyccel that allows users to define custom GPU kernels. The syntax for creating these kernels is inspired by Numba. and I also need to fix issue #45 for testing purposes **Commit Summary** - Introduced KernelCall class - Added cuda printer methods _print_KernelCall and _print_FunctionDef to generate the corresponding CUDA representation for both kernel calls and definitions - Added IndexedFunctionCall represents an indexed function call - Added CUDA module and cuda.synchronize() - Fixing a bug that I found in the header: it does not import the necessary header for the used function --------- Co-authored-by: EmilyBourne <[email protected]> Co-authored-by: bauom <[email protected]> Co-authored-by: Emily Bourne <[email protected]>
- Loading branch information
1 parent
7ad90da
commit b3de549
Showing
19 changed files
with
599 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,3 +120,4 @@ indexable | |
traceback | ||
STC | ||
gFTL | ||
GPUs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Getting started GPU | ||
|
||
Pyccel now supports NVIDIA CUDA, empowering users to accelerate numerical computations on GPUs seamlessly. With Pyccel's high-level syntax and automatic code generation, harnessing the power of CUDA becomes effortless. This documentation provides a quick guide to enabling CUDA in Pyccel | ||
|
||
## Cuda Decorator | ||
|
||
### kernel | ||
|
||
The kernel decorator allows the user to declare a CUDA kernel. The kernel can be defined in Python, and the syntax is similar to that of Numba. | ||
|
||
```python | ||
from pyccel.decorators import kernel | ||
|
||
@kernel | ||
def my_kernel(): | ||
pass | ||
|
||
blockspergrid = 1 | ||
threadsperblock = 1 | ||
# Call your kernel function | ||
my_kernel[blockspergrid, threadsperblock]() | ||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# -*- coding: utf-8 -*- | ||
#------------------------------------------------------------------------------------------# | ||
# This file is part of Pyccel which is released under MIT License. See the LICENSE file or # | ||
# go to https://github.com/pyccel/pyccel/blob/master/LICENSE for full license details. # | ||
#------------------------------------------------------------------------------------------# | ||
""" | ||
CUDA Module | ||
This module provides a collection of classes and utilities for CUDA programming. | ||
""" | ||
from pyccel.ast.core import FunctionCall | ||
|
||
__all__ = ( | ||
'KernelCall', | ||
) | ||
|
||
class KernelCall(FunctionCall): | ||
""" | ||
Represents a kernel function call in the code. | ||
The class serves as a representation of a kernel | ||
function call within the codebase. | ||
Parameters | ||
---------- | ||
func : FunctionDef | ||
The definition of the function being called. | ||
args : iterable of FunctionCallArgument | ||
The arguments passed to the function. | ||
num_blocks : TypedAstNode | ||
The number of blocks. These objects must have a primitive type of `PrimitiveIntegerType`. | ||
tp_block : TypedAstNode | ||
The number of threads per block. These objects must have a primitive type of `PrimitiveIntegerType`. | ||
current_function : FunctionDef, optional | ||
The function where the call takes place. | ||
""" | ||
__slots__ = ('_num_blocks','_tp_block') | ||
_attribute_nodes = (*FunctionCall._attribute_nodes, '_num_blocks', '_tp_block') | ||
|
||
def __init__(self, func, args, num_blocks, tp_block, current_function = None): | ||
self._num_blocks = num_blocks | ||
self._tp_block = tp_block | ||
super().__init__(func, args, current_function) | ||
|
||
@property | ||
def num_blocks(self): | ||
""" | ||
The number of blocks in the kernel being called. | ||
The number of blocks in the kernel being called. | ||
""" | ||
return self._num_blocks | ||
|
||
@property | ||
def tp_block(self): | ||
""" | ||
The number of threads per block. | ||
The number of threads per block. | ||
""" | ||
return self._tp_block | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
#------------------------------------------------------------------------------------------# | ||
# This file is part of Pyccel which is released under MIT License. See the LICENSE file or # | ||
# go to https://github.com/pyccel/pyccel/blob/master/LICENSE for full license details. # | ||
#------------------------------------------------------------------------------------------# | ||
""" | ||
CUDA Extension Module | ||
Provides CUDA functionality for code generation. | ||
""" | ||
from .internals import PyccelFunction | ||
|
||
from .datatypes import VoidType | ||
from .core import Module, PyccelFunctionDef | ||
|
||
__all__ = ( | ||
'CudaSynchronize', | ||
) | ||
|
||
class CudaSynchronize(PyccelFunction): | ||
""" | ||
Represents a call to Cuda.synchronize for code generation. | ||
This class serves as a representation of the Cuda.synchronize method. | ||
""" | ||
__slots__ = () | ||
_attribute_nodes = () | ||
_shape = None | ||
_class_type = VoidType() | ||
def __init__(self): | ||
super().__init__() | ||
|
||
cuda_funcs = { | ||
'synchronize' : PyccelFunctionDef('synchronize' , CudaSynchronize), | ||
} | ||
|
||
cuda_mod = Module('cuda', | ||
variables=[], | ||
funcs=cuda_funcs.values(), | ||
imports=[] | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#------------------------------------------------------------------------------------------# | ||
# This file is part of Pyccel which is released under MIT License. See the LICENSE file or # | ||
# go to https://github.com/pyccel/pyccel/blob/master/LICENSE for full license details. # | ||
#------------------------------------------------------------------------------------------# | ||
""" | ||
This module is for exposing the CudaSubmodule functions. | ||
""" | ||
from .cuda_sync_primitives import synchronize | ||
|
||
__all__ = ['synchronize'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#------------------------------------------------------------------------------------------# | ||
# This file is part of Pyccel which is released under MIT License. See the LICENSE file or # | ||
# go to https://github.com/pyccel/pyccel/blob/master/LICENSE for full license details. # | ||
#------------------------------------------------------------------------------------------# | ||
""" | ||
This submodule contains CUDA methods for Pyccel. | ||
""" | ||
|
||
|
||
def synchronize(): | ||
""" | ||
Synchronize CUDA device execution. | ||
Synchronize CUDA device execution. | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.