Skip to content
Snippets Groups Projects
Commit 2fd81990 authored by Andreas Klöckner's avatar Andreas Klöckner
Browse files

Add SourceModule.

parent c88bec96
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,11 @@ def _add_functionality():
_add_functionality()
def pagelocked_zeros(shape, dtype, order="C"):
result = pagelocked_empty(shape, dtype, order)
result.fill(0)
......@@ -24,4 +29,32 @@ def pagelocked_zeros(shape, dtype, order="C"):
_add_functionality()
class SourceModule(object):
def __init__(self, source, options=[], keep=False):
from tempfile import mkdtemp
tempdir = mkdtemp()
print tempdir
from os.path import join
outf = open(join(tempdir, "kernel.cu"), "w")
outf.write(source)
outf.close()
from subprocess import call
result = call(["nvcc", "--cubin"]
+ options
+ ["kernel.cu"]
cwd=tempdir)
data = open(join(tempdir, "kernel.cubin"), "r").read()
self.module = module_from_buffer(data)
if not keep:
from os import listdir, unlink, rmdir
for name in listdir(tempdir):
os.unlink(join(tempdir, name))
os.rmdir(tempdir)
self.get_function = self.module.get_function
self.get_global = self.module.get_global
self.get_texref = self.module.get_texref
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment