Changeset b3f6bc3 in sasmodels for sasmodels/dll.py
- Timestamp:
- Feb 15, 2015 2:07:00 PM (9 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:
- f786ff3
- Parents:
- cb6ecf4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/dll.py
rcb6ecf4 rb3f6bc3 11 11 12 12 from . import generate 13 from .pykernel import PyInput, PyKernel 13 14 14 15 from .generate import F32, F64 … … 116 117 117 118 def __call__(self, input): 119 # Support pure python kernel call 120 if input.is_2D and callable(self.info['Iqxy']): 121 return PyKernel(self.info['Iqxy'], self.info, input) 122 elif not input.is_2D and callable(self.info['Iq']): 123 return PyKernel(self.info['Iq'], self.info, input) 124 118 125 if self.dll is None: self._load_dll() 119 120 126 kernel = self.Iqxy if input.is_2D else self.Iq 121 127 return DllKernel(kernel, self.info, input) … … 125 131 Make q input vectors available to the model. 126 132 127 This only needs to be done once for all models that operate on the 128 same input. So for example, if you are adding two different models 129 together to compare to a data set, then only one model needs to 130 needs to call make_input, so long as the models have the same dtype. 133 Note that each model needs its own q vector even if the case of 134 mixture models because some models may be OpenCL, some may be 135 ctypes and some may be pure python. 131 136 """ 132 return DllInput(q_vectors)137 return PyInput(q_vectors, dtype=F64) 133 138 134 139 def release(self): … … 136 141 137 142 138 class DllInput(object):139 """140 Make q data available to the gpu.141 142 *q_vectors* is a list of q vectors, which will be *[q]* for 1-D data,143 and *[qx, qy]* for 2-D data. Internally, the vectors will be reallocated144 to get the best performance on OpenCL, which may involve shifting and145 stretching the array to better match the memory architecture. Additional146 points will be evaluated with *q=1e-3*.147 148 *dtype* is the data type for the q vectors. The data type should be149 set to match that of the kernel, which is an attribute of150 :class:`GpuProgram`. Note that not all kernels support double151 precision, so even if the program was created for double precision,152 the *GpuProgram.dtype* may be single precision.153 154 Call :meth:`release` when complete. Even if not called directly, the155 buffer will be released when the data object is freed.156 """157 def __init__(self, q_vectors):158 self.nq = q_vectors[0].size159 self.dtype = np.dtype('double')160 self.is_2D = (len(q_vectors) == 2)161 self.q_vectors = [np.ascontiguousarray(q,self.dtype) for q in q_vectors]162 self.q_pointers = [q.ctypes.data for q in q_vectors]163 164 def release(self):165 self.q_vectors = []166 167 143 class DllKernel(object): 168 144 """ 169 145 Callable SAS kernel. 170 146 171 *kernel* is the DllKernel objectto call.147 *kernel* is the c function to call. 172 148 173 149 *info* is the module information
Note: See TracChangeset
for help on using the changeset viewer.