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)
Metadata
Release files for simplepycuda 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simplepycuda-0.0.1.tar.gz | 8.3 kB | Details |
Release files / simplepycuda-0.0.1.tar.gz
| Download URL | simplepycuda-0.0.1.tar.gz |
|---|---|
| Size | 8.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c686507fecc9d4aee50001a3f915fef711c0f2fbc7315eb22c76ca01c4bd339
|
|
BLAKE2b-256 checksum How to use checksums |
1eaec7adf1c9a65f6aa7d99bbb22c59cc736ef2ec3bd0eb0a3629783cb21dc53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|