Skip to content
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

Add get_surfobj and get_texobj to cuda arrays #174

Open
wants to merge 1 commit 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
79 changes: 79 additions & 0 deletions src/cpp/cuda.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,63 @@ namespace pycuda

// }}}

// {{{ texture object
#if CUDAPP_CUDA_VERSION >= 5000
class texture_object : public boost::noncopyable
{
private:
CUtexObject m_texobj;
bool m_managed;

public:
texture_object(CUtexObject to, bool managed)
: m_texobj(to), m_managed(managed)
{ }

~texture_object()
{
if (m_managed)
{
CUDAPP_CALL_GUARDED_CLEANUP(cuTexObjectDestroy, (m_texobj));
}
}

CUtexObject handle() const
{ return m_texobj; }
};
#endif

// }}}

// {{{ surface object
#if CUDAPP_CUDA_VERSION >= 5000
class surface_object : public boost::noncopyable
{
private:
CUsurfObject m_surfobj;
bool m_managed;

public:
surface_object(CUsurfObject so, bool managed)
: m_surfobj(so), m_managed(managed)
{ }

~surface_object()
{
if (m_managed)
{
CUDAPP_CALL_GUARDED_CLEANUP(cuSurfObjectDestroy, (m_surfobj));
}
}

CUsurfObject handle() const
{ return m_surfobj; }
};
#endif

// }}}


// {{{ array
class array : public boost::noncopyable, public context_dependent
{
Expand Down Expand Up @@ -1060,6 +1117,28 @@ namespace pycuda
}
#endif

#if CUDAPP_CUDA_VERSION >= 5000
texture_object *get_texobj(CUDA_TEXTURE_DESC* pTexDesc) {
CUtexObject texObject;
CUDA_RESOURCE_DESC resDesc;
memset(&resDesc,0,sizeof(CUDA_RESOURCE_DESC));
resDesc.resType = CU_RESOURCE_TYPE_ARRAY;
resDesc.res.array.hArray = m_array;
CUDAPP_CALL_GUARDED(cuTexObjectCreate, (&texObject, &resDesc, pTexDesc, NULL));
return new texture_object(texObject, true);
}

surface_object *get_surfobj() {
CUsurfObject surfObject;
CUDA_RESOURCE_DESC resDesc;
memset(&resDesc,0,sizeof(CUDA_RESOURCE_DESC));
resDesc.resType = CU_RESOURCE_TYPE_ARRAY;
resDesc.res.array.hArray = m_array;
CUDAPP_CALL_GUARDED(cuSurfObjectCreate, (&surfObject, &resDesc));
return new surface_object(surfObject, true);
}
#endif

CUarray handle() const
{ return m_array; }

Expand Down
43 changes: 43 additions & 0 deletions src/wrapper/wrap_cudadrv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1586,12 +1586,55 @@ BOOST_PYTHON_MODULE(_driver)
#if CUDAPP_CUDA_VERSION >= 2000
.def(py::init<const CUDA_ARRAY3D_DESCRIPTOR &>())
.DEF_SIMPLE_METHOD(get_descriptor_3d)
#endif
#if CUDAPP_CUDA_VERSION >= 5000
.def("get_texobj", &cl::get_texobj,
py::return_value_policy<py::manage_new_object>())
.def("get_surfobj", &cl::get_surfobj,
py::return_value_policy<py::manage_new_object>())
#endif
.add_property("handle", &cl::handle_int)
;
}
// }}}

// {{{ texture object
#if CUDAPP_CUDA_VERSION >= 5000
{
typedef CUDA_TEXTURE_DESC cl;
py::class_<cl>("TextureDesc")
.add_property("address_mode", make_array(&cl::addressMode))
.add_property("border_color", make_array(&cl::borderColor))
.def_readwrite("filter_mode", &cl::filterMode)
.def_readwrite("flags", &cl::flags)
.def_readwrite("max_anisotropy", &cl::maxAnisotropy)
.def_readwrite("max_mipmap_level_clamp", &cl::maxMipmapLevelClamp)
.def_readwrite("min_mipmap_level_clamp", &cl::minMipmapLevelClamp)
.def_readwrite("mipmap_filter_mode", &cl::mipmapFilterMode)
.def_readwrite("mipmap_level_bias", &cl::mipmapLevelBias)
;
}

{
typedef texture_object cl;
py::class_<cl, boost::noncopyable>("TextureObject", py::no_init)
.add_property("handle", &cl::handle)
;
}
#endif
// }}}

// {{{ surface object
#if CUDAPP_CUDA_VERSION >= 5000
{
typedef surface_object cl;
py::class_<cl, boost::noncopyable>("SurfaceObject", py::no_init)
.add_property("handle", &cl::handle)
;
}
#endif
// }}}

// {{{ texture reference
{
typedef texture_reference cl;
Expand Down
Loading