A simple wrapper for CUDA functions in Python.
Project description
The library cudapp is the basis of SimplePyCuda, a simple wrapper for CUDA functions in Python. The idea is to workaround the issues regarding Context in old CUDA versions, that persist on PyCuda.
Usage:
"make [all]" will build the lib cudapp.so
"make run" will execute "testSimplePyCuda.py", using library "simplepycuda.py".
==========================
In Python:
import ctypes
import numpy
from simplepycuda import SimplePyCuda, SimpleSourceModule, grid, block
def classicExample(cuda):
a = numpy.random.randn(4,4)
a = a.astype(numpy.float32)
print a
a_gpu = cuda.mem_alloc(a.nbytes)
cuda.memcpy_htod(a_gpu, a)
mod = SimpleSourceModule("""
#include<stdio.h>
__global__ void doublify ( float* a )
{
int idx = threadIdx.x + threadIdx.y*4;
a[idx] *= 2;
//printf("oi=%d\\n",idx);
}
""")
func = mod.get_function("doublify")
# TODO: this next line will be made automatically in get_function method... just need a few more time :)
func.argtypes = [ctypes.c_void_p, grid, block, ctypes.c_ulong, ctypes.c_ulong]
func(a_gpu, grid(1,1), block(4,4,1), 0, 0)
cuda.memcpy_dtoh(a, a_gpu)
cuda.deviceSynchronize()
print a
cuda.free(a_gpu) # this is not necessary in PyCUDA
print "Finished"
def main():
cuda = SimplePyCuda()
classicExample(cuda)
return 0
MIT License - Igor Machado Coelho and Rodolfo Pereira Araujo (2017)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
simplepycuda-0.0.1.tar.gz
(8.3 kB
view details)
File details
Details for the file simplepycuda-0.0.1.tar.gz.
File metadata
- Download URL: simplepycuda-0.0.1.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.9.1 setuptools/20.7.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c686507fecc9d4aee50001a3f915fef711c0f2fbc7315eb22c76ca01c4bd339
|
|
| MD5 |
3a909c3c03914c9b31148a7b8311a468
|
|
| BLAKE2b-256 |
1eaec7adf1c9a65f6aa7d99bbb22c59cc736ef2ec3bd0eb0a3629783cb21dc53
|