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.
Feature: Improve Kernel Decorator (#69)
This pull request addresses issue #68 by changing the implantation of kernel decorate, so the function runs multiple times depending on the number of blocks and the number of threads for each block --------- Co-authored-by: EmilyBourne <[email protected]> Co-authored-by: bauom <[email protected]>
- Loading branch information
1 parent
f6ac853
commit de362d3
Showing
8 changed files
with
181 additions
and
3 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
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,88 @@ | ||
#------------------------------------------------------------------------------------------# | ||
# 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 contains all the CUDA thread indexing methods | ||
""" | ||
class CudaThreadIndexing: | ||
""" | ||
Class representing the CUDA thread indexing. | ||
Class representing the CUDA thread indexing. | ||
Parameters | ||
---------- | ||
block_idx : int | ||
The index of the block in the x-dimension. | ||
thread_idx : int | ||
The index of the thread in the x-dimension. | ||
""" | ||
def __init__(self, block_idx, thread_idx): | ||
self._block_idx = block_idx | ||
self._thread_idx = thread_idx | ||
|
||
def threadIdx(self, dim): | ||
""" | ||
Get the thread index. | ||
Get the thread index. | ||
Parameters | ||
---------- | ||
dim : int | ||
The dimension of the indexing. It can be: | ||
- 0 for the x-dimension | ||
- 1 for the y-dimension | ||
- 2 for the z-dimension | ||
Returns | ||
------- | ||
int | ||
The index of the thread in the specified dimension of its block. | ||
""" | ||
return self._thread_idx | ||
|
||
def blockIdx(self, dim): | ||
""" | ||
Get the block index. | ||
Get the block index. | ||
Parameters | ||
---------- | ||
dim : int | ||
The dimension of the indexing. It can be: | ||
- 0 for the x-dimension | ||
- 1 for the y-dimension | ||
- 2 for the z-dimension | ||
Returns | ||
------- | ||
int | ||
The index of the block in the specified dimension. | ||
""" | ||
return self._block_idx | ||
|
||
def blockDim(self, dim): | ||
""" | ||
Get the block dimension. | ||
Get the block dimension. | ||
Parameters | ||
---------- | ||
dim : int | ||
The dimension of the indexing. It can be: | ||
- 0 for the x-dimension | ||
- 1 for the y-dimension | ||
- 2 for the z-dimension | ||
Returns | ||
------- | ||
int | ||
The size of the block in the specified dimension. | ||
""" | ||
return 0 | ||
|
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,15 @@ | ||
# pylint: disable=missing-function-docstring, missing-module-docstring | ||
from pyccel.decorators import kernel | ||
from pyccel import cuda | ||
|
||
@kernel | ||
def print_block(): | ||
print(cuda.blockIdx(0)) # pylint: disable=no-member | ||
|
||
def f(): | ||
print_block[5,5]() | ||
cuda.synchronize() | ||
|
||
if __name__ == '__main__': | ||
f() | ||
|
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,15 @@ | ||
# pylint: disable=missing-function-docstring, missing-module-docstring | ||
from pyccel.decorators import kernel | ||
from pyccel import cuda | ||
|
||
@kernel | ||
def print_block(): | ||
print(cuda.threadIdx(0)) # pylint: disable=no-member | ||
|
||
def f(): | ||
print_block[5,5]() | ||
cuda.synchronize() | ||
|
||
if __name__ == '__main__': | ||
f() | ||
|
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