Skip to content

Commit

Permalink
Updated CUDA Name Clash Checker By Added CUDA-specific keywords (#60)
Browse files Browse the repository at this point in the history
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 <louise.bourne@gmail.com>
Co-authored-by: bauom <40796259+bauom@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 3, 2024
1 parent b8de68d commit aa367fa
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ 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`.
- #59 : Updated `cuda` clash checker.
- #42 : Add support for custom kernel in`cuda`.
- #42 : Add Cuda module to Pyccel. Add support for `cuda.synchronize` function.

Expand Down
36 changes: 35 additions & 1 deletion pyccel/naming/cudanameclashchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class CudaNameClashChecker(LanguageNameClashChecker):
verify that they do not cause name clashes. Name clashes may be due to
new variables, or due to the use of reserved keywords.
"""

# Keywords as mentioned on https://en.cppreference.com/w/c/keyword
keywords = set(['isign', 'fsign', 'csign', 'auto', 'break', 'case', 'char', 'const',
'continue', 'default', 'do', 'double', 'else', 'enum',
Expand All @@ -37,7 +38,40 @@ class CudaNameClashChecker(LanguageNameClashChecker):
'GET_INDEX_FUNC_H2', 'GET_INDEX_FUNC', 'GET_INDEX',
'INDEX', 'GET_ELEMENT', 'free_array', 'free_pointer',
'get_index', 'numpy_to_ndarray_strides',
'numpy_to_ndarray_shape', 'get_size', 'order_f', 'order_c', 'array_copy_data'])
'numpy_to_ndarray_shape', 'get_size', 'order_f', 'order_c', 'array_copy_data'
'__global__', '__device__', '__host__','__constant__', '__shared__',
'__managed__','threadIdx', 'blockIdx', 'blockDim', 'gridDim',
'warpSize', 'cudaMalloc', 'cudaFree', 'cudaMemcpy', 'cudaMemset',
'cudaMallocHost', 'cudaFreeHost', 'cudaMallocPitch',
'cudaMallocArray', 'cudaFreeArray', 'cudaHostAlloc',
'cudaHostRegister', 'cudaHostUnregister', 'cudaHostGetDevicePointer',
'cudaHostGetFlags', 'cudaDeviceSynchronize', 'cudaDeviceReset',
'cudaSetDevice', 'cudaGetDeviceCount', 'cudaGetDeviceProperties',
'cudaChooseDevice', 'cudaSetDeviceFlags', 'cudaGetDevice',
'cudaStreamCreate', 'cudaStreamDestroy', 'cudaStreamSynchronize',
'cudaStreamWaitEvent', 'cudaEventCreate', 'cudaEventDestroy', 'cudaEventRecord',
'cudaEventSynchronize', 'cudaEventElapsedTime', 'cuInit', 'cuDeviceGet',
'cuDeviceGetCount', 'cuDeviceGetName',
'cuDeviceComputeCapability', 'cuCtxCreate', 'cuCtxDestroy',
'cuCtxSynchronize', 'cuModuleLoad', 'cuModuleUnload',
'cuModuleGetFunction', 'cuModuleGetGlobal', 'cuModuleGetTexRef',
'cuMemAlloc', 'cuMemFree', 'cuMemcpyHtoD', 'cuMemcpyDtoH',
'cuMemcpyDtoD', 'cuMemcpyHtoDAsync', 'cuMemcpyDtoHAsync',
'cuMemcpyDtoDAsync', 'cuMemsetD8', 'cuMemsetD16', 'cuMemsetD32',
'cuMemsetD2D8', 'cuMemsetD2D16', 'cuMemsetD2D32', 'cuParamSetSize',
'cuParamSeti', 'cuParamSetf', 'cuParamSetv', 'cuLaunch', 'cuLaunchGrid',
'cuLaunchGridAsync', 'cuEventCreate', 'cuEventRecord', 'cuEventQuery',
'cuEventSynchronize', 'cuEventDestroy', 'cuEventElapsedTime',
'cuStreamCreate', 'cuStreamQuery', 'cuStreamSynchronize',
'cuStreamDestroy', 'cuFuncSetBlockShape', 'cuFuncSetSharedSize',
'cuFuncGetAttribute', 'cuTexRefCreate', 'cuTexRefDestroy',
'cuTexRefSetArray', 'cuTexRefSetAddress', 'cuTexRefSetAddress2D',
'cuTexRefSetFormat', 'cuTexRefSetAddressMode', 'cuTexRefSetFilterMode',
'cuTexRefSetFlags', 'cuTexRefGetAddress', 'cuTexRefGetArray',
'cuTexRefGetAddressMode', 'cuTexRefGetFilterMode', 'cuTexRefGetFormat',
'cuTexRefGetFlags', 'cuLaunchKernel', 'cuOccupancyMaxActiveBlocksPerMultiprocessor',
'cuOccupancyMaxPotentialBlockSize', 'cuOccupancyMaxPotentialBlockSizeWithFlags'
])

def has_clash(self, name, symbols):
"""
Expand Down
5 changes: 5 additions & 0 deletions pyccel/naming/languagenameclashchecker.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class LanguageNameClashChecker(metaclass = Singleton):
"""
keywords = None

def __init__(self): #pylint: disable=useless-parent-delegation
# This __init__ function is required so the ArgumentSingleton can
# always detect a signature
super().__init__()

def _get_collisionless_name(self, name, symbols):
"""
Get a name which doesn't collision with keywords or symbols.
Expand Down

0 comments on commit aa367fa

Please sign in to comment.