4 from .
import cudart, check_error
8 cudaKeyValuePair = ctypes.c_int(0)
9 cudaCSV = ctypes.c_int(1)
13 if key ==
'key_value':
14 return cudaOutputMode.cudaKeyValuePair
16 return cudaOutputMode.cudaCSV
18 raise RuntimeError(
"supported CUDA profiler output modes are: key_value and csv")
31 def init(output_file, flags=None, output_mode='key_value'):
32 flags = DEFAULT_FLAGS
if flags
is None else flags
33 output_mode = cudaOutputMode.for_key(output_mode)
34 with tempfile.NamedTemporaryFile(delete=
True)
as f:
35 f.write(b
'\n'.join(map(
lambda f: f.encode(
'ascii'), flags)))
37 check_error(cudart().cudaProfilerInitialize(
38 ctypes.c_char_p(f.name.encode(
'ascii')), ctypes.c_char_p(output_file.encode(
'ascii')), output_mode))
42 check_error(cudart().cudaProfilerStart())
46 check_error(cudart().cudaProfilerStop())
49 @contextlib.contextmanager