Hi,

* Andreas Kloeckner <[email protected]> [2010-06-19 18:24:49 -0400]:

I'm afraid there isn't really a way around the explicit cast, at least
for now. The documentation [1] says that memcpy_dtoh only takes int or
DeviceAllocation objects. If you have Boost.Python code that you are
compiling, you can mimic what PyCUDA does for DeviceAllocation. It is
also possible to have PyCUDA attempt a __long__ cast wherever it takes a
device pointer--do you think it's imperative that this should be done?

I am using an old version of PyCUDA (0.92), but I wrote this really
simple function for my code (attached). I use it to load data in C
without having to worry about doing in-kernel casts to pointers, and
also so I can use ctypes instead of Boost.Python which I prefer. It
is probably cleaner to do the casting in functions, but if this diff
is helpful, enjoy!

nick
diff --git a/src/wrapper/wrap_cudadrv.cpp b/src/wrapper/wrap_cudadrv.cpp
index 495040f..33ba97d 100644
--- a/src/wrapper/wrap_cudadrv.cpp
+++ b/src/wrapper/wrap_cudadrv.cpp
@@ -88,6 +88,11 @@ namespace
   }
 
 
+  device_allocation *long_to_device_allocation(long ptr)
+  {
+    return new device_allocation((CUdeviceptr)ptr);
+  }
+
 
   device_allocation *mem_alloc_wrap(unsigned long bytes)
   {
@@ -724,6 +727,8 @@ BOOST_PYTHON_MODULE(_driver)
   }
 
   DEF_SIMPLE_FUNCTION(mem_get_info);
+  py::def("int_to_ptr", long_to_device_allocation,
+      py::return_value_policy<py::manage_new_object>());
   py::def("mem_alloc", mem_alloc_wrap, 
       py::return_value_policy<py::manage_new_object>());
   py::def("mem_alloc_pitch", mem_alloc_pitch_wrap,
_______________________________________________
PyCUDA mailing list
[email protected]
http://lists.tiker.net/listinfo/pycuda

Reply via email to