Changeset 74e9b5f in sasmodels for sasmodels/kernelcuda.py
- Timestamp:
- Oct 12, 2018 10:52:48 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 4de14584
- Parents:
- b0de252
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernelcuda.py
rb0de252 r74e9b5f 62 62 import logging 63 63 import time 64 import re 64 65 65 66 import numpy as np # type: ignore … … 146 147 return dtype in (generate.F32, generate.F64) 147 148 149 150 FUNCTION_PATTERN = re.compile(r"""^ 151 (?P<space>\s*) # initial space 152 (?P<qualifiers>^(?:\s*\b\w+\b\s*)+) # one or more qualifiers before function 153 (?P<function>\s*\b\w+\b\s*[(]) # function name plus open parens 154 """, re.VERBOSE|re.MULTILINE) 155 156 MARKED_PATTERN = re.compile(r""" 157 \b(return|else|kernel|device|__device__)\b 158 """, re.VERBOSE|re.MULTILINE) 159 160 def _add_device_tag(match): 161 # type: (None) -> str 162 # Note: should be re.Match, but that isn't a simple type 163 """ 164 replace qualifiers with __device__ qualifiers if needed 165 """ 166 qualifiers = match.group("qualifiers") 167 if MARKED_PATTERN.search(qualifiers): 168 start, end = match.span() 169 return match.string[start:end] 170 else: 171 function = match.group("function") 172 space = match.group("space") 173 return "".join((space, "__device__ ", qualifiers, function)) 174 175 def mark_device_functions(source): 176 # type: (str) -> str 177 """ 178 Mark all function declarations as __device__ functions (except kernel). 179 """ 180 return FUNCTION_PATTERN.sub(_add_device_tag, source) 181 182 def show_device_functions(source): 183 # type: (str) -> str 184 """ 185 Show all discovered function declarations, but don't change any. 186 """ 187 for match in FUNCTION_PATTERN.finditer(source): 188 print(match.group('qualifiers').replace('\n',r'\n'), match.group('function'), '(') 189 return source 190 148 191 def compile_model(source, dtype, fast=False): 149 192 # type: (str, np.dtype, bool) -> SourceModule … … 163 206 source_list.insert(0, "#define USE_SINCOS\n") 164 207 source = "\n".join(source_list) 165 options = '-use_fast_math' if fast else None 208 #source = show_device_functions(source) 209 source = mark_device_functions(source) 210 #with open('/tmp/kernel.cu', 'w') as fd: fd.write(source) 211 #print(source) 212 #options = ['--verbose', '-E'] 213 options = ['--use_fast_math'] if fast else None 166 214 program = SourceModule(source, no_extern_c=True, options=options) # include_dirs=[...] 215 167 216 #print("done with "+program) 168 217 return program
Note: See TracChangeset
for help on using the changeset viewer.