It is possible to specify include directories for models whether they are compiled for cpu or gpu. See patch below.
The individual OpenCL implementations can be temperamental. For example, the apple opencl compiler does not accept -I "path/to/models" with quotes around the path. Instead it needs spaces in the path escaped with a backslash.
If we do this, though, we need to scan the sources for all files for the includes so that we can detect code changes that require recompile and so that we can convert double to float when running models in single precision. These updates are not included in the patch.
diff --git a/sasmodels/kernelcl.py b/sasmodels/kernelcl.py
index 76500360..fbf4e980 100644
--- a/sasmodels/kernelcl.py
+++ b/sasmodels/kernelcl.py
@@ -234,6 +234,7 @@ def compile_model(context, source, dtype, fast=False):
source_list.insert(0, "#define USE_SINCOS\n")
options = (get_fast_inaccurate_build_options(context.devices[0])
if fast else [])
+ options = [*options, '-I', generate.MODEL_PATH.replace(" ", r"\ ")]
source = "\n".join(source_list)
program = cl.Program(context, source).build(options=options)
diff --git a/sasmodels/kernelcuda.py b/sasmodels/kernelcuda.py
index cf96de70..8dfeffd1 100644
--- a/sasmodels/kernelcuda.py
+++ b/sasmodels/kernelcuda.py
@@ -224,6 +224,7 @@ def compile_model(source, dtype, fast=False):
#print(source)
#options = ['--verbose', '-E']
options = ['--use_fast_math'] if fast else None
+ options = [*options, '-I', generate.MODEL_PATH.replace(" ", r"\ ")]
program = SourceModule(source, no_extern_c=True, options=options) #, include_dirs=[...])
#print("done with "+program)
diff --git a/sasmodels/kerneldll.py b/sasmodels/kerneldll.py
index 216b668d..344a0323 100644
--- a/sasmodels/kerneldll.py
+++ b/sasmodels/kerneldll.py
@@ -88,7 +88,7 @@ except ImportError:
from . import generate
from .exception import annotate_exception
-from .generate import F16, F32, F64
+from .generate import F16, F32, F64, MODEL_PATH
from .kernel import Kernel, KernelModel
from .kernelpy import PyInput
@@ -133,7 +133,7 @@ if COMPILER == "unix":
# On Mac users will need the X code command line tools installed.
#COMPILE = "gcc-mp-4.7 -shared -fPIC -std=c99 -fopenmp -O2 -Wall %s -o %s -lm -lgomp"
CC = os.environ.get("CC", "cc")
- CPPFLAGS = os.environ.get("CPPFLAGS", "")
+ CPPFLAGS = os.environ.get("CPPFLAGS", f'-I"{MODEL_PATH}"')
CFLAGS = os.environ.get("CFLAGS", "-std=c99 -O2 -Wall")
LDFLAGS = os.environ.get("LDFLAGS", "")
SOFLAGS = "-fPIC -shared"
@@ -162,6 +162,7 @@ elif COMPILER == "msvc":
CC = "cl /nologo /Ox /MD /W3 /GS- /DNDEBUG".split()
if "SAS_OPENMP" in os.environ:
CC.append("/openmp")
+ CC.append(f'/I"{MODEL_PATH}"')
LN = "/link /DLL /INCREMENTAL:NO /MANIFEST".split()
def compile_command(source, output):
"""MSVC compiler command"""
@@ -175,6 +176,7 @@ elif COMPILER == "tinycc":
f"-L{tccbox.tcc_lib_dir()}",
f"-L{joinpath(tccbox.tcc_lib_dir(), 'tcc')}",
f"-I{tccbox.tcc_dist_dir()}/include",
+ f'-I"{MODEL_PATH}"',
"-shared",
"-rdynamic",
"-Wall",
@@ -187,6 +189,7 @@ elif COMPILER == "mingw":
CC = "gcc -shared -std=c99 -O2 -Wall".split()
if "SAS_OPENMP" in os.environ:
CC.append("-fopenmp")
+ CC.append(f'-I"{MODEL_PATH}"')
def compile_command(source, output):
"""mingw compiler command"""
return CC + [source, "-o", output, "-lm"]
It is possible to specify include directories for models whether they are compiled for cpu or gpu. See patch below.
The individual OpenCL implementations can be temperamental. For example, the apple opencl compiler does not accept
-I "path/to/models"with quotes around the path. Instead it needs spaces in the path escaped with a backslash.If we do this, though, we need to scan the sources for all files for the includes so that we can detect code changes that require recompile and so that we can convert double to float when running models in single precision. These updates are not included in the patch.