Skip to content

Fix #789: Remove cyclical import between driver and _lib.utils #865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ __pycache__/
cache_driver
cache_runtime
cache_nvrtc
cuda_bindings/cuda/bindings/_lib/utils.pxi

# CUDA Python specific (auto-generated)
cuda_bindings/cuda/bindings/_bindings/cydriver.pxd
Expand Down
63 changes: 31 additions & 32 deletions cuda_bindings/cuda/bindings/_lib/param_packer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,44 @@
// SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE

#include <Python.h>
#include "param_packer.h"

#include <map>
#include <functional>
#include <stdexcept>
#include <string>

PyObject* enum_module = nullptr;
PyTypeObject* enum_Enum = nullptr;
static PyObject* enum_module = nullptr;
static PyTypeObject* enum_Enum = nullptr;

PyObject* ctypes_module = nullptr;
PyObject* ctypes_addressof = nullptr;
PyObject* addressof_param_tuple = nullptr;
static PyObject* ctypes_module = nullptr;
static PyObject* ctypes_addressof = nullptr;
static PyObject* addressof_param_tuple = nullptr;

PyTypeObject* ctypes_c_char = nullptr;
PyTypeObject* ctypes_c_bool = nullptr;
PyTypeObject* ctypes_c_wchar = nullptr;
PyTypeObject* ctypes_c_byte = nullptr;
PyTypeObject* ctypes_c_ubyte = nullptr;
PyTypeObject* ctypes_c_short = nullptr;
PyTypeObject* ctypes_c_ushort = nullptr;
PyTypeObject* ctypes_c_int = nullptr;
PyTypeObject* ctypes_c_uint = nullptr;
PyTypeObject* ctypes_c_long = nullptr;
PyTypeObject* ctypes_c_ulong = nullptr;
PyTypeObject* ctypes_c_longlong = nullptr;
PyTypeObject* ctypes_c_ulonglong = nullptr;
PyTypeObject* ctypes_c_size_t = nullptr;
PyTypeObject* ctypes_c_float = nullptr;
PyTypeObject* ctypes_c_double = nullptr;
PyTypeObject* ctypes_c_void_p = nullptr;
static PyTypeObject* ctypes_c_char = nullptr;
static PyTypeObject* ctypes_c_bool = nullptr;
static PyTypeObject* ctypes_c_wchar = nullptr;
static PyTypeObject* ctypes_c_byte = nullptr;
static PyTypeObject* ctypes_c_ubyte = nullptr;
static PyTypeObject* ctypes_c_short = nullptr;
static PyTypeObject* ctypes_c_ushort = nullptr;
static PyTypeObject* ctypes_c_int = nullptr;
static PyTypeObject* ctypes_c_uint = nullptr;
static PyTypeObject* ctypes_c_long = nullptr;
static PyTypeObject* ctypes_c_ulong = nullptr;
static PyTypeObject* ctypes_c_longlong = nullptr;
static PyTypeObject* ctypes_c_ulonglong = nullptr;
static PyTypeObject* ctypes_c_size_t = nullptr;
static PyTypeObject* ctypes_c_float = nullptr;
static PyTypeObject* ctypes_c_double = nullptr;
static PyTypeObject* ctypes_c_void_p = nullptr;

PyTypeObject* ctypes_c_ssize_t = nullptr;
PyTypeObject* ctypes_c_longdouble = nullptr;
PyTypeObject* ctypes_c_char_p = nullptr;
PyTypeObject* ctypes_c_wchar_p = nullptr;
PyTypeObject* ctypes_c_structure = nullptr;
static PyTypeObject* ctypes_c_ssize_t = nullptr;
static PyTypeObject* ctypes_c_longdouble = nullptr;
static PyTypeObject* ctypes_c_char_p = nullptr;
static PyTypeObject* ctypes_c_wchar_p = nullptr;
static PyTypeObject* ctypes_c_structure = nullptr;

