Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Fix the regular expression in RTC code (#20810) (#20840)
Browse files Browse the repository at this point in the history
Co-authored-by: Przemyslaw Tredak <[email protected]>
  • Loading branch information
josephevans and ptrendx authored Jan 25, 2022
1 parent 33c0c8e commit ac4c8dc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions python/mxnet/rtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,22 @@ def get_kernel(self, name, signature):
is_ndarray = []
is_const = []
dtypes = []
pattern = re.compile(r"""^\s*(const)?\s*([\w_]+)\s*(\*)?\s*([\w_]+)?\s*$""")
pattern = re.compile(r"""^(const)?\s?([\w_]+)\s?(\*)?\s?([\w_]+)?$""")
args = re.sub(r"\s+", " ", signature).split(",")
for arg in args:
match = pattern.match(arg)
sanitized_arg = " ".join(arg.split())
match = pattern.match(sanitized_arg)
if not match or match.groups()[1] == 'const':
raise ValueError(
'Invalid function prototype "%s". Must be in the '
'form of "(const) type (*) (name)"'%arg)
'form of "(const) type (*) (name)"'%sanitized_arg)
is_const.append(bool(match.groups()[0]))
dtype = match.groups()[1]
is_ndarray.append(bool(match.groups()[2]))
if dtype not in _DTYPE_CPP_TO_NP:
raise TypeError(
"Unsupported kernel argument type %s. Supported types are: %s."%(
arg, ','.join(_DTYPE_CPP_TO_NP.keys())))
sanitized_arg, ','.join(_DTYPE_CPP_TO_NP.keys())))
dtypes.append(_DTYPE_NP_TO_MX[_DTYPE_CPP_TO_NP[dtype]])

check_call(_LIB.MXRtcCudaKernelCreate(
Expand Down

0 comments on commit ac4c8dc

Please sign in to comment.