Skip to content

Commit 4ac5182

Browse files
smazouz42EmilyBournebauom
committed
Updated CUDA Name Clash Checker By Added CUDA-specific keywords (#60)
This pull request addresses issue #59 by adding more CUDA-specific keywords to enhance the checking of variable/function names and prevent name clashes --------- Co-authored-by: EmilyBourne <[email protected]> Co-authored-by: bauom <[email protected]>
1 parent b3de549 commit 4ac5182

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
77

88
- #32 : Add support for `nvcc` Compiler and `cuda` language as a possible option.
99
- #48 : Fix incorrect handling of imports in `cuda`.
10+
- #59 : Updated `cuda` clash checker.
1011
- #42 : Add support for custom kernel in`cuda`.
1112
- #42 : Add Cuda module to Pyccel. Add support for `cuda.synchronize` function.
1213

pyccel/naming/cudanameclashchecker.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CudaNameClashChecker(LanguageNameClashChecker):
1616
verify that they do not cause name clashes. Name clashes may be due to
1717
new variables, or due to the use of reserved keywords.
1818
"""
19+
1920
# Keywords as mentioned on https://en.cppreference.com/w/c/keyword
2021
keywords = set(['isign', 'fsign', 'csign', 'auto', 'break', 'case', 'char', 'const',
2122
'continue', 'default', 'do', 'double', 'else', 'enum',
@@ -37,7 +38,40 @@ class CudaNameClashChecker(LanguageNameClashChecker):
3738
'GET_INDEX_FUNC_H2', 'GET_INDEX_FUNC', 'GET_INDEX',
3839
'INDEX', 'GET_ELEMENT', 'free_array', 'free_pointer',
3940
'get_index', 'numpy_to_ndarray_strides',
40-
'numpy_to_ndarray_shape', 'get_size', 'order_f', 'order_c', 'array_copy_data'])
41+
'numpy_to_ndarray_shape', 'get_size', 'order_f', 'order_c', 'array_copy_data'
42+
'__global__', '__device__', '__host__','__constant__', '__shared__',
43+
'__managed__','threadIdx', 'blockIdx', 'blockDim', 'gridDim',
44+
'warpSize', 'cudaMalloc', 'cudaFree', 'cudaMemcpy', 'cudaMemset',
45+
'cudaMallocHost', 'cudaFreeHost', 'cudaMallocPitch',
46+
'cudaMallocArray', 'cudaFreeArray', 'cudaHostAlloc',
47+
'cudaHostRegister', 'cudaHostUnregister', 'cudaHostGetDevicePointer',
48+
'cudaHostGetFlags', 'cudaDeviceSynchronize', 'cudaDeviceReset',
49+
'cudaSetDevice', 'cudaGetDeviceCount', 'cudaGetDeviceProperties',
50+
'cudaChooseDevice', 'cudaSetDeviceFlags', 'cudaGetDevice',
51+
'cudaStreamCreate', 'cudaStreamDestroy', 'cudaStreamSynchronize',
52+
'cudaStreamWaitEvent', 'cudaEventCreate', 'cudaEventDestroy', 'cudaEventRecord',
53+
'cudaEventSynchronize', 'cudaEventElapsedTime', 'cuInit', 'cuDeviceGet',
54+
'cuDeviceGetCount', 'cuDeviceGetName',
55+
'cuDeviceComputeCapability', 'cuCtxCreate', 'cuCtxDestroy',
56+
'cuCtxSynchronize', 'cuModuleLoad', 'cuModuleUnload',
57+
'cuModuleGetFunction', 'cuModuleGetGlobal', 'cuModuleGetTexRef',
58+
'cuMemAlloc', 'cuMemFree', 'cuMemcpyHtoD', 'cuMemcpyDtoH',
59+
'cuMemcpyDtoD', 'cuMemcpyHtoDAsync', 'cuMemcpyDtoHAsync',
60+
'cuMemcpyDtoDAsync', 'cuMemsetD8', 'cuMemsetD16', 'cuMemsetD32',
61+
'cuMemsetD2D8', 'cuMemsetD2D16', 'cuMemsetD2D32', 'cuParamSetSize',
62+
'cuParamSeti', 'cuParamSetf', 'cuParamSetv', 'cuLaunch', 'cuLaunchGrid',
63+
'cuLaunchGridAsync', 'cuEventCreate', 'cuEventRecord', 'cuEventQuery',
64+
'cuEventSynchronize', 'cuEventDestroy', 'cuEventElapsedTime',
65+
'cuStreamCreate', 'cuStreamQuery', 'cuStreamSynchronize',
66+
'cuStreamDestroy', 'cuFuncSetBlockShape', 'cuFuncSetSharedSize',
67+
'cuFuncGetAttribute', 'cuTexRefCreate', 'cuTexRefDestroy',
68+
'cuTexRefSetArray', 'cuTexRefSetAddress', 'cuTexRefSetAddress2D',
69+
'cuTexRefSetFormat', 'cuTexRefSetAddressMode', 'cuTexRefSetFilterMode',
70+
'cuTexRefSetFlags', 'cuTexRefGetAddress', 'cuTexRefGetArray',
71+
'cuTexRefGetAddressMode', 'cuTexRefGetFilterMode', 'cuTexRefGetFormat',
72+
'cuTexRefGetFlags', 'cuLaunchKernel', 'cuOccupancyMaxActiveBlocksPerMultiprocessor',
73+
'cuOccupancyMaxPotentialBlockSize', 'cuOccupancyMaxPotentialBlockSizeWithFlags'
74+
])
4175

4276
def has_clash(self, name, symbols):
4377
"""

pyccel/naming/languagenameclashchecker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class LanguageNameClashChecker(metaclass = Singleton):
1919
"""
2020
keywords = None
2121

22+
def __init__(self): #pylint: disable=useless-parent-delegation
23+
# This __init__ function is required so the ArgumentSingleton can
24+
# always detect a signature
25+
super().__init__()
26+
2227
def _get_collisionless_name(self, name, symbols):
2328
"""
2429
Get a name which doesn't collision with keywords or symbols.

0 commit comments

Comments
 (0)