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

Add support for kernels #42

Merged
merged 462 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
462 commits
Select commit Hold shift + click to select a range
b1fdaea
remove trailing whitespace
smazouz42 Mar 8, 2024
242e907
Removed unnecessary argument from function signature.
smazouz42 Mar 8, 2024
d479ec2
i moved the cuda import to the f function so that Pyccel can recognizt
smazouz42 Mar 11, 2024
32ab182
end summary with period.
smazouz42 Mar 11, 2024
fa71ba5
end summary with period.
smazouz42 Mar 11, 2024
e9580b3
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
ac9e2df
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
e363972
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
2b19a94
Merge branch 'devel' into feat/kernels-support-25
EmilyBourne Mar 11, 2024
051710d
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
7be2a71
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
4db5163
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
494aa83
Merge remote-tracking branch 'origin/devel' into feat/kernels-support-25
EmilyBourne Mar 12, 2024
4635599
Fix merge
EmilyBourne Mar 12, 2024
5ebd87a
Fix merge
EmilyBourne Mar 12, 2024
07db48f
Fix markexpr
EmilyBourne Mar 12, 2024
0e7e7cb
Fix condition
EmilyBourne Mar 12, 2024
bf03c8b
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
a06a216
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
9b9c8d1
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
c5793be
add tests in pytest
smazouz42 Mar 15, 2024
df1d712
Merge devel branch into kernel
smazouz42 Mar 15, 2024
5a226ab
fix invalid syntax
smazouz42 Mar 15, 2024
c6c80a5
register gpu mark
smazouz42 Mar 15, 2024
8cae11f
register gpu marker
smazouz42 Mar 15, 2024
d4c7df9
register gpu marker
smazouz42 Mar 15, 2024
030dd8b
fix some codacy errors
smazouz42 Mar 16, 2024
82b5bed
add final line to my test fucntions
smazouz42 Mar 16, 2024
87c2954
add final line to my test fucntions
smazouz42 Mar 16, 2024
4115fca
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
eacf2bf
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
6344221
add cuda wrapper
smazouz42 Mar 18, 2024
94c212b
commats cuda stuff trying understand how exactly tests are working on…
smazouz42 Mar 18, 2024
a178e23
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
d9c2064
Merge changes from devel into kernel
smazouz42 Mar 18, 2024
11dbf45
change cuda modules type to new one
smazouz42 Mar 18, 2024
45f8b15
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
309275b
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
3de9001
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
fb2f925
Merge remote-tracking branch 'origin/devel' into feat/kernels-support-25
smazouz42 Mar 18, 2024
c725378
remove some lines
smazouz42 Mar 18, 2024
74eaa89
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
879b3af
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
5b2e442
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
ba8014b
Merge remote-tracking branch 'origin/devel' into feat/kernels-support-25
smazouz42 Mar 19, 2024
08e9a42
fix some import problems
smazouz42 Mar 19, 2024
243612f
add _getitem__ to allows the kernel function to be invoked with
smazouz42 Mar 20, 2024
2632656
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
f3d7df1
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
4771948
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
d98b992
make codegane uptodate with last changes
smazouz42 Mar 21, 2024
db82214
Merge remote-tracking branch 'origin/devel' into feat/kernels-support-25
smazouz42 Mar 21, 2024
5c23553
debugging purpose
smazouz42 Mar 21, 2024
f6ba584
debugging purpose
smazouz42 Mar 21, 2024
69fc471
debugging purpose
smazouz42 Mar 21, 2024
d08c0ca
debugging purpose
smazouz42 Mar 22, 2024
f2e8d33
add kernel function definition in header
smazouz42 Mar 23, 2024
abfc3da
uncomment cuda synchronize
smazouz42 Mar 23, 2024
b6fec98
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
d27062c
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
e9a1f57
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
cc11488
Merge branch 'devel' into feat/kernels-support-25
EmilyBourne Mar 25, 2024
61bff09
debugging purpose
smazouz42 Mar 26, 2024
463ae58
Merge branch 'feat/kernels-support-25' of https://github.com/pyccel/p…
smazouz42 Mar 26, 2024
27e29f0
debugging purpose
smazouz42 Mar 26, 2024
3d374e1
debugging purpose
smazouz42 Mar 26, 2024
3e9fbb9
debugging purpose
smazouz42 Mar 26, 2024
ffa81fa
debugging purpose
smazouz42 Mar 26, 2024
f3a9d7f
debugging purpose
smazouz42 Mar 26, 2024
0f21fe5
debugging purpose
smazouz42 Mar 27, 2024
2570ac1
debugging purpose
smazouz42 Mar 27, 2024
aa28b21
debugging purpose
smazouz42 Mar 27, 2024
9b138f3
debugging purpose
smazouz42 Mar 27, 2024
e1ce71c
debugging purpose
smazouz42 Mar 27, 2024
c60078a
debugging purpose
smazouz42 Mar 27, 2024
52faa1d
debugging purpose
smazouz42 Mar 27, 2024
8cce4a1
debugging purpose
smazouz42 Mar 27, 2024
13566ba
debugging purpose
smazouz42 Mar 27, 2024
5c0aef7
debugging purpose
smazouz42 Mar 27, 2024
41891b9
debugging purpose
smazouz42 Mar 27, 2024
55ff6dd
debugging purpose
smazouz42 Mar 27, 2024
c061f50
debugging purpose
smazouz42 Mar 27, 2024
f1c3f03
debugging purpose
smazouz42 Mar 27, 2024
34c4a5d
debugging purpose
smazouz42 Mar 27, 2024
145b56d
debugging purpose
smazouz42 Mar 27, 2024
78d68f8
debugging purpose
smazouz42 Mar 27, 2024
bb5e6b9
debugging purpose
smazouz42 Mar 27, 2024
196722d
debugging purpose
smazouz42 Mar 27, 2024
40ed0b1
debugging purpose
smazouz42 Mar 27, 2024
a6ecd2f
debugging purpose
smazouz42 Mar 27, 2024
4d23140
debugging purpose
smazouz42 Mar 27, 2024
d5270df
debugging purpose
smazouz42 Mar 27, 2024
7641e4b
debugging purpose
smazouz42 Mar 27, 2024
ec20259
debugging purpose
smazouz42 Mar 27, 2024
0f49632
debugging purpose
smazouz42 Mar 27, 2024
0ffd39e
debugging purpose
smazouz42 Mar 27, 2024
c2cdfa0
debugging purpose
smazouz42 Mar 27, 2024
9b2e928
debugging purpose
smazouz42 Mar 27, 2024
fec23ce
debugging purpose
smazouz42 Mar 27, 2024
4146f54
debugging purpose
smazouz42 Mar 28, 2024
7280484
debugging purpose
smazouz42 Mar 28, 2024
61fc718
fix some codacy errors
smazouz42 Mar 28, 2024
2549887
fix some codacy errors
smazouz42 Mar 28, 2024
6e30522
fix some codacy errors
smazouz42 Mar 28, 2024
3caf9b0
fix some codacy errors
smazouz42 Mar 28, 2024
e4a3923
fix some codacy errors
smazouz42 Mar 28, 2024
f36cf8b
uncomment extern C in _print_Module
smazouz42 Mar 28, 2024
42557f8
import PythonNativeInt
smazouz42 Mar 28, 2024
398fd95
import PythonNativeInt
smazouz42 Mar 28, 2024
a2eedef
refactoring codegen test
smazouz42 Mar 28, 2024
0ea41ea
refactoring codegen test
smazouz42 Mar 28, 2024
63912fc
change type from the old version to new one supported by Pyccel
smazouz42 Mar 28, 2024
bc36140
change type from the old version to new one supported by Pyccel
smazouz42 Apr 1, 2024
57c51d0
debugging purpose
smazouz42 Apr 1, 2024
9fc92ac
debugging purpose
smazouz42 Apr 1, 2024
d3d2161
debugging purpose
smazouz42 Apr 1, 2024
01ffab6
debugging purpose
smazouz42 Apr 1, 2024
8a127fb
Removed 'extern C' block from imports concatenation
smazouz42 Apr 1, 2024
51471a1
add 'extern C' block from imports concatenation
smazouz42 Apr 1, 2024
f41b256
debugging purpose
smazouz42 Apr 1, 2024
22b31a1
debugging purpose
smazouz42 Apr 2, 2024
7ca3d73
documented both kernel class definition and function definition in cu…
smazouz42 Apr 2, 2024
ad0dbe9
documented cuda synchronize
smazouz42 Apr 2, 2024
dee1063
remove extern C
smazouz42 Apr 3, 2024
c1ba07a
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
0cc6cd4
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
39be59c
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
8c003fe
merge with devel
smazouz42 Apr 15, 2024
0883789
rename c_headers_imports so it is clear that it contains cuda imports
smazouz42 Apr 15, 2024
34b65aa
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
3e62767
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
3b0cc72
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
a6c099b
Merge branch 'devel' of https://github.com/pyccel/pyccel-cuda into fe…
smazouz42 May 8, 2024
87ab48d
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
7447938
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
1fb7ce2
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
6742731
Fix import handling (#49)
smazouz42 May 15, 2024
e590f94
merging my PR to devel and fix any errors related to the new changes …
smazouz42 May 15, 2024
e982c82
fix some errors related to a bad merger
smazouz42 May 16, 2024
534490f
Remove debugging code
smazouz42 May 16, 2024
aecc1ad
fix errors related to the new changes in devel
smazouz42 May 16, 2024
4fcea21
Remove debugging code
smazouz42 May 16, 2024
61d4ccb
make sure tests are running successfully
smazouz42 May 16, 2024
6921022
make sure tests are running successfully
smazouz42 May 16, 2024
89aecf3
cleaning upmy PR
smazouz42 May 16, 2024
e3fe1be
cleaning upmy PR
smazouz42 May 16, 2024
9490f60
Fixing documentation
smazouz42 May 16, 2024
2be272a
Adding new line for more readability
smazouz42 May 17, 2024
cc3b47b
cleaning upmy PR
smazouz42 May 17, 2024
71091e1
adding get_expected_name to make sure I get the correct semantic obj …
smazouz42 May 17, 2024
2aabe03
Update Changelog
smazouz42 May 19, 2024
5eca104
add cuda doc
smazouz42 May 21, 2024
bdb65dd
add cuda doc
smazouz42 May 21, 2024
8664b02
Adding newline after the header in CUDA documentation
smazouz42 May 21, 2024
7596275
GPUs to GPU
smazouz42 May 21, 2024
a2557c4
GPU to GPUs
smazouz42 May 21, 2024
354c143
GPU to GPUs
smazouz42 May 21, 2024
254d24f
Update deprecated action (4 lines) (#1873)
EmilyBourne May 22, 2024
2396f63
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
7d0b4fb
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
8cfa9e8
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
1c96bfc
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
93c6832
Fix import handling (#49)
smazouz42 May 15, 2024
f8fde93
Merge branch 'devel' of https://github.com/pyccel/pyccel-cuda into fe…
smazouz42 May 27, 2024
196799f
feat: Add support for GPU availability flag
smazouz42 May 29, 2024
1cc7c72
removing old pytest configure for gpu
smazouz42 May 29, 2024
3357017
debuging perpose
smazouz42 May 29, 2024
2d94da8
Fixed a small error in _print_ModuleHeader and stopped GPU test befor…
smazouz42 May 29, 2024
e2c2f05
Cleaning up my PR.
smazouz42 May 29, 2024
7f9f540
Cleaning up my PR.
smazouz42 May 29, 2024
0bb9970
Cleaning up my PR.
smazouz42 May 29, 2024
4bfd4c8
passing args to kernel function in tests
smazouz42 May 30, 2024
002d358
cleaning upmy PR
smazouz42 May 30, 2024
14866e9
cleaning upmy PR
smazouz42 May 30, 2024
b65de61
cleaning upmy PR
smazouz42 May 31, 2024
8da4b8b
cleaning upmy PR
smazouz42 May 31, 2024
5af90a4
cleaning upmy PR
smazouz42 May 31, 2024
26cf144
cleaning up my PR
smazouz42 Jun 4, 2024
fa92012
fix doc string of_handle_kernel
smazouz42 Jun 4, 2024
5f2df09
removing unnecessary lines
smazouz42 Jun 4, 2024
b487769
write clear doc string
smazouz42 Jun 5, 2024
d4d7ca4
adding cuda module to CHANGELOG and fixing
smazouz42 Jun 5, 2024
3d9c33d
Removing useless lines and adding one for readability
smazouz42 Jun 5, 2024
b000bd9
using join to avoid allocating memory for the list
smazouz42 Jun 5, 2024
730e69b
cleaning up my PR
smazouz42 Jun 5, 2024
9e97280
removing comment line that I used for debugging and cleaning the code
smazouz42 Jun 5, 2024
3c2967c
cleaning up my PR
smazouz42 Jun 5, 2024
81c5292
replace lunch_confiq with indexes
smazouz42 Jun 6, 2024
3e7d535
cleaning up my PR
smazouz42 Jun 7, 2024
049c3b7
cleaning up my PR
smazouz42 Jun 7, 2024
ba56731
refactoryhing cuda module
smazouz42 Jun 7, 2024
2cf6ed0
refactoring the code
smazouz42 Jun 7, 2024
4307d67
renaming cuda submodule and cleaning up the code
smazouz42 Jun 10, 2024
2ce3bf2
cleaning up the code
smazouz42 Jun 10, 2024
7da5235
adding newline
smazouz42 Jun 10, 2024
51346a1
cleaning up the code
smazouz42 Jun 10, 2024
d6a4291
changing the type of arg kernel in docstring to something more specific
smazouz42 Jun 10, 2024
1b5ad2e
cleaning up the code
smazouz42 Jun 10, 2024
53a852d
fixing kernel class docstring
smazouz42 Jun 11, 2024
ff8e26d
Reverse logic of execution in GPU to make it not affect other tests.
smazouz42 Jun 11, 2024
70e7cdf
move f function to main section
smazouz42 Jun 11, 2024
f9c61f8
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
f3662c2
Add cuda workflow to test cuda developments on CI
EmilyBourne Mar 11, 2024
4061a1f
Trigger tests on push to devel or main branch
EmilyBourne Mar 11, 2024
c84b86a
[init] Adding CUDA language/compiler and CodePrinter (#32)
bauom Feb 28, 2024
8fc32f4
Fix import handling (#49)
smazouz42 May 15, 2024
544497f
Merge branch 'devel' of https://github.com/pyccel/pyccel-cuda into fe…
smazouz42 Jun 12, 2024
a54eda1
refactoring function_signature
smazouz42 Jun 12, 2024
8d2440d
fix: fixing import problem
smazouz42 Jun 12, 2024
adad61a
Add error message for invalid launch configuration with incorrect par…
smazouz42 Jun 12, 2024
d7c805e
refactoring the code
smazouz42 Jun 13, 2024
0712ae7
adding file that I removed by mistake
smazouz42 Jun 13, 2024
075f737
refactoring the code
smazouz42 Jun 13, 2024
4d06447
Change doc string for arg passed to kernel call to any
smazouz42 Jun 13, 2024
5b97ac7
Merge branch 'feat/kernels-support-25' of https://github.com/pyccel/p…
smazouz42 Jun 19, 2024
ddda4e6
fix some doc errors
smazouz42 Jun 20, 2024
d2a0c48
fix some doc errors
smazouz42 Jun 20, 2024
463b8c2
Test specific problem
EmilyBourne Jun 21, 2024
86182c5
Add investigative prints
EmilyBourne Jun 21, 2024
a6dd5f3
debuging perpose
smazouz42 Jun 23, 2024
a24effa
debuging perpose
smazouz42 Jun 24, 2024
3212b1f
debuging perpose
smazouz42 Jun 24, 2024
d69c63d
debuging perpose
smazouz42 Jun 24, 2024
8583af9
debuging perpose
smazouz42 Jun 24, 2024
d6700f6
debuging perpose
smazouz42 Jun 24, 2024
dc4659d
debuging perpose
smazouz42 Jun 24, 2024
466a625
pin the numpy version
smazouz42 Jun 24, 2024
ec71ed2
pin the numpy version
smazouz42 Jun 24, 2024
083beb1
change arg doc in handle kernel from any to tuple
smazouz42 Jun 24, 2024
750ade3
debuging perpose
smazouz42 Jun 24, 2024
f32042f
pin the numpy version
smazouz42 Jun 24, 2024
1a4527c
refactoring the code
smazouz42 Jun 25, 2024
d04d3b8
refactoring the code
smazouz42 Jun 25, 2024
162c5e8
refactoring the code
smazouz42 Jun 25, 2024
1f19376
refactoring the code
smazouz42 Jun 25, 2024
e47bdd9
changing cuda submodel name and refactoring the code
smazouz42 Jun 25, 2024
4a9e3b3
refactoring the code
smazouz42 Jun 25, 2024
53d696e
removing unused import and adding doc string to KernelAccessor
smazouz42 Jun 25, 2024
82cff83
change the way i import synchronize
smazouz42 Jun 25, 2024
6da52ab
adding ret section to Kernel class
smazouz42 Jun 25, 2024
92fbf54
trying to fix a doc problem
smazouz42 Jun 25, 2024
312d389
trying to fix a doc problem
smazouz42 Jun 25, 2024
7def545
fix a doc problem
smazouz42 Jun 25, 2024
07cf232
refactoring the code
smazouz42 Jun 26, 2024
d0e5d93
refactoring the code
smazouz42 Jun 26, 2024
9aed2f5
refactoring the code
smazouz42 Jun 26, 2024
a38b3f4
catch error in case the function Undefined indexed function call
smazouz42 Jun 26, 2024
1b84236
Merge branch 'devel' of https://github.com/pyccel/pyccel-cuda into fe…
smazouz42 Jun 27, 2024
e4fc902
adding test for name collision for the kernel call
smazouz42 Jun 27, 2024
84c1b53
refactoring the code
smazouz42 Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dict_custom.txt
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,4 @@ datatyping
datatypes
indexable
traceback
GPUs
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ All notable changes to this project will be documented in this file.

- #32 : Add support for `nvcc` Compiler and `cuda` language as a possible option.
- #48 : Fix incorrect handling of imports in `cuda`.
- #42 : Add support for custom kernel in`cuda`.
- #42 : Add Cuda module to Pyccel. Add support for `cuda.synchronize` function.

## \[UNRELEASED\]

Expand Down
23 changes: 23 additions & 0 deletions docs/cuda.md
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]()

```
37 changes: 37 additions & 0 deletions pyccel/ast/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,61 +37,62 @@

# TODO [YG, 12.03.2020]: Move non-Python constructs to other modules
# TODO [YG, 12.03.2020]: Rename classes to avoid name clashes in pyccel/ast
__all__ = (
'AliasAssign',
'Allocate',
'AnnotatedComment',
'AsName',
'Assert',
'Assign',
'AugAssign',
'Break',
'ClassDef',
'CodeBlock',
'Comment',
'CommentBlock',
'Concatenate',
'ConstructorCall',
'Continue',
'Deallocate',
'Declare',
'Decorator',
'Del',
'DoConcurrent',
'Duplicate',
'EmptyNode',
'ErrorExit',
'Exit',
'For',
'FuncAddressDeclare',
'FunctionAddress',
'FunctionCall',
'FunctionCallArgument',
'FunctionDef',
'FunctionDefArgument',
'FunctionDefResult',
'If',
'IfSection',
'Import',
'IndexedFunctionCall',
'InProgram',
'InlineFunctionDef',
'Interface',
'Iterable',
'Module',
'ModuleHeader',
'Pass',
'Program',
'PyccelFunctionDef',
'Raise',
'Return',
'SeparatorComment',
'StarredArguments',
'SymbolicAssign',
'SymbolicPrint',
'SympyFunction',
'While',
'With',
)

Check warning on line 95 in pyccel/ast/core.py

View check run for this annotation

Pyccel Bot / Pyccel best practices (pyccel_lint, 3.8)

pyccel/ast/core.py#L40-L95

Sort the __all__ attribute of `core`

#==============================================================================

Expand Down Expand Up @@ -2065,6 +2066,42 @@
"""
return c is None or isinstance(c, (FunctionDef, *cls._ignored_types))

class IndexedFunctionCall(FunctionCall):
"""
Represents an indexed function call in the code.

Class representing indexed function calls, encapsulating all
relevant information for such calls within the code base.

Parameters
----------
func : FunctionDef
The function being called.

args : iterable of FunctionCallArgument
The arguments passed to the function.

indexes : iterable of TypedAstNode
The indexes of the function call.

current_function : FunctionDef, optional
The function where the call takes place.
"""
__slots__ = ('_indexes',)
_attribute_nodes = FunctionCall._attribute_nodes + ('_indexes',)
def __init__(self, func, args, indexes, current_function = None):
self._indexes = indexes
super().__init__(func, args, current_function)

@property
def indexes(self):
"""
Indexes of function call.

Represents the indexes of the function call
"""
return self._indexes

class ConstructorCall(FunctionCall):

"""
Expand Down
65 changes: 65 additions & 0 deletions pyccel/ast/cuda.py
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

42 changes: 42 additions & 0 deletions pyccel/ast/cudaext.py
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=[]
)

4 changes: 3 additions & 1 deletion pyccel/ast/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .literals import LiteralInteger, LiteralEllipsis, Nil
from .mathext import math_mod
from .sysext import sys_mod
from .cudaext import cuda_mod

from .numpyext import (NumpyEmpty, NumpyArray, numpy_mod,
NumpyTranspose, NumpyLinspace)
Expand All @@ -49,7 +50,8 @@
decorators_mod = Module('decorators',(),
funcs = [PyccelFunctionDef(d, PyccelFunction) for d in pyccel_decorators.__all__])
pyccel_mod = Module('pyccel',(),(),
imports = [Import('decorators', decorators_mod)])
imports = [Import('decorators', decorators_mod),
Import('cuda', cuda_mod)])

# TODO add documentation
builtin_import_registry = Module('__main__',
Expand Down
46 changes: 43 additions & 3 deletions pyccel/codegen/printing/cucode.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
enabling the direct translation of high-level Pyccel expressions into CUDA code.
"""

EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
from pyccel.codegen.printing.ccode import CCodePrinter, c_library_headers
from pyccel.codegen.printing.ccode import CCodePrinter

from pyccel.ast.core import Import, Module
from pyccel.ast.core import Import, Module
from pyccel.ast.literals import Nil

from pyccel.errors.errors import Errors
from pyccel.errors.errors import Errors


errors = Errors()
Expand Down Expand Up @@ -61,6 +62,44 @@ def _print_Module(self, expr):
self.exit_scope()
return code

def function_signature(self, expr, print_arg_names = True):
"""
Get the Cuda representation of the function signature.

Extract from the function definition `expr` all the
information (name, input, output) needed to create the
function signature and return a string describing the
function.
This is not a declaration as the signature does not end
with a semi-colon.

Parameters
----------
expr : FunctionDef
The function definition for which a signature is needed.

print_arg_names : bool, default : True
jalalium marked this conversation as resolved.
Show resolved Hide resolved
Indicates whether argument names should be printed.

Returns
-------
str
Signature of the function.
"""
cuda_decorater = '__global__' if 'kernel' in expr.decorators else ''
c_function_signature = super().function_signature(expr, print_arg_names)
return f'{cuda_decorater} {c_function_signature}'

def _print_KernelCall(self, expr):
func = expr.funcdef
args = [a.value or Nil() for a in expr.args]

args = ', '.join(self._print(a) for a in args)
return f"{func.name}<<<{expr.num_blocks}, {expr.tp_block}>>>({args});\n"

def _print_CudaSynchronize(self, expr):
return 'cudaDeviceSynchronize();\n'

def _print_ModuleHeader(self, expr):
self.set_scope(expr.module.scope)
self._in_header = True
Expand All @@ -87,6 +126,7 @@ def _print_ModuleHeader(self, expr):
}}\n'
return '\n'.join((f"#ifndef {name.upper()}_H",
f"#define {name.upper()}_H",
imports,
EmilyBourne marked this conversation as resolved.
Show resolved Hide resolved
global_variables,
function_declaration,
"#endif // {name.upper()}_H\n"))
Expand Down
10 changes: 10 additions & 0 deletions pyccel/cuda/__init__.py
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']
16 changes: 16 additions & 0 deletions pyccel/cuda/cuda_sync_primitives.py
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.
"""

32 changes: 32 additions & 0 deletions pyccel/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'sympy',
'template',
'types',
'kernel'
)


Expand Down Expand Up @@ -109,3 +110,34 @@ def allow_negative_index(f,*args):
def identity(f):
return f
return identity

def kernel(f):
"""
Decorator for marking a Python function as a kernel.

This class serves as a decorator to mark a Python function
as a kernel function, typically used for GPU computations.
This allows the function to be indexed with the number of blocks and threads.

Parameters
----------
f : function
The function to which the decorator is applied.

Returns
-------
KernelAccessor
A class representing the kernel function.
"""
class KernelAccessor:
"""
Class representing the kernel function.

Class representing the kernel function.
"""
def __init__(self, f):
self._f = f
def __getitem__(self, args):
return self._f

return KernelAccessor(f)
8 changes: 8 additions & 0 deletions pyccel/errors/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,11 @@
WRONG_LINSPACE_ENDPOINT = 'endpoint argument must be boolean'
NON_LITERAL_KEEP_DIMS = 'keep_dims argument must be a literal, otherwise rank is unknown'
NON_LITERAL_AXIS = 'axis argument must be a literal, otherwise pyccel cannot determine which dimension to operate on'
MISSING_KERNEL_CONFIGURATION = 'Kernel launch configuration not specified'
INVALID_KERNEL_LAUNCH_CONFIG = 'Expected exactly 2 parameters for kernel launch'
INVALID_KERNEL_CALL_BP_GRID = 'Invalid Block per grid parameter for Kernel call'
INVALID_KERNEL_CALL_TP_BLOCK = 'Invalid Thread per Block parameter for Kernel call'




Loading
Loading