Skip to content

Commit becc33c

Browse files
committed
Fix #789: Remove cyclical import between driver and _lib.utils
1 parent 6b8ae2b commit becc33c

12 files changed

Lines changed: 347 additions & 346 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ __pycache__/
1616
cache_driver
1717
cache_runtime
1818
cache_nvrtc
19+
cuda_bindings/cuda/bindings/_lib/utils.pxi
1920

2021
# CUDA Python specific (auto-generated)
2122
cuda_bindings/cuda/bindings/_bindings/cydriver.pxd

cuda_bindings/cuda/bindings/_lib/param_packer.h

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
11
// SPDX-FileCopyrightText: Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
// SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4+
// Please refer to the NVIDIA end user license agreement (EULA) associated
5+
// with this source code for terms and conditions that govern your use of
6+
// this software. Any use, reproduction, disclosure, or distribution of
7+
// this software and related documentation outside the terms of the EULA
8+
// is strictly prohibited.
9+
410
#include <Python.h>
5-
#include "param_packer.h"
611

712
#include <map>
813
#include <functional>
914
#include <stdexcept>
1015
#include <string>
1116

12-
PyObject* enum_module = nullptr;
13-
PyTypeObject* enum_Enum = nullptr;
14-
15-
PyObject* ctypes_module = nullptr;
16-
PyObject* ctypes_addressof = nullptr;
17-
PyObject* addressof_param_tuple = nullptr;
17+
static PyObject* ctypes_module = nullptr;
1818

19-
PyTypeObject* ctypes_c_char = nullptr;
20-
PyTypeObject* ctypes_c_bool = nullptr;
21-
PyTypeObject* ctypes_c_wchar = nullptr;
22-
PyTypeObject* ctypes_c_byte = nullptr;
23-
PyTypeObject* ctypes_c_ubyte = nullptr;
24-
PyTypeObject* ctypes_c_short = nullptr;
25-
PyTypeObject* ctypes_c_ushort = nullptr;
26-
PyTypeObject* ctypes_c_int = nullptr;
27-
PyTypeObject* ctypes_c_uint = nullptr;
28-
PyTypeObject* ctypes_c_long = nullptr;
29-
PyTypeObject* ctypes_c_ulong = nullptr;
30-
PyTypeObject* ctypes_c_longlong = nullptr;
31-
PyTypeObject* ctypes_c_ulonglong = nullptr;
32-
PyTypeObject* ctypes_c_size_t = nullptr;
33-
PyTypeObject* ctypes_c_float = nullptr;
34-
PyTypeObject* ctypes_c_double = nullptr;
35-
PyTypeObject* ctypes_c_void_p = nullptr;
19+
static PyTypeObject* ctypes_c_char = nullptr;
20+
static PyTypeObject* ctypes_c_bool = nullptr;
21+
static PyTypeObject* ctypes_c_wchar = nullptr;
22+
static PyTypeObject* ctypes_c_byte = nullptr;
23+
static PyTypeObject* ctypes_c_ubyte = nullptr;
24+
static PyTypeObject* ctypes_c_short = nullptr;
25+
static PyTypeObject* ctypes_c_ushort = nullptr;
26+
static PyTypeObject* ctypes_c_int = nullptr;
27+
static PyTypeObject* ctypes_c_uint = nullptr;
28+
static PyTypeObject* ctypes_c_long = nullptr;
29+
static PyTypeObject* ctypes_c_ulong = nullptr;
30+
static PyTypeObject* ctypes_c_longlong = nullptr;
31+
static PyTypeObject* ctypes_c_ulonglong = nullptr;
32+
static PyTypeObject* ctypes_c_size_t = nullptr;
33+
static PyTypeObject* ctypes_c_float = nullptr;
34+
static PyTypeObject* ctypes_c_double = nullptr;
35+
static PyTypeObject* ctypes_c_void_p = nullptr;
3636

