Skip to content

Commit

Permalink
banish opencl from test scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
ahnitz committed Jun 30, 2015
1 parent 4f3ae25 commit 9a3e7a1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 40 deletions.
6 changes: 0 additions & 6 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
import pycuda
import pycuda.gpuarray
from pycuda.gpuarray import GPUArray as SchemeArray
elif _scheme == 'opencl':
import pyopencl
import pyopencl.array
from pyopencl.array import Array as SchemeArray
elif _scheme == 'cpu':
from pycbc.types.aligned import ArrayWithAligned as SchemeArray

Expand Down Expand Up @@ -183,8 +179,6 @@ def test_numpy_init(self):
# We also need to check initialization using GPU arrays
if self.scheme == 'cuda':
in4 = pycuda.gpuarray.zeros(3,self.dtype)
elif self.scheme == 'opencl':
in4 = pyopencl.array.zeros(pycbc.scheme.mgr.state.queue,3, self.dtype)
if self.scheme != 'cpu':
out4 = Array(in4, copy=False)
in4 += 1
Expand Down
6 changes: 0 additions & 6 deletions test/test_frequencyseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
import pycuda
import pycuda.gpuarray
from pycuda.gpuarray import GPUArray as SchemeArray
elif _scheme == 'opencl':
import pyopencl
import pyopencl.array
from pyopencl.array import Array as SchemeArray
elif _scheme == 'cpu':
from pycbc.types.aligned import ArrayWithAligned as SchemeArray

Expand Down Expand Up @@ -182,8 +178,6 @@ def test_numpy_init(self):
# We also need to check initialization using GPU arrays
if self.scheme == 'cuda':
in4 = pycuda.gpuarray.zeros(3,self.dtype)
elif self.scheme == 'opencl':
in4 = pyopencl.array.zeros(pycbc.scheme.mgr.state.queue,3, self.dtype)
if self.scheme != 'cpu':
out4 = FrequencySeries(in4,0.1, copy=False, epoch=self.epoch)
in4 += 1
Expand Down
2 changes: 1 addition & 1 deletion test/test_lalsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

