Comments (5)
Is there any C API for CUDAMat? I want to create a matrix using CUDAMat in python from an already allocated GPU memory and I can only access the memory by a pointer in c.
CUDAMat is a C shared library accessed from Python via the ctypes
module. So the CUDAMatrix
is defined in Python and there is no C API to create it. However, if you can get your pointer into Python, you can create a CUDAMatrix
accessing this pointer. See this example:
https://github.com/Theano/Theano/blob/7a97cfe/theano/misc/cudamat_utils.py#L67-L86
In that example, it is assumed that the memory belongs to the already existing object x
, so the matrix is marked as not owning the data, and the object x
is attached as a property to the CUDAMatrix
object so Python will not delete x
before deleting the CUDAMatrix
. If instead, you want the memory to be managed by cudamat (and freed with cublasFree
), just set owns_data
to True.
Hope this makes things clear -- if you want to make this use case easier, I'd be open for a PR that adds a factory method CUDAMatrix.from_memory
or something, taking a device pointer, shape and an optional parent object.
from cudamat.
@f0k Thanks for your answer! It's clear.
But the python module I'm trying to extend uses boost.python to wrap C++ code and doesn't expose the GPU memory pointer to python. So I have to start from C++ and it seems that boost.python doesn't have an elegant way to expose a pointer such as float *
to python. So I'm wondering whether can I use cudamat to handle this along with boost python?
from cudamat.
Or what type
of object should I expose in python managing the GPU memory pointer?
from cudamat.
So I have to start from C++ and it seems that boost.python doesn't have an elegant way to expose a pointer such as float * to python.
There should be a way. In the worst case, you can expose it as a Python long
and then cast it to a pointer within Python using ctypes
, as in the example code I linked to.
You can also create the cudamat
struct in C/C++, but then you still have to pass it to Python -- this won't make things easier.
from cudamat.
@f0k I will try it. Thanks for your thorough explanation.
from cudamat.
Related Issues (20)
- install problem in windows (python in anaconda) HOT 10
- failed to import cudamat
- import error : could not find module libcudamat.dll
- problem while installing cudamat
- Windows import/compile issue
- EE ===ERROR: Failure: OSError (/home/facecnn/cudamat-master/test/libcudamat.so: cannot open shared object file: No such file or directory) HOT 4
- how to do subtract_row_vec or subtract_col_vec in cudamat HOT 3
- Install Error on Windows HOT 2
- cudamat cannot initialize HOT 11
- install error on Windows HOT 22
- I have an error in importing cudamat. HOT 3
- Compile error: undefined reference to `jsonp_dtostr'
- install error on windows 10 HOT 3
- install error on windows 10 HOT 6
- error initializing CUBLAS: (err=1) HOT 2
- fp16 HOT 1
- cudamat.cudamat.CUDAMatException: error initializing CUBLAS: (err=1) HOT 3
- test errors HOT 5
- [Solved] Linux install fails: "unable to execute 'nvcc': No such file or directory" HOT 2
- clang: error: cannot find libdevice for sm_61 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cudamat.