Skip to content

Commit c1cf749

Browse files
committed
using csbiginteger lib
1 parent 894ff08 commit c1cf749

8 files changed

+89
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pyc

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "csBigIntegerpp"]
2+
path = csBigIntegerpp
3+
url = https://github.com/NeoResearch/csBigInteger.cpp.git

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
all:
2+
g++ --shared csBigIntegerpp/src/csBigIntegerLib.cpp csBigIntegerpp/src/BigInteger.cpp -lgmp -lgmpxx -o build/csbiginteger.so -fPIC
3+
4+
# test python
5+
run:
6+
export LD_LIBRARY_PATH=. && ./test.py
7+
8+
clean:
9+
rm *.so

build/csbiginteger.so

127 KB
Binary file not shown.

csBigInteger

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 3eaeddfd95bb96f981e8dd4de94d64cdc582ab34

csBigInteger.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/python
2+
3+
import ctypes
4+
from ctypes import * #import Structure
5+
6+
import os
7+
import os.path
8+
import re
9+
10+
class BigInteger:
11+
def __init__(self):
12+
self.lib = ctypes.cdll.LoadLibrary('./build/csbiginteger.so')
13+
self.lib.csbiginteger_init_empty.argtypes = [ctypes.c_void_p, ctypes.c_int]
14+
self.lib.csbiginteger_init_empty.restype = ctypes.c_int
15+
16+
def initEmpty(self, data, datasize):
17+
sz = self.lib.csbiginteger_init_empty(data, datasize)
18+
return sz

csBigIntegerpp

Submodule csBigIntegerpp added at 3eaeddf

test.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/python
2+
# basic example from SimplePyCuda library
3+
# MIT License - Igor Machado Coelho (2017)
4+
5+
import ctypes
6+
7+
from csBigInteger import BigInteger
8+
9+
import numpy
10+
'''
11+
def simpleLoadTest(cuda):
12+
lib = ctypes.cdll.LoadLibrary('./__simplepycuda_kernel_doublify.so')
13+
lib.kernel_loader.argtypes = [ctypes.c_void_p, grid, block, ctypes.c_ulong, ctypes.c_ulong]
14+
a = numpy.random.randn(4,4)
15+
a_gpu = cuda.mem_alloc(a.nbytes)
16+
lib.kernel_loader(a_gpu, grid(1,1), block(4,4,1), 0, 0)
17+
print "Kernel OK"
18+
# finish
19+
20+
def classicExample(cuda):
21+
a = numpy.random.randn(4,4)
22+
a = a.astype(numpy.float32)
23+
print a
24+
a_gpu = cuda.mem_alloc(a.nbytes)
25+
cuda.memcpy_htod(a_gpu, a)
26+
mod = SimpleSourceModule("""
27+
#include<stdio.h>
28+
__global__ void doublify ( float* a )
29+
{
30+
int idx = threadIdx.x + threadIdx.y*4;
31+
a[idx] *= 2;
32+
printf("oi=%d\\n",idx);
33+
}
34+
""","nvcc", ["--ptxas-options=-v","--compiler-options -O3","--compiler-options -Wall"])
35+
func = mod.get_function("doublify")
36+
# TODO: this next line will be made automatically in get_function method... just need a few more time :)
37+
func.argtypes = [ctypes.c_void_p, grid, block, ctypes.c_ulong, ctypes.c_ulong]
38+
func(a_gpu, grid(1,1), block(4,4,1), 0, 0)
39+
cuda.memcpy_dtoh(a, a_gpu)
40+
cuda.deviceSynchronize()
41+
print a
42+
cuda.free(a_gpu) # this is not necessary in PyCUDA
43+
print "Finished"
44+
'''
45+
46+
def main():
47+
big = BigInteger()
48+
data = (ctypes.c_uint8*5)()
49+
sz = big.initEmpty(data, 5)
50+
print('size = ', sz)
51+
return 0
52+
53+
if __name__ == '__main__':
54+
main()
55+
56+

0 commit comments

Comments
 (0)