Changeset ff7119b in sasmodels for sasmodels/alignment.py
- Timestamp:
- Aug 26, 2014 10:27:06 PM (10 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 5d4777d
- Parents:
- a7684e5
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/alignment.py
r14de349 rff7119b 3 3 4 4 Some web sites say that maximizing performance for OpenCL code requires 5 aligning data on certain memory boundaries. 5 aligning data on certain memory boundaries. The following functions 6 provide this service: 6 7 7 :func:` data_alignment` queries all devices in the OpenCL context, returning8 the most restrictivealignment.8 :func:`align_data` aligns an existing array, returning a new array of the 9 correct alignment. 9 10 10 :func:`align_ data` aligns an existing array.11 :func:`align_empty` to create an empty array of the correct alignment. 11 12 12 :func:`align_empty` to create a new array of the correct alignment.13 Set alignment to :func:`gpu.environment()` attribute *boundary*. 13 14 14 15 Note: This code is unused. So far, tests have not demonstrated any … … 17 18 to decide whether it is really required. 18 19 """ 19 20 20 import numpy as np 21 import pyopencl as cl22 23 def data_alignment(context):24 """25 Return the desired byte alignment across all devices.26 """27 # Note: rely on the fact that alignment will be 2^k28 return max(d.min_data_type_align_size for d in context.devices)29 21 30 22 def align_empty(shape, dtype, alignment=128): 23 """ 24 Return an empty array aligned on the alignment boundary. 25 """ 31 26 size = np.prod(shape) 32 27 dtype = np.dtype(dtype) … … 40 35 41 36 def align_data(v, dtype, alignment=128): 37 """ 38 Return a copy of an array on the alignment boundary. 39 """ 42 40 # if v is contiguous, aligned, and of the correct type then just return v 43 41 view = align_empty(v.shape, dtype, alignment=alignment) … … 45 43 return view 46 44 47 def work_group_size(context, kernel):48 """49 Return the desired work group size for the context.50 """51 max(kernel.get_work_group_info(cl.kernel_work_group_info.PREFERRED_WORK_GROUP_SIZE_MULTIPLE, d)52 for d in context.devices)53 54
Note: See TracChangeset
for help on using the changeset viewer.