void fetch_ctypes()
static void fetch_ctypes()
{
ctypes_module = PyImport_ImportModule("ctypes");
if (ctypes_module == nullptr)
Expand Down Expand Up @@ -72,9 +71,9 @@ void fetch_ctypes()


// (target type, source type)
std::map<std::pair<PyTypeObject*,PyTypeObject*>, std::function<int(void*, PyObject*)>> m_feeders;
static std::map<std::pair<PyTypeObject*,PyTypeObject*>, std::function<int(void*, PyObject*)>> m_feeders;

void populate_feeders(PyTypeObject* target_t, PyTypeObject* source_t)
static void populate_feeders(PyTypeObject* target_t, PyTypeObject* source_t)
{
if (target_t == ctypes_c_int)
{
Expand Down Expand Up @@ -140,7 +139,7 @@ void populate_feeders(PyTypeObject* target_t, PyTypeObject* source_t)
}
}

int feed(void* ptr, PyObject* value, PyObject* type)
static int feed(void* ptr, PyObject* value, PyObject* type)
{
PyTypeObject* pto = (PyTypeObject*)type;
if (ctypes_c_int == nullptr)
Expand Down
12 changes: 0 additions & 12 deletions cuda_bindings/cuda/bindings/_lib/param_packer.h

This file was deleted.

4 changes: 3 additions & 1 deletion cuda_bindings/cuda/bindings/_lib/param_packer.pxd
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-FileCopyrightText: Copyright (c) 2021-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: LicenseRef-NVIDIA-SOFTWARE-LICENSE

cdef extern from "param_packer.h":
# Include "param_packer.cpp" so its contents get compiled into every
# Cython extension module that depends on param_packer.pxd.
cdef extern from "param_packer.cpp":
int feed(void* ptr, object o, object ct)
28 changes: 14 additions & 14 deletions cuda_bindings/cuda/bindings/_lib/utils.pxd.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ cimport cuda.bindings.cydriver as cydriver
cimport cuda.bindings.cyruntime as cyruntime
from libcpp.vector cimport vector

cdef class HelperKernelParams:
cdef class _HelperKernelParams:
cdef Py_buffer _pybuffer
cdef bint _pyobj_acquired
cdef void** _ckernelParams
cdef char* _ckernelParamsData
cdef int _length
cdef bint _malloc_list_created

cdef class HelperInputVoidPtr:
cdef class _HelperInputVoidPtr:
cdef Py_buffer _pybuffer
cdef void* _cptr
cdef bint _pyobj_acquired
{{if 'CUmemPool_attribute_enum' in found_types}}

cdef class HelperCUmemPool_attribute:
cdef class _HelperCUmemPool_attribute:
cdef void* _cptr
cdef cydriver.CUmemPool_attribute_enum _attr
cdef bint _is_getter
Expand All @@ -31,7 +31,7 @@ cdef class HelperCUmemPool_attribute:
{{endif}}
{{if 'CUmem_range_attribute_enum' in found_types}}

cdef class HelperCUmem_range_attribute:
cdef class _HelperCUmem_range_attribute:
cdef void* _cptr
cdef cydriver.CUmem_range_attribute_enum _attr
cdef size_t _data_size
Expand All @@ -42,7 +42,7 @@ cdef class HelperCUmem_range_attribute:
{{endif}}
{{if 'CUpointer_attribute_enum' in found_types}}

cdef class HelperCUpointer_attribute:
cdef class _HelperCUpointer_attribute:
cdef void* _cptr
cdef cydriver.CUpointer_attribute_enum _attr
cdef bint _is_getter
Expand All @@ -60,7 +60,7 @@ cdef class HelperCUpointer_attribute:
{{endif}}
{{if 'CUgraphMem_attribute_enum' in found_types}}

cdef class HelperCUgraphMem_attribute:
cdef class _HelperCUgraphMem_attribute:
cdef void* _cptr
cdef cydriver.CUgraphMem_attribute_enum _attr
cdef bint _is_getter
Expand All @@ -70,7 +70,7 @@ cdef class HelperCUgraphMem_attribute:
{{endif}}
{{if 'CUjit_option_enum' in found_types}}

cdef class HelperCUjit_option:
cdef class _HelperCUjit_option:
cdef void* _cptr
cdef cydriver.CUjit_option_enum _attr

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

cdef class HelperCudaJitOption:
cdef class _HelperCudaJitOption:
cdef void* _cptr
cdef cyruntime.cudaJitOption _attr

Expand All @@ -101,7 +101,7 @@ cdef class HelperCudaJitOption:
{{endif}}
{{if 'CUlibraryOption_enum' in found_types}}

cdef class HelperCUlibraryOption:
cdef class _HelperCUlibraryOption:
cdef void* _cptr
cdef cydriver.CUlibraryOption_enum _attr

Expand All @@ -110,7 +110,7 @@ cdef class HelperCUlibraryOption:
{{endif}}
{{if 'cudaLibraryOption' in found_types}}

cdef class HelperCudaLibraryOption:
cdef class _HelperCudaLibraryOption:
cdef void* _cptr
cdef cyruntime.cudaLibraryOption _attr

Expand All @@ -119,7 +119,7 @@ cdef class HelperCudaLibraryOption:
{{endif}}
{{if 'CUmemAllocationHandleType_enum' in found_types}}

cdef class HelperCUmemAllocationHandleType:
cdef class _HelperCUmemAllocationHandleType:
cdef void* _cptr
cdef cydriver.CUmemAllocationHandleType_enum _type

Expand All @@ -132,12 +132,12 @@ cdef class HelperCUmemAllocationHandleType:
{{endif}}
{{endif}}

cdef class InputVoidPtrPtrHelper:
cdef class _InputVoidPtrPtrHelper:
cdef void** _cptr

{{if 'CUcoredumpSettings_enum' in found_types}}

cdef class HelperCUcoredumpSettings:
cdef class _HelperCUcoredumpSettings:
cdef void* _cptr
cdef cydriver.CUcoredumpSettings_enum _attrib
cdef bint _is_getter
Expand Down
Loading
Loading