Changeset b3f6bc3 in sasmodels for sasmodels/gpu.py


Ignore:
Timestamp:
Feb 15, 2015 4:07:00 PM (9 years ago)
Author:
pkienzle
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
Message:

support pure python model Iq/Iqxy?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/gpu.py

    rcb6ecf4 rb3f6bc3  
    2424""" 
    2525import numpy as np 
     26 
    2627import pyopencl as cl 
    2728from pyopencl import mem_flags as mf 
    2829 
    2930from . import generate 
     31from .pykernel import PyInput, PyKernel 
    3032 
    3133F64_DEFS = """\ 
     
    185187 
    186188    def __call__(self, input): 
     189        # Support pure python kernel call 
     190        if input.is_2D and callable(self.info['Iqxy']): 
     191            return PyKernel(self.info['Iqxy'], self.info, input) 
     192        elif not input.is_2D and callable(self.info['Iq']): 
     193            return PyKernel(self.info['Iq'], self.info, input) 
     194 
    187195        if self.dtype != input.dtype: 
    188196            raise TypeError("data and kernel have different types") 
     
    202210        Make q input vectors available to the model. 
    203211 
    204         This only needs to be done once for all models that operate on the 
    205         same input.  So for example, if you are adding two different models 
    206         together to compare to a data set, then only one model needs to 
    207         needs to call make_input, so long as the models have the same dtype. 
     212        Note that each model needs its own q vector even if the case of 
     213        mixture models because some models may be OpenCL, some may be 
     214        ctypes and some may be pure python. 
    208215        """ 
    209         # Note: the weird interface, where make_input doesn't care which 
    210         # model calls it, allows us to ask the model to define the data 
    211         # and the caller does not need to know if it is opencl or ctypes. 
    212         # The returned data object is opaque. 
    213         return GpuInput(q_vectors, dtype=self.dtype) 
     216        # Support pure python kernel call 
     217        if len(q_vectors) == 1 and callable(self.info['Iq']): 
     218            return PyInput(q_vectors, dtype=self.dtype) 
     219        elif callable(self.info['Iqxy']): 
     220            return PyInput(q_vectors, dtype=self.dtype) 
     221        else: 
     222            return GpuInput(q_vectors, dtype=self.dtype) 
    214223 
    215224# TODO: check that we don't need a destructor for buffers which go out of scope 
Note: See TracChangeset for help on using the changeset viewer.