diff --git a/boxtree/area_query.py b/boxtree/area_query.py index b35d6d9abe83a08c88faf023edb1f27f6b70739e..700b64757edf5da5fdd63f268ab9db787698184d 100644 --- a/boxtree/area_query.py +++ b/boxtree/area_query.py @@ -663,13 +663,13 @@ class AreaQueryBuilder(object): debug=False, root_extent_stretch_factor=TreeBuilder.ROOT_EXTENT_STRETCH_FACTOR) - from pyopencl.tools import VectorArg, ScalarArg + from boxtree.tools import VectorArg, ScalarArg arg_decls = [ - VectorArg(coord_dtype, "box_centers"), + VectorArg(coord_dtype, "box_centers", with_offset=False), ScalarArg(coord_dtype, "root_extent"), VectorArg(np.uint8, "box_levels"), ScalarArg(box_id_dtype, "aligned_nboxes"), - VectorArg(box_id_dtype, "box_child_ids"), + VectorArg(box_id_dtype, "box_child_ids", with_offset=False), VectorArg(box_flags_enum.dtype, "box_flags"), VectorArg(peer_list_idx_dtype, "peer_list_starts"), VectorArg(box_id_dtype, "peer_lists"), @@ -748,12 +748,12 @@ class AreaQueryBuilder(object): result, evt = area_query_kernel( queue, len(ball_radii), tree.box_centers.data, tree.root_extent, - tree.box_levels.data, tree.aligned_nboxes, - tree.box_child_ids.data, tree.box_flags.data, - peer_lists.peer_list_starts.data, - peer_lists.peer_lists.data, ball_radii.data, + tree.box_levels, tree.aligned_nboxes, + tree.box_child_ids.data, tree.box_flags, + peer_lists.peer_list_starts, + peer_lists.peer_lists, ball_radii, *(tuple(tree.bounding_box[0]) - + tuple(bc.data for bc in ball_centers)), + + tuple(bc for bc in ball_centers)), wait_for=wait_for) aq_plog.done() @@ -1066,13 +1066,13 @@ class PeerListFinder(object): targets_have_extent=False, sources_have_extent=False) - from pyopencl.tools import VectorArg, ScalarArg + from boxtree.tools import VectorArg, ScalarArg arg_decls = [ - VectorArg(coord_dtype, "box_centers"), + VectorArg(coord_dtype, "box_centers", with_offset=False), ScalarArg(coord_dtype, "root_extent"), VectorArg(np.uint8, "box_levels"), ScalarArg(box_id_dtype, "aligned_nboxes"), - VectorArg(box_id_dtype, "box_child_ids"), + VectorArg(box_id_dtype, "box_child_ids", with_offset=False), VectorArg(box_flags_enum.dtype, "box_flags"), ] @@ -1116,8 +1116,8 @@ class PeerListFinder(object): result, evt = peer_list_finder_kernel( queue, tree.nboxes, tree.box_centers.data, tree.root_extent, - tree.box_levels.data, tree.aligned_nboxes, - tree.box_child_ids.data, tree.box_flags.data, + tree.box_levels, tree.aligned_nboxes, + tree.box_child_ids.data, tree.box_flags, wait_for=wait_for) pl_plog.done() diff --git a/boxtree/tools.py b/boxtree/tools.py index 03678ae2b4cde61c32fe228a2adddec930d59337..56180ac83ee91ebe9dedbeb4e6f155bef1bea84f 100644 --- a/boxtree/tools.py +++ b/boxtree/tools.py @@ -27,10 +27,20 @@ import numpy as np from pytools import Record, memoize_method import pyopencl as cl import pyopencl.array # noqa -from pyopencl.tools import dtype_to_c_struct +from pyopencl.tools import dtype_to_c_struct, VectorArg as _VectorArg +from pyopencl.tools import ScalarArg # noqa from mako.template import Template from pytools.obj_array import make_obj_array from boxtree.fmm import TimingFuture, TimingResult +import loopy as lp + +from loopy.version import LOOPY_USE_LANGUAGE_VERSION_2018_2 # noqa + +from functools import partial + + +# Use offsets in VectorArg by default. +VectorArg = partial(_VectorArg, with_offset=True) AXIS_NAMES = ("x", "y", "z", "w") @@ -100,16 +110,16 @@ def make_normal_particle_array(queue, nparticles, dims, dtype, seed=15): def make_surface_particle_array(queue, nparticles, dims, dtype, seed=15): - import loopy as lp - if dims == 2: def get_2d_knl(dtype): knl = lp.make_kernel( "{[i]: 0<=i phi = 2*M_PI/n * i - x[i] = 0.5* (3*cos(phi) + 2*sin(3*phi)) - y[i] = 0.5* (1*sin(phi) + 1.5*sin(2*phi)) + for i + <> phi = 2*M_PI/n * i + x[i] = 0.5* (3*cos(phi) + 2*sin(3*phi)) + y[i] = 0.5* (1*sin(phi) + 1.5*sin(2*phi)) + end """, [ lp.GlobalArg("x,y", dtype, shape=lp.auto), @@ -133,11 +143,13 @@ def make_surface_particle_array(queue, nparticles, dims, dtype, seed=15): knl = lp.make_kernel( "{[i,j]: 0<=i,j phi = 2*M_PI/n * i - <> theta = 2*M_PI/n * j - x[i,j] = 5*cos(phi) * (3 + cos(theta)) - y[i,j] = 5*sin(phi) * (3 + cos(theta)) - z[i,j] = 5*sin(theta) + for i,j + <> phi = 2*M_PI/n * i + <> theta = 2*M_PI/n * j + x[i,j] = 5*cos(phi) * (3 + cos(theta)) + y[i,j] = 5*sin(phi) * (3 + cos(theta)) + z[i,j] = 5*sin(theta) + end """, [ lp.GlobalArg("x,y,z,", dtype, shape=lp.auto), @@ -159,8 +171,6 @@ def make_surface_particle_array(queue, nparticles, dims, dtype, seed=15): def make_uniform_particle_array(queue, nparticles, dims, dtype, seed=15): - import loopy as lp - if dims == 2: n = int(nparticles**0.5) @@ -168,13 +178,15 @@ def make_uniform_particle_array(queue, nparticles, dims, dtype, seed=15): knl = lp.make_kernel( "{[i,j]: 0<=i,j xx = 4*i/(n-1) - <> yy = 4*j/(n-1) - angle = 0.3 - <> s = sin(angle) - <> c = cos(angle) - x[i,j] = c*xx + s*yy - 2 - y[i,j] = -s*xx + c*yy - 2 + for i,j + <> xx = 4*i/(n-1) + <> yy = 4*j/(n-1) + angle = 0.3 + <> s = sin(angle) + <> c = cos(angle) + x[i,j] = c*xx + s*yy - 2 + y[i,j] = -s*xx + c*yy - 2 + end """, [ lp.GlobalArg("x,y", dtype, shape=lp.auto), @@ -198,25 +210,27 @@ def make_uniform_particle_array(queue, nparticles, dims, dtype, seed=15): knl = lp.make_kernel( "{[i,j,k]: 0<=i,j,k xx = i/(n-1) - <> yy = j/(n-1) - <> zz = k/(n-1) - - phi = 0.3 - <> s1 = sin(phi) - <> c1 = cos(phi) - - <> xxx = c1*xx + s1*yy - <> yyy = -s1*xx + c1*yy - <> zzz = zz - - theta = 0.7 - <> s2 = sin(theta) - <> c2 = cos(theta) - - x[i,j,k] = 4 * (c2*xxx + s2*zzz) - 2 - y[i,j,k] = 4 * yyy - 2 - z[i,j,k] = 4 * (-s2*xxx + c2*zzz) - 2 + for i,j,k + <> xx = i/(n-1) + <> yy = j/(n-1) + <> zz = k/(n-1) + + phi = 0.3 + <> s1 = sin(phi) + <> c1 = cos(phi) + + <> xxx = c1*xx + s1*yy + <> yyy = -s1*xx + c1*yy + <> zzz = zz + + theta = 0.7 + <> s2 = sin(theta) + <> c2 = cos(theta) + + x[i,j,k] = 4 * (c2*xxx + s2*zzz) - 2 + y[i,j,k] = 4 * yyy - 2 + z[i,j,k] = 4 * (-s2*xxx + c2*zzz) - 2 + end """, [ lp.GlobalArg("x,y,z", dtype, shape=lp.auto), @@ -378,21 +392,21 @@ class GappyCopyAndMapKernel: @memoize_method def _get_kernel(self, dtype, src_index_dtype, dst_index_dtype, have_src_indices, have_dst_indices, map_values): - from pyopencl.tools import VectorArg + from boxtree.tools import VectorArg args = [ - VectorArg(dtype, "input_ary", with_offset=True), - VectorArg(dtype, "output_ary", with_offset=True), + VectorArg(dtype, "input_ary"), + VectorArg(dtype, "output_ary"), ] if have_src_indices: - args.append(VectorArg(src_index_dtype, "from_indices", with_offset=True)) + args.append(VectorArg(src_index_dtype, "from_indices")) if have_dst_indices: - args.append(VectorArg(dst_index_dtype, "to_indices", with_offset=True)) + args.append(VectorArg(dst_index_dtype, "to_indices")) if map_values: - args.append(VectorArg(dtype, "value_map", with_offset=True)) + args.append(VectorArg(dtype, "value_map")) from pyopencl.tools import dtype_to_ctype src = GAPPY_COPY_TPL.render( diff --git a/boxtree/traversal.py b/boxtree/traversal.py index 59624df36d4eeed0fe9fa8077b8a75eaa6715ebe..2d60f68725ea5f1b2b95a77f7b547f5954cd6951 100644 --- a/boxtree/traversal.py +++ b/boxtree/traversal.py @@ -1793,7 +1793,7 @@ class FMMTraversalBuilder: from_sep_smaller_crit=from_sep_smaller_crit, ) from pyopencl.algorithm import ListOfListsBuilder - from pyopencl.tools import VectorArg, ScalarArg + from boxtree.tools import VectorArg, ScalarArg result = {} @@ -1851,11 +1851,11 @@ class FMMTraversalBuilder: # {{{ build list N builders base_args = [ - VectorArg(coord_dtype, "box_centers"), + VectorArg(coord_dtype, "box_centers", with_offset=False), ScalarArg(coord_dtype, "root_extent"), VectorArg(np.uint8, "box_levels"), ScalarArg(box_id_dtype, "aligned_nboxes"), - VectorArg(box_id_dtype, "box_child_ids"), + VectorArg(box_id_dtype, "box_child_ids", with_offset=False), VectorArg(box_flags_enum.dtype, "box_flags"), ] @@ -1869,7 +1869,8 @@ class FMMTraversalBuilder: ("from_sep_siblings", FROM_SEP_SIBLINGS_TEMPLATE, [ VectorArg(box_id_dtype, "target_or_target_parent_boxes"), - VectorArg(box_id_dtype, "box_parent_ids"), + VectorArg(box_id_dtype, "box_parent_ids", + with_offset=False), VectorArg(box_id_dtype, "same_level_non_well_sep_boxes_starts"), VectorArg(box_id_dtype, @@ -1883,8 +1884,10 @@ class FMMTraversalBuilder: "same_level_non_well_sep_boxes_starts"), VectorArg(box_id_dtype, "same_level_non_well_sep_boxes_lists"), - VectorArg(coord_dtype, "box_target_bounding_box_min"), - VectorArg(coord_dtype, "box_target_bounding_box_max"), + VectorArg(coord_dtype, "box_target_bounding_box_min", + with_offset=False), + VectorArg(coord_dtype, "box_target_bounding_box_max", + with_offset=False), VectorArg(particle_id_dtype, "box_source_counts_cumul"), ScalarArg(particle_id_dtype, "from_sep_smaller_min_nsources_cumul"), @@ -1897,7 +1900,8 @@ class FMMTraversalBuilder: [ ScalarArg(coord_dtype, "stick_out_factor"), VectorArg(box_id_dtype, "target_or_target_parent_boxes"), - VectorArg(box_id_dtype, "box_parent_ids"), + VectorArg(box_id_dtype, "box_parent_ids", + with_offset=False), VectorArg(box_id_dtype, "same_level_non_well_sep_boxes_starts"), VectorArg(box_id_dtype, @@ -1982,7 +1986,7 @@ class FMMTraversalBuilder: fin_debug("building list of source boxes, their parents, and target boxes") result, evt = knl_info.sources_parents_and_targets_builder( - queue, tree.nboxes, tree.box_flags.data, wait_for=wait_for) + queue, tree.nboxes, tree.box_flags, wait_for=wait_for) wait_for = [evt] source_parent_boxes = result["source_parent_boxes"].lists @@ -2137,8 +2141,8 @@ class FMMTraversalBuilder: result, evt = knl_info.same_level_non_well_sep_boxes_builder( queue, tree.nboxes, - tree.box_centers.data, tree.root_extent, tree.box_levels.data, - tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags.data, + tree.box_centers.data, tree.root_extent, tree.box_levels, + tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags, wait_for=wait_for) wait_for = [evt] same_level_non_well_sep_boxes = result["same_level_non_well_sep_boxes"] @@ -2151,9 +2155,9 @@ class FMMTraversalBuilder: result, evt = knl_info.neighbor_source_boxes_builder( queue, len(target_boxes), - tree.box_centers.data, tree.root_extent, tree.box_levels.data, - tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags.data, - target_boxes.data, wait_for=wait_for) + tree.box_centers.data, tree.root_extent, tree.box_levels, + tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags, + target_boxes, wait_for=wait_for) wait_for = [evt] neighbor_source_boxes = result["neighbor_source_boxes"] @@ -2166,11 +2170,11 @@ class FMMTraversalBuilder: result, evt = knl_info.from_sep_siblings_builder( queue, len(target_or_target_parent_boxes), - tree.box_centers.data, tree.root_extent, tree.box_levels.data, - tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags.data, - target_or_target_parent_boxes.data, tree.box_parent_ids.data, - same_level_non_well_sep_boxes.starts.data, - same_level_non_well_sep_boxes.lists.data, + tree.box_centers.data, tree.root_extent, tree.box_levels, + tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags, + target_or_target_parent_boxes, tree.box_parent_ids.data, + same_level_non_well_sep_boxes.starts, + same_level_non_well_sep_boxes.lists, wait_for=wait_for) wait_for = [evt] from_sep_siblings = result["from_sep_siblings"] @@ -2185,14 +2189,14 @@ class FMMTraversalBuilder: from_sep_smaller_base_args = ( queue, len(target_boxes), - tree.box_centers.data, tree.root_extent, tree.box_levels.data, - tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags.data, - tree.stick_out_factor, target_boxes.data, - same_level_non_well_sep_boxes.starts.data, - same_level_non_well_sep_boxes.lists.data, + tree.box_centers.data, tree.root_extent, tree.box_levels, + tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags, + tree.stick_out_factor, target_boxes, + same_level_non_well_sep_boxes.starts, + same_level_non_well_sep_boxes.lists, box_target_bounding_box_min.data, box_target_bounding_box_max.data, - tree.box_source_counts_cumul.data, + tree.box_source_counts_cumul, _from_sep_smaller_min_nsources_cumul, ) @@ -2240,12 +2244,12 @@ class FMMTraversalBuilder: result, evt = knl_info.from_sep_bigger_builder( queue, len(target_or_target_parent_boxes), - tree.box_centers.data, tree.root_extent, tree.box_levels.data, - tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags.data, - tree.stick_out_factor, target_or_target_parent_boxes.data, + tree.box_centers.data, tree.root_extent, tree.box_levels, + tree.aligned_nboxes, tree.box_child_ids.data, tree.box_flags, + tree.stick_out_factor, target_or_target_parent_boxes, tree.box_parent_ids.data, - same_level_non_well_sep_boxes.starts.data, - same_level_non_well_sep_boxes.lists.data, + same_level_non_well_sep_boxes.starts, + same_level_non_well_sep_boxes.lists, wait_for=wait_for) wait_for = [evt] diff --git a/boxtree/tree.py b/boxtree/tree.py index 174286f8850e737c96c4e67ec7c00f4bdb6ecb9a..c09ee65a24960b1eccb993b717e0c3291f5dcf8e 100644 --- a/boxtree/tree.py +++ b/boxtree/tree.py @@ -731,7 +731,8 @@ class ParticleListFilter(object): @memoize_method def get_filter_target_lists_in_user_order_kernel(self, particle_id_dtype, user_order_flags_dtype): - from pyopencl.tools import VectorArg, dtype_to_ctype + from boxtree.tools import VectorArg + from pyopencl.tools import dtype_to_ctype from pyopencl.algorithm import ListOfListsBuilder from mako.template import Template @@ -786,9 +787,10 @@ class ParticleListFilter(object): tree.particle_id_dtype, user_order_flags.dtype) result, evt = kernel(queue, tree.nboxes, - user_order_flags.data, - user_target_ids.data, - tree.box_target_starts.data, tree.box_target_counts_nonchild.data) + user_order_flags, + user_target_ids, + tree.box_target_starts, + tree.box_target_counts_nonchild) return FilteredTargetListsInUserOrder( nfiltered_targets=result["filt_tgt_list"].count, diff --git a/boxtree/tree_build_kernels.py b/boxtree/tree_build_kernels.py index 0d900ce4e92e1b616e6ac531f0b3181e39d5eb6e..3bab74bb6b115fe494294e8b8441d1af779f6d41 100644 --- a/boxtree/tree_build_kernels.py +++ b/boxtree/tree_build_kernels.py @@ -892,7 +892,7 @@ LEVEL_RESTRICT_TPL = Template( def build_level_restrict_kernel(context, preamble_with_dtype_decls, dimensions, axis_names, box_id_dtype, coord_dtype, box_level_dtype, max_levels): - from pyopencl.tools import VectorArg, ScalarArg + from boxtree.tools import VectorArg, ScalarArg arguments = ( [ @@ -1369,7 +1369,7 @@ def get_tree_build_kernel_info(context, dimensions, coord_dtype, + str(MORTON_NR_SCAN_PREAMBLE_TPL.render(**codegen_args)) ) - from pyopencl.tools import VectorArg, ScalarArg + from boxtree.tools import VectorArg, ScalarArg common_arguments = ( [ # box-local morton bin counts for each particle at the current level @@ -1496,8 +1496,8 @@ def get_tree_build_kernel_info(context, dimensions, coord_dtype, context, common_arguments + [ - VectorArg(np.int32, "box_has_children", with_offset=True), - VectorArg(np.int32, "box_force_split", with_offset=True), + VectorArg(np.int32, "box_has_children"), + VectorArg(np.int32, "box_force_split"), ScalarArg(coord_dtype, "root_extent"), ] + [VectorArg(box_id_dtype, "box_child_ids_mnr_{mnr}".format(mnr=mnr)) @@ -1531,11 +1531,10 @@ def get_tree_build_kernel_info(context, dimensions, coord_dtype, context, common_arguments + [ - VectorArg(np.int32, "box_has_children", with_offset=True), - VectorArg(np.int32, "box_force_split", with_offset=True), - VectorArg(particle_id_dtype, "new_user_srcntgt_ids", - with_offset=True), - VectorArg(box_id_dtype, "new_srcntgt_box_ids", with_offset=True), + VectorArg(np.int32, "box_has_children"), + VectorArg(np.int32, "box_force_split"), + VectorArg(particle_id_dtype, "new_user_srcntgt_ids"), + VectorArg(box_id_dtype, "new_srcntgt_box_ids"), ], str(particle_renumberer_kernel_source), name="renumber_particles", preamble=( @@ -1582,7 +1581,7 @@ def get_tree_build_kernel_info(context, dimensions, coord_dtype, # FIXME: Turn me into a scan template - from pyopencl.tools import VectorArg + from boxtree.tools import VectorArg find_prune_indices_kernel = GenericScanKernel( context, box_id_dtype, arguments=[ diff --git a/setup.py b/setup.py index 32cca6a23d46884c398fe0f31c363f7e8f4e7c76..4d1d3254d784c48b10e2a4615144a2432d5745e3 100644 --- a/setup.py +++ b/setup.py @@ -42,7 +42,7 @@ def main(): packages=["boxtree"], install_requires=[ "pytools>=2018.4", - "pyopencl>=2013.1", + "pyopencl>=2018.2", "Mako>=0.7.3", "pytest>=2.3", "cgen>=2013.1.2", diff --git a/test/test_fmm.py b/test/test_fmm.py index d1c0ecbbe1c29a22a2e4e16ddfa87741dd370156..53892d5b8347db75857aa43de0b0c579ed11e56a 100644 --- a/test/test_fmm.py +++ b/test/test_fmm.py @@ -106,7 +106,7 @@ class ConstantOneExpansionWranglerWithFilteredTargetsInUserOrder( (3, 5 * 10**5, 4*10**4, "t", p_normal, p_normal, None, "l2", "static_l2"), # noqa: E501 ]) -def test_fmm_completeness(ctx_getter, dims, nsources_req, ntargets_req, +def test_fmm_completeness(ctx_factory, dims, nsources_req, ntargets_req, who_has_extent, source_gen, target_gen, filter_kind, well_sep_is_n_away, extent_norm, from_sep_smaller_crit): """Tests whether the built FMM traversal structures and driver completely @@ -118,7 +118,7 @@ def test_fmm_completeness(ctx_getter, dims, nsources_req, ntargets_req, logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) dtype = np.float64 @@ -336,13 +336,13 @@ def test_fmm_completeness(ctx_getter, dims, nsources_req, ntargets_req, @pytest.mark.parametrize("dims", [2, 3]) @pytest.mark.parametrize("use_dipoles", [True, False]) @pytest.mark.parametrize("helmholtz_k", [0, 2]) -def test_pyfmmlib_fmm(ctx_getter, dims, use_dipoles, helmholtz_k): +def test_pyfmmlib_fmm(ctx_factory, dims, use_dipoles, helmholtz_k): logging.basicConfig(level=logging.INFO) from pytest import importorskip importorskip("pyfmmlib") - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nsources = 3000 @@ -505,8 +505,8 @@ def test_pyfmmlib_fmm(ctx_getter, dims, use_dipoles, helmholtz_k): # {{{ test particle count thresholding in traversal generation @pytest.mark.parametrize("enable_extents", [True, False]) -def test_interaction_list_particle_count_thresholding(ctx_getter, enable_extents): - ctx = ctx_getter() +def test_interaction_list_particle_count_thresholding(ctx_factory, enable_extents): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) logging.basicConfig(level=logging.INFO) @@ -563,8 +563,8 @@ def test_interaction_list_particle_count_thresholding(ctx_getter, enable_extents # {{{ test fmm with float32 dtype @pytest.mark.parametrize("enable_extents", [True, False]) -def test_fmm_float32(ctx_getter, enable_extents): - ctx = ctx_getter() +def test_fmm_float32(ctx_factory, enable_extents): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from pyopencl.characterize import has_struct_arg_count_bug diff --git a/test/test_tools.py b/test/test_tools.py index 0a2f23e9a77b82c0c3e37c40117f1e71bf140152..2da427e2470a0636d152c976c225286045f0045a 100644 --- a/test/test_tools.py +++ b/test/test_tools.py @@ -26,6 +26,17 @@ THE SOFTWARE. """ +import pytest +from pyopencl.tools import ( # noqa + pytest_generate_tests_for_pyopencl as pytest_generate_tests) + + +from boxtree.tools import ( # noqa: F401 + make_normal_particle_array as p_normal, + make_surface_particle_array as p_surface, + make_uniform_particle_array as p_uniform) + + def test_device_record(): from boxtree.tools import DeviceDataRecord @@ -52,6 +63,17 @@ def test_device_record(): assert np.array_equal(record_host.obj_array[i], record.obj_array[i]) +@pytest.mark.parametrize("array_factory", (p_normal, p_surface, p_uniform)) +@pytest.mark.parametrize("dim", (2, 3)) +@pytest.mark.parametrize("dtype", (np.float32, np.float64)) +def test_particle_array(ctx_factory, array_factory, dim, dtype): + ctx = ctx_factory() + queue = cl.CommandQueue(ctx) + particles = array_factory(queue, 1000, dim, dtype) + assert len(particles) == dim + assert all(len(particles[0]) == len(axis) for axis in particles) + + # You can test individual routines by typing # $ python test_tools.py 'test_routine' diff --git a/test/test_traversal.py b/test/test_traversal.py index 538739dcccc10221389d3d950231eaa34974b47e..32645a2a708d0f4403a714fdccf69bd654cc7dbe 100644 --- a/test/test_traversal.py +++ b/test/test_traversal.py @@ -48,10 +48,10 @@ logger = logging.getLogger(__name__) (3, True), (3, False), ]) -def test_tree_connectivity(ctx_getter, dims, sources_are_targets): +def test_tree_connectivity(ctx_factory, dims, sources_are_targets): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) dtype = np.float64 @@ -292,8 +292,8 @@ def test_tree_connectivity(ctx_getter, dims, sources_are_targets): # {{{ visualization helper (not a test) -def plot_traversal(ctx_getter, do_plot=False, well_sep_is_n_away=1): - ctx = ctx_getter() +def plot_traversal(ctx_factory, do_plot=False, well_sep_is_n_away=1): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) #for dims in [2, 3]: diff --git a/test/test_tree.py b/test/test_tree.py index e4bc95e7dec877ab1ed352c433ccb300a6ce9f21..2f55273633e154732e3846caeaa6ff4d81dd533f 100644 --- a/test/test_tree.py +++ b/test/test_tree.py @@ -43,10 +43,10 @@ logger = logging.getLogger(__name__) @pytest.mark.parametrize("dtype", [np.float32, np.float64]) @pytest.mark.parametrize("dims", [2, 3]) @pytest.mark.parametrize("nparticles", [9, 4096, 10**5]) -def test_bounding_box(ctx_getter, dtype, dims, nparticles): +def test_bounding_box(ctx_factory, dtype, dims, nparticles): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree.tools import AXIS_NAMES @@ -213,8 +213,8 @@ def particle_tree_test_decorator(f): @particle_tree_test_decorator -def test_single_box_particle_tree(ctx_getter, dtype, dims, do_plot=False): - ctx = ctx_getter() +def test_single_box_particle_tree(ctx_factory, dtype, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree import TreeBuilder @@ -225,8 +225,8 @@ def test_single_box_particle_tree(ctx_getter, dtype, dims, do_plot=False): @particle_tree_test_decorator -def test_two_level_particle_tree(ctx_getter, dtype, dims, do_plot=False): - ctx = ctx_getter() +def test_two_level_particle_tree(ctx_factory, dtype, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree import TreeBuilder @@ -237,8 +237,8 @@ def test_two_level_particle_tree(ctx_getter, dtype, dims, do_plot=False): @particle_tree_test_decorator -def test_unpruned_particle_tree(ctx_getter, dtype, dims, do_plot=False): - ctx = ctx_getter() +def test_unpruned_particle_tree(ctx_factory, dtype, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree import TreeBuilder @@ -250,8 +250,8 @@ def test_unpruned_particle_tree(ctx_getter, dtype, dims, do_plot=False): @particle_tree_test_decorator -def test_particle_tree_with_reallocations(ctx_getter, dtype, dims, do_plot=False): - ctx = ctx_getter() +def test_particle_tree_with_reallocations(ctx_factory, dtype, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree import TreeBuilder @@ -263,8 +263,8 @@ def test_particle_tree_with_reallocations(ctx_getter, dtype, dims, do_plot=False @particle_tree_test_decorator def test_particle_tree_with_many_empty_leaves( - ctx_getter, dtype, dims, do_plot=False): - ctx = ctx_getter() + ctx_factory, dtype, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree import TreeBuilder @@ -275,8 +275,8 @@ def test_particle_tree_with_many_empty_leaves( @particle_tree_test_decorator -def test_vanilla_particle_tree(ctx_getter, dtype, dims, do_plot=False): - ctx = ctx_getter() +def test_vanilla_particle_tree(ctx_factory, dtype, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree import TreeBuilder @@ -287,9 +287,9 @@ def test_vanilla_particle_tree(ctx_getter, dtype, dims, do_plot=False): @particle_tree_test_decorator -def test_explicit_refine_weights_particle_tree(ctx_getter, dtype, dims, +def test_explicit_refine_weights_particle_tree(ctx_factory, dtype, dims, do_plot=False): - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree import TreeBuilder @@ -307,8 +307,8 @@ def test_explicit_refine_weights_particle_tree(ctx_getter, dtype, dims, @particle_tree_test_decorator -def test_non_adaptive_particle_tree(ctx_getter, dtype, dims, do_plot=False): - ctx = ctx_getter() +def test_non_adaptive_particle_tree(ctx_factory, dtype, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) from boxtree import TreeBuilder @@ -324,10 +324,10 @@ def test_non_adaptive_particle_tree(ctx_getter, dtype, dims, do_plot=False): @pytest.mark.opencl @pytest.mark.parametrize("dims", [2, 3]) -def test_source_target_tree(ctx_getter, dims, do_plot=False): +def test_source_target_tree(ctx_factory, dims, do_plot=False): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nsources = 2 * 10**5 @@ -436,10 +436,10 @@ def test_source_target_tree(ctx_getter, dims, do_plot=False): @pytest.mark.opencl @pytest.mark.parametrize("dims", [2, 3]) @pytest.mark.parametrize("extent_norm", ["linf", "l2"]) -def test_extent_tree(ctx_getter, dims, extent_norm, do_plot=False): +def test_extent_tree(ctx_factory, dims, extent_norm, do_plot=False): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nsources = 100000 @@ -659,10 +659,10 @@ def test_extent_tree(ctx_getter, dims, extent_norm, do_plot=False): @pytest.mark.opencl @pytest.mark.geo_lookup @pytest.mark.parametrize("dims", [2, 3]) -def test_leaves_to_balls_query(ctx_getter, dims, do_plot=False): +def test_leaves_to_balls_query(ctx_factory, dims, do_plot=False): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nparticles = 10**5 @@ -763,8 +763,8 @@ def run_area_query_test(ctx, queue, tree, ball_centers, ball_radii): @pytest.mark.opencl @pytest.mark.area_query @pytest.mark.parametrize("dims", [2, 3]) -def test_area_query(ctx_getter, dims, do_plot=False): - ctx = ctx_getter() +def test_area_query(ctx_factory, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nparticles = 10**5 @@ -792,12 +792,12 @@ def test_area_query(ctx_getter, dims, do_plot=False): @pytest.mark.opencl @pytest.mark.area_query @pytest.mark.parametrize("dims", [2, 3]) -def test_area_query_balls_outside_bbox(ctx_getter, dims, do_plot=False): +def test_area_query_balls_outside_bbox(ctx_factory, dims, do_plot=False): """ The input to the area query includes balls whose centers are not within the tree bounding box. """ - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nparticles = 10**4 @@ -832,8 +832,8 @@ def test_area_query_balls_outside_bbox(ctx_getter, dims, do_plot=False): @pytest.mark.opencl @pytest.mark.area_query @pytest.mark.parametrize("dims", [2, 3]) -def test_area_query_elwise(ctx_getter, dims, do_plot=False): - ctx = ctx_getter() +def test_area_query_elwise(ctx_factory, dims, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nparticles = 10**5 @@ -901,8 +901,8 @@ def test_area_query_elwise(ctx_getter, dims, do_plot=False): @pytest.mark.parametrize("lookbehind", [0, 1]) @pytest.mark.parametrize("skip_prune", [True, False]) @pytest.mark.parametrize("dims", [2, 3]) -def test_level_restriction(ctx_getter, dims, skip_prune, lookbehind, do_plot=False): - ctx = ctx_getter() +def test_level_restriction(ctx_factory, dims, skip_prune, lookbehind, do_plot=False): + ctx = ctx_factory() queue = cl.CommandQueue(ctx) nparticles = 10**5 @@ -982,10 +982,10 @@ def test_level_restriction(ctx_getter, dims, skip_prune, lookbehind, do_plot=Fal @pytest.mark.geo_lookup @pytest.mark.parametrize("dtype", [np.float32, np.float64]) @pytest.mark.parametrize("dims", [2, 3]) -def test_space_invader_query(ctx_getter, dims, dtype, do_plot=False): +def test_space_invader_query(ctx_factory, dims, dtype, do_plot=False): logging.basicConfig(level=logging.INFO) - ctx = ctx_getter() + ctx = ctx_factory() queue = cl.CommandQueue(ctx) dtype = np.dtype(dtype)