Changeset 9ee2756 in sasmodels for sasmodels/generate.py


Ignore:
Timestamp:
Oct 19, 2017 12:31:30 PM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
2c108a3
Parents:
94f4543
Message:

simplify kernel wrapper code and combine OpenCL with DLL in one file

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    r8698a0d r9ee2756  
    167167import string 
    168168from zlib import crc32 
     169from inspect import currentframe, getframeinfo 
    169170 
    170171import numpy as np  # type: ignore 
     
    685686    # Load templates and user code 
    686687    kernel_header = load_template('kernel_header.c') 
    687     dll_code = load_template('kernel_iq.c') 
    688     ocl_code = load_template('kernel_iq.cl') 
    689     #ocl_code = load_template('kernel_iq_local.cl') 
     688    kernel_code = load_template('kernel_iq.c') 
    690689    user_code = [(f, open(f).read()) for f in model_sources(model_info)] 
     690 
     691    # What kind of 2D model do we need? 
     692    xy_mode = ('qa' if not _have_Iqxy(user_code) and not isinstance(model_info.Iqxy, str) 
     693               else 'qac' if not partable.is_asymmetric 
     694               else 'qabc') 
    691695 
    692696    # Build initial sources 
     
    713717 
    714718    # Define the parameter table 
    715     # TODO: plug in current line number 
    716     source.append('#line 716 "sasmodels/generate.py"') 
     719    lineno = getframeinfo(currentframe()).lineno + 2 
     720    source.append('#line %d "sasmodels/generate.py"'%lineno) 
     721    #source.append('introduce breakage in generate to test lineno reporting') 
    717722    source.append("#define PARAMETER_TABLE \\") 
    718723    source.append("\\\n".join(p.as_definition() 
     
    733738    pars = ",".join(["_q"] + model_refs) 
    734739    call_iq = "#define CALL_IQ(_q, _v) Iq(%s)" % pars 
    735     if _have_Iqxy(user_code) or isinstance(model_info.Iqxy, str): 
    736         if partable.is_asymmetric: 
    737             pars = ",".join(["_qa", "_qb", "_qc"] + model_refs) 
    738             call_iqxy = "#define CALL_IQ_ABC(_qa,_qb,_qc,_v) Iqxy(%s)" % pars 
    739             clear_iqxy = "#undef CALL_IQ_ABC" 
    740         else: 
    741             pars = ",".join(["_qa", "_qc"] + model_refs) 
    742             call_iqxy = "#define CALL_IQ_AC(_qa,_qc,_v) Iqxy(%s)" % pars 
    743             clear_iqxy = "#undef CALL_IQ_AC" 
    744     else: 
     740    if xy_mode == 'qabc': 
     741        pars = ",".join(["_qa", "_qb", "_qc"] + model_refs) 
     742        call_iqxy = "#define CALL_IQ_ABC(_qa,_qb,_qc,_v) Iqxy(%s)" % pars 
     743        clear_iqxy = "#undef CALL_IQ_ABC" 
     744    elif xy_mode == 'qac': 
     745        pars = ",".join(["_qa", "_qc"] + model_refs) 
     746        call_iqxy = "#define CALL_IQ_AC(_qa,_qc,_v) Iqxy(%s)" % pars 
     747        clear_iqxy = "#undef CALL_IQ_AC" 
     748    else:  # xy_mode == 'qa' 
    745749        pars = ",".join(["_qa"] + model_refs) 
    746750        call_iqxy = "#define CALL_IQ_A(_qa,_v) Iq(%s)" % pars 
     
    761765    # TODO: allow mixed python/opencl kernels? 
    762766 
    763     ocl = kernels(ocl_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 
    764     dll = kernels(dll_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 
     767    ocl = kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 
     768    dll = kernels(kernel_code, call_iq, call_iqxy, clear_iqxy, model_info.name) 
    765769    result = { 
    766770        'dll': '\n'.join(source+dll[0]+dll[1]+dll[2]), 
Note: See TracChangeset for help on using the changeset viewer.