37-
PyTypeObject* ctypes_c_ssize_t = nullptr;
38-
PyTypeObject* ctypes_c_longdouble = nullptr;
39-
PyTypeObject* ctypes_c_char_p = nullptr;
40-
PyTypeObject* ctypes_c_wchar_p = nullptr;
41-
PyTypeObject* ctypes_c_structure = nullptr;
42-
43-
void fetch_ctypes()
37+
static void fetch_ctypes()
4438
{
4539
ctypes_module = PyImport_ImportModule("ctypes");
4640
if (ctypes_module == nullptr)
@@ -50,7 +44,6 @@ void fetch_ctypes()
5044
if (ctypes_dict == nullptr)
5145
throw std::runtime_error(std::string("FAILURE @ ") + std::string(__FILE__) + " : " + std::to_string(__LINE__));
5246
// supportedtypes
53-
ctypes_c_int = (PyTypeObject*) PyDict_GetItemString(ctypes_dict, "c_int");
5447
ctypes_c_char = (PyTypeObject*) PyDict_GetItemString(ctypes_dict, "c_char");
5548
ctypes_c_bool = (PyTypeObject*) PyDict_GetItemString(ctypes_dict, "c_bool");
5649
ctypes_c_wchar = (PyTypeObject*) PyDict_GetItemString(ctypes_dict, "c_wchar");
@@ -72,9 +65,9 @@ void fetch_ctypes()
7265

7366

7467
// (target type, source type)
75-
std::map<std::pair<PyTypeObject*,PyTypeObject*>, std::function<int(void*, PyObject*)>> m_feeders;
68+
static std::map<std::pair<PyTypeObject*,PyTypeObject*>, std::function<int(void*, PyObject*)>> m_feeders;
7669

77-
void populate_feeders(PyTypeObject* target_t, PyTypeObject* source_t)
70+
static void populate_feeders(PyTypeObject* target_t, PyTypeObject* source_t)
7871
{
7972
if (target_t == ctypes_c_int)
8073
{
@@ -140,7 +133,7 @@ void populate_feeders(PyTypeObject* target_t, PyTypeObject* source_t)
140133
}
141134
}
142135

143-
int feed(void* ptr, PyObject* value, PyObject* type)
136+
static int feed(void* ptr, PyObject* value, PyObject* type)
144137
{
145138
PyTypeObject* pto = (PyTypeObject*)type;
146139
if (ctypes_c_int == nullptr)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE
33

4+
# Include "param_packer.h" so its contents get compiled into every
5+
# Cython extension module that depends on param_packer.pxd.
46
cdef extern from "param_packer.h":
57
int feed(void* ptr, object o, object ct)

cuda_bindings/cuda/bindings/_lib/utils.pxd.in

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@ cimport cuda.bindings.cydriver as cydriver
66
cimport cuda.bindings.cyruntime as cyruntime
77
from libcpp.vector cimport vector
88

9-
cdef class HelperKernelParams:
9+
cdef class _HelperKernelParams:
1010
cdef Py_buffer _pybuffer
1111
cdef bint _pyobj_acquired
1212
cdef void** _ckernelParams
1313
cdef char* _ckernelParamsData
1414
cdef int _length
1515
cdef bint _malloc_list_created
1616

17-
cdef class HelperInputVoidPtr:
17+
cdef class _HelperInputVoidPtr:
1818
cdef Py_buffer _pybuffer
1919
cdef void* _cptr
2020
cdef bint _pyobj_acquired
2121
{{if 'CUmemPool_attribute_enum' in found_types}}
2222

23-
cdef class HelperCUmemPool_attribute:
23+
cdef class _HelperCUmemPool_attribute:
2424
cdef void* _cptr
2525
cdef cydriver.CUmemPool_attribute_enum _attr
2626
cdef bint _is_getter
@@ -31,7 +31,7 @@ cdef class HelperCUmemPool_attribute:
3131
{{endif}}
3232
{{if 'CUmem_range_attribute_enum' in found_types}}
3333

34-
cdef class HelperCUmem_range_attribute:
34+
cdef class _HelperCUmem_range_attribute:
3535
cdef void* _cptr
3636
cdef cydriver.CUmem_range_attribute_enum _attr
3737
cdef size_t _data_size
@@ -42,7 +42,7 @@ cdef class HelperCUmem_range_attribute:
4242
{{endif}}
4343
{{if 'CUpointer_attribute_enum' in found_types}}
4444

45-
cdef class HelperCUpointer_attribute:
45+
cdef class _HelperCUpointer_attribute:
4646
cdef void* _cptr
4747
cdef cydriver.CUpointer_attribute_enum _attr
4848
cdef bint _is_getter
@@ -60,7 +60,7 @@ cdef class HelperCUpointer_attribute:
6060
{{endif}}
6161
{{if 'CUgraphMem_attribute_enum' in found_types}}
6262

63-
cdef class HelperCUgraphMem_attribute:
63+
cdef class _HelperCUgraphMem_attribute:
6464
cdef void* _cptr
6565
cdef cydriver.CUgraphMem_attribute_enum _attr
6666
cdef bint _is_getter
@@ -70,7 +70,7 @@ cdef class HelperCUgraphMem_attribute:
7070
{{endif}}
7171
{{if 'CUjit_option_enum' in found_types}}
7272

73-
cdef class HelperCUjit_option:
73+
cdef class _HelperCUjit_option:
7474
cdef void* _cptr
7575
cdef cydriver.CUjit_option_enum _attr
7676

@@ -83,11 +83,11 @@ cdef class HelperCUjit_option:
8383
cdef int _int
8484
cdef cydriver.CUjit_cacheMode_enum _cacheMode
8585
cdef vector[char*] _charstarstar # list of names
86-
cdef InputVoidPtrPtrHelper _voidstarstar # list of addresses
86+
cdef _InputVoidPtrPtrHelper _voidstarstar # list of addresses
8787
{{endif}}
8888
{{if 'cudaJitOption' in found_types}}
8989

90-
cdef class HelperCudaJitOption:
90+
cdef class _HelperCudaJitOption:
9191
cdef void* _cptr
9292
cdef cyruntime.cudaJitOption _attr
9393

@@ -101,7 +101,7 @@ cdef class HelperCudaJitOption:
101101
{{endif}}
102102
{{if 'CUlibraryOption_enum' in found_types}}
103103

104-
cdef class HelperCUlibraryOption:
104+
cdef class _HelperCUlibraryOption:
105105
cdef void* _cptr
106106
cdef cydriver.CUlibraryOption_enum _attr
107107

@@ -110,7 +110,7 @@ cdef class HelperCUlibraryOption:
110110
{{endif}}
111111
{{if 'cudaLibraryOption' in found_types}}
112112

113-
cdef class HelperCudaLibraryOption:
113+
cdef class _HelperCudaLibraryOption:
114114
cdef void* _cptr
115115
cdef cyruntime.cudaLibraryOption _attr
116116

@@ -119,7 +119,7 @@ cdef class HelperCudaLibraryOption:
119119
{{endif}}
120120
{{if 'CUmemAllocationHandleType_enum' in found_types}}
121121

122-
cdef class HelperCUmemAllocationHandleType:
122+
cdef class _HelperCUmemAllocationHandleType:
123123
cdef void* _cptr
124124
cdef cydriver.CUmemAllocationHandleType_enum _type
125125

@@ -132,12 +132,12 @@ cdef class HelperCUmemAllocationHandleType:
132132
{{endif}}
133133
{{endif}}
134134

135-
cdef class InputVoidPtrPtrHelper:
135+
cdef class _InputVoidPtrPtrHelper:
136136
cdef void** _cptr
137137

138138
{{if 'CUcoredumpSettings_enum' in found_types}}
139139

140-
cdef class HelperCUcoredumpSettings:
140+
cdef class _HelperCUcoredumpSettings:
141141
cdef void* _cptr
142142
cdef cydriver.CUcoredumpSettings_enum _attrib
143143
cdef bint _is_getter

0 commit comments

Comments
 (0)