From a2f7a3aed3eccb018dda989b5390371d6c0d6784 Mon Sep 17 00:00:00 2001 From: Stan Seibert Date: Fri, 16 Sep 2011 19:21:57 -0400 Subject: Add a srcdir attribute to the chroma.cuda module. This consolidates the calculation of the path to the CUDA source code in one place. --- chroma/cuda/__init__.py | 2 ++ chroma/gpu.py | 4 ++-- test/linalg_test.py | 2 +- test/matrix_test.py | 3 ++- test/rotate_test.py | 2 +- test/test_sample_cdf.py | 2 +- 6 files changed, 9 insertions(+), 6 deletions(-) diff --git a/chroma/cuda/__init__.py b/chroma/cuda/__init__.py index e69de29..dd87cbc 100644 --- a/chroma/cuda/__init__.py +++ b/chroma/cuda/__init__.py @@ -0,0 +1,2 @@ +import os.path +srcdir = os.path.dirname(os.path.abspath(__file__)) diff --git a/chroma/gpu.py b/chroma/gpu.py index 2b143a3..af83c75 100644 --- a/chroma/gpu.py +++ b/chroma/gpu.py @@ -34,7 +34,7 @@ def get_cu_module(name, options=None, include_source_directory=True): else: raise TypeError('`options` must be a tuple.') - srcdir = os.path.dirname(os.path.abspath(chroma.cuda.__file__)) + from chroma.cuda import srcdir if include_source_directory: options += ['-I' + srcdir] @@ -49,7 +49,7 @@ def get_cu_module(name, options=None, include_source_directory=True): def get_cu_source(name): """Get the source code for a CUDA source file located in the chroma cuda directory at src/[name].""" - srcdir = os.path.dirname(os.path.abspath(chroma.cuda.__file__)) + from chroma.cuda import srcdir with open('%s/%s' % (srcdir, name)) as f: source = f.read() return source diff --git a/test/linalg_test.py b/test/linalg_test.py index 31688d9..23ebfa7 100644 --- a/test/linalg_test.py +++ b/test/linalg_test.py @@ -10,7 +10,7 @@ float3 = gpuarray.vec.float3 print 'device %s' % autoinit.device.name() current_directory = os.path.split(os.path.realpath(__file__))[0] -source_directory = current_directory + '/../src' +from chroma.cuda import srcdir as source_directory source = open(current_directory + '/linalg_test.cu').read() diff --git a/test/matrix_test.py b/test/matrix_test.py index c843025..3499945 100644 --- a/test/matrix_test.py +++ b/test/matrix_test.py @@ -10,7 +10,8 @@ float3 = gpuarray.vec.float3 print 'device %s' % autoinit.device.name() current_directory = os.path.split(os.path.realpath(__file__))[0] -source_directory = current_directory + '/../src' + +from chroma.cuda import srcdir as source_directory source = open(current_directory + '/matrix_test.cu').read() diff --git a/test/rotate_test.py b/test/rotate_test.py index 92eff84..7ac7804 100644 --- a/test/rotate_test.py +++ b/test/rotate_test.py @@ -18,7 +18,7 @@ def rotate(x, phi, n): print 'device %s' % autoinit.device.name() current_directory = os.path.split(os.path.realpath(__file__))[0] -source_directory = current_directory + '/../src' +from chroma.cuda import srcdir as source_directory source = open(current_directory + '/rotate_test.cu').read() diff --git a/test/test_sample_cdf.py b/test/test_sample_cdf.py index 2baa2ac..d12efa4 100644 --- a/test/test_sample_cdf.py +++ b/test/test_sample_cdf.py @@ -7,7 +7,7 @@ import ROOT import os current_directory = os.path.split(os.path.realpath(__file__))[0] -source_directory = current_directory + '/../src' +from chroma.cuda import srcdir as source_directory source = open(current_directory + '/test_sample_cdf.cu').read() -- cgit