parser = OptionParser()
parser.add_option('--scheme','-s', action='callback', type = 'choice',
choices = ('cpu','cuda','opencl'),
choices = ('cpu','cuda'),
default = 'cpu', dest = 'scheme', callback = _check_scheme_cpu,
help = optparse.SUPPRESS_HELP)
parser.add_option('--device-num','-d', action='store', type = 'int',
Expand Down
4 changes: 0 additions & 4 deletions test/test_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@
import pycuda
import pycuda.gpuarray
from pycuda.gpuarray import GPUArray as SchemeArray
elif isinstance(_context,OpenCLScheme):
import pyopencl
import pyopencl.array
from pyopencl.array import Array as SchemeArray
elif isinstance(_context,CPUScheme):
from pycbc.types.aligned import ArrayWithAligned as SchemeArray

Expand Down
6 changes: 0 additions & 6 deletions test/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
import pycuda
import pycuda.gpuarray
from pycuda.gpuarray import GPUArray as SchemeArray
elif _scheme == 'opencl':
import pyopencl
import pyopencl.array
from pyopencl.array import Array as SchemeArray
elif _scheme == 'cpu':
from pycbc.types.aligned import ArrayWithAligned as SchemeArray

Expand Down Expand Up @@ -181,8 +177,6 @@ def test_numpy_init(self):
# We also need to check initialization using GPU arrays
if self.scheme == 'cuda':
in4 = pycuda.gpuarray.zeros(3,self.dtype)
elif self.scheme == 'opencl':
in4 = pyopencl.array.zeros(pycbc.scheme.mgr.state.queue,3, self.dtype)
if self.scheme != 'cpu':
out4 = TimeSeries(in4,0.1, copy=False, epoch=self.epoch)
in4 += 1
Expand Down
27 changes: 10 additions & 17 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@
#
"""
This module contains a few helper functions designed to make writing PyCBC
unit tests easier, while still allowing the tests to be run on CPU, CUDA,
and OpenCL.
unit tests easier, while still allowing the tests to be run on CPU and CUDA
All tests starting with 'test_' in the test subdirectory of pycbc are run
whenever the command 'python setup.py test' is given. That command will
attempt to call each test, passing it the argument '-s <scheme>' where
scheme is each of 'cpu', 'cuda', and 'opencl' in turn. Unit tests
scheme is each of 'cpu', 'cuda' in turn. Unit tests
designed to validate code that should run under multiple schemes should accept
each of these options, rerunning the same tests under each successive scheme.
Expand Down Expand Up @@ -68,7 +67,7 @@
import optparse
from sys import exit as _exit
from optparse import OptionParser, OptionValueError
from pycbc.scheme import CPUScheme, CUDAScheme, OpenCLScheme
from pycbc.scheme import CPUScheme, CUDAScheme
from numpy import dtype, float32, float64, complex64, complex128
from pycbc.types import Array

Expand All @@ -77,20 +76,18 @@ def _check_scheme_all(option, opt_str, scheme, parser):
if scheme=='cuda' and not pycbc.HAVE_CUDA:
raise optparse.OptionValueError("CUDA not found")

if scheme=='opencl' and not pycbc.HAVE_OPENCL:
raise optparse.OptionValueError("OpenCL not found")
setattr (parser.values, option.dest, scheme)


def parse_args_all_schemes(feature_str):
_parser = OptionParser()
_parser.add_option('--scheme','-s', action='callback', type = 'choice',
choices = ('cpu','cuda','opencl'),
choices = ('cpu','cuda'),
default = 'cpu', dest = 'scheme', callback = _check_scheme_all,
help = 'specifies processing scheme, can be cpu [default], cuda, or opencl')
help = 'specifies processing scheme, can be cpu [default], cuda')
_parser.add_option('--device-num','-d', action='store', type = 'int',
dest = 'devicenum', default=0,
help = 'specifies a GPU device to use for CUDA or OpenCL, 0 by default')
help = 'specifies a GPU device to use for CUDA, 0 by default')
(_opt_list, _args) = _parser.parse_args()

# Changing the optvalues to a dict makes them easier to read
Expand All @@ -102,10 +99,8 @@ def parse_args_all_schemes(feature_str):
_context = CPUScheme()
if _scheme == 'cuda':
_context = CUDAScheme(device_num=_options['devicenum'])
if _scheme == 'opencl':
_context = OpenCLScheme(device_num=_options['devicenum'])

_scheme_dict = { 'cpu': 'CPU', 'cuda': 'CUDA', 'opencl' : 'OpenCL'}
_scheme_dict = { 'cpu': 'CPU', 'cuda': 'CUDA'}

print 72*'='
print "Running {0} unit tests for {1}:".format(_scheme_dict[_scheme],feature_str)
Expand All @@ -116,20 +111,18 @@ def _check_scheme_cpu(option, opt_str, scheme, parser):
if scheme=='cuda':
exit(0)

if scheme=='opencl':
exit(0)
setattr (parser.values, option.dest, scheme)


def parse_args_cpu_only(feature_str):
_parser = OptionParser()
_parser.add_option('--scheme','-s', action='callback', type = 'choice',
choices = ('cpu','cuda','opencl'),
choices = ('cpu','cuda'),
default = 'cpu', dest = 'scheme', callback = _check_scheme_cpu,
help = 'specifies processing scheme, can be cpu [default], cuda, or opencl')
help = 'specifies processing scheme, can be cpu [default], cuda')
_parser.add_option('--device-num','-d', action='store', type = 'int',
dest = 'devicenum', default=0,
help = 'specifies a GPU device to use for CUDA or OpenCL, 0 by default')
help = 'specifies a GPU device to use for CUDA, 0 by default')
(_opt_list, _args) = _parser.parse_args()

# In this case, the only reason we parsed the arguments was to exit if we were given
Expand Down

0 comments on commit 9a3e7a1

Please sign in to comment.