def test_cuda(): try: from pycuda.tools import mark_cuda_test except ImportError: pass yield "SP CUDA Maxwell", mark_cuda_test(do_test_maxwell_cavities_cuda), numpy.float32 yield "DP CUDA Maxwell", mark_cuda_test(do_test_maxwell_cavities_cuda), numpy.float64
def test_cuda(): try: from pycuda.tools import mark_cuda_test except ImportError: pass yield "SP CUDA Maxwell", mark_cuda_test( do_test_maxwell_cavities_cuda), np.float32 yield "DP CUDA Maxwell", mark_cuda_test( do_test_maxwell_cavities_cuda), np.float64
def make_unary_function_test(name, a=0, b=1, threshold=0, complex=False): def test(): gpu_func = getattr(cumath, name) cpu_func = getattr(np, numpy_func_names.get(name, name)) if complex: _dtypes = complex_dtypes else: _dtypes = dtypes for s in sizes: for dtype in _dtypes: np.random.seed(1) A = (np.random.random(s) * (b - a) + a).astype(dtype) if complex: A += (np.random.random(s) * (b - a) + a) * 1j args = gpuarray.to_gpu(A) gpu_results = gpu_func(args).get() cpu_results = cpu_func(A) max_err = np.max(np.abs(cpu_results - gpu_results)) assert (max_err <= threshold).all(), \ (max_err, name, dtype) gpu_results2 = gpuarray.empty_like(args) gr2 = gpu_func(args, out=gpu_results2) assert gpu_results2 is gr2 gr2 = gr2.get() max_err = np.max(np.abs(cpu_results - gr2)) assert (max_err <= threshold).all(), \ (max_err, name, dtype) return mark_cuda_test(test)
def make_unary_function_test(name, a=0, b=1, threshold=0, complex=False): def test(): gpu_func = getattr(cumath, name) cpu_func = getattr(np, numpy_func_names.get(name, name)) if complex: _dtypes = complex_dtypes else: _dtypes = dtypes for s in sizes: for dtype in _dtypes: np.random.seed(1) A = (np.random.random(s)*(b-a) + a).astype(dtype) if complex: A += (np.random.random(s)*(b-a) + a)*1j args = gpuarray.to_gpu(A) gpu_results = gpu_func(args).get() cpu_results = cpu_func(A) max_err = np.max(np.abs(cpu_results - gpu_results)) assert (max_err <= threshold).all(), \ (max_err, name, dtype) return mark_cuda_test(test)
def make_unary_function_test(name, a=0, b=1, threshold=0): def test(): gpu_func = getattr(cumath, name) cpu_func = getattr(np, numpy_func_names.get(name, name)) for s in sizes: for dtype in dtypes: args = gpuarray.arange(a, b, (b - a) / s, dtype=np.float32) gpu_results = gpu_func(args).get() cpu_results = cpu_func(args.get()) max_err = np.max(np.abs(cpu_results - gpu_results)) assert (max_err <= threshold).all(), \ (max_err, name, dtype) return mark_cuda_test(test)
def make_unary_function_test(name, a=0, b=1, threshold=0): def test(): gpu_func = getattr(cumath, name) cpu_func = getattr(np, numpy_func_names.get(name, name)) for s in sizes: for dtype in dtypes: args = gpuarray.arange(a, b, (b-a)/s, dtype=np.float32) gpu_results = gpu_func(args).get() cpu_results = cpu_func(args.get()) max_err = np.max(np.abs(cpu_results - gpu_results)) assert (max_err <= threshold).all(), \ (max_err, name, dtype) return mark_cuda_test(test)
def make_unary_function_test(name, (a, b)=(0, 1), threshold=0): def test(): gpu_func = getattr(cumath, name) cpu_func = getattr(np, numpy_func_names.get(name, name)) for s in sizes: for dtype in dtypes: args = gpuarray.arange(a, b, (b - a) / s, dtype=np.float32) gpu_results = gpu_func(args).get() cpu_results = cpu_func(args.get()) max_err = np.max(np.abs(cpu_results - gpu_results)) assert (max_err <= threshold).all(), \ (max_err, name, dtype) return mark_cuda_test(test) if have_pycuda(): test_ceil = make_unary_function_test("ceil", (-10, 10)) test_floor = make_unary_function_test("ceil", (-10, 10)) test_fabs = make_unary_function_test("fabs", (-10, 10)) test_exp = make_unary_function_test("exp", (-3, 3), 1e-5) test_log = make_unary_function_test("log", (1e-5, 1), 5e-7) test_log10 = make_unary_function_test("log10", (1e-5, 1), 3e-7) test_sqrt = make_unary_function_test("sqrt", (1e-5, 1), 2e-7) test_sin = make_unary_function_test("sin", (-10, 10), 1e-7) test_cos = make_unary_function_test("cos", (-10, 10), 1e-7) test_asin = make_unary_function_test("asin", (-0.9, 0.9), 5e-7) test_acos = make_unary_function_test("acos", (-0.9, 0.9), 5e-7)
def make_unary_function_test(name, (a, b)=(0, 1), threshold=0): def test(): gpu_func = getattr(cumath, name) cpu_func = getattr(np, numpy_func_names.get(name, name)) for s in sizes: for dtype in dtypes: args = gpuarray.arange(a, b, (b-a)/s, dtype=np.float32) gpu_results = gpu_func(args).get() cpu_results = cpu_func(args.get()) max_err = np.max(np.abs(cpu_results - gpu_results)) assert (max_err <= threshold).all(), \ (max_err, name, dtype) return mark_cuda_test(test) if have_pycuda(): test_ceil = make_unary_function_test("ceil", (-10, 10)) test_floor = make_unary_function_test("ceil", (-10, 10)) test_fabs = make_unary_function_test("fabs", (-10, 10)) test_exp = make_unary_function_test("exp", (-3, 3), 1e-5) test_log = make_unary_function_test("log", (1e-5, 1), 5e-7) test_log10 = make_unary_function_test("log10", (1e-5, 1), 3e-7) test_sqrt = make_unary_function_test("sqrt", (1e-5, 1), 2e-7) test_sin = make_unary_function_test("sin", (-10, 10), 1e-7) test_cos = make_unary_function_test("cos", (-10, 10), 1e-7)