Changes in / [4bfbca2:d5e0592] in sasmodels
- Location:
- sasmodels
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/generate.py
r558d3b3 ra7a5ff3 785 785 model_info = dict( 786 786 id=kernel_id, # string used to load the kernel 787 filename=abspath(kernel_module.__file__ ),787 filename=abspath(kernel_module.__file__.rstrip("cd")), 788 788 name=name, 789 789 title=kernel_module.title, -
sasmodels/kerneldll.py
r5efe850 r7e16db7 49 49 import os 50 50 from os.path import join as joinpath, split as splitpath, splitext 51 import subprocess 51 52 import tempfile 52 53 import ctypes as ct … … 63 64 # Windows compiler; check if TinyCC is available 64 65 try: 65 from tinycc import TCC66 import tinycc 66 67 except ImportError: 67 TCC= None68 tinycc = None 68 69 # call vcvarsall.bat before compiling to set path, headers, libs, etc. 69 70 if "VCINSTALLDIR" in os.environ: … … 75 76 # TODO: maybe don't use randomized name for the c file 76 77 # TODO: maybe ask distutils to find MSVC 77 CC = "cl /nologo /Ox /MD /W3 /GS- /DNDEBUG /Tp%(source)s " 78 LN = "/link /DLL /INCREMENTAL:NO /MANIFEST /OUT:%(output)s" 78 CC = "cl /nologo /Ox /MD /W3 /GS- /DNDEBUG".split() 79 79 if "SAS_OPENMP" in os.environ: 80 COMPILE = " ".join((CC, "/openmp", LN)) 81 else: 82 COMPILE = " ".join((CC, LN)) 83 elif TCC: 80 CC.append("/openmp") 81 LN = "/link /DLL /INCREMENTAL:NO /MANIFEST".split() 82 def compile_command(source, output): 83 return CC + ["/Tp%s"%source] + LN + ["/OUT:%s"%output] 84 elif tinycc: 84 85 # TinyCC compiler. 85 COMPILE = TCC + " -shared -rdynamic -Wall %(source)s -o %(output)s" 86 CC = [tinycc.find_tcc_path()] + "-shared -rdynamic -Wall".split() 87 def compile_command(source, output): 88 return CC + ["%s"%source, "-o", "%s"%output] 86 89 else: 87 90 # MinGW compiler. 88 C OMPILE = "gcc -shared -std=c99 -O2 -Wall %(source)s -o %(output)s -lm"91 CC = "gcc -shared -std=c99 -O2 -Wall".split() 89 92 if "SAS_OPENMP" in os.environ: 90 COMPILE += " -fopenmp" 93 CC.append("-fopenmp") 94 def compile_command(source, output): 95 return CC + ["%s"%source, "-o", "%s"%output, "-lm"] 91 96 else: 92 97 # Generic unix compile 93 98 # On mac users will need the X code command line tools installed 94 COMPILE = "cc -shared -fPIC -std=c99 -O2 -Wall %(source)s -o %(output)s -lm"95 99 #COMPILE = "gcc-mp-4.7 -shared -fPIC -std=c99 -fopenmp -O2 -Wall %s -o %s -lm -lgomp" 100 CC = "gcc -shared -fPIC -std=c99 -O2 -Wall".split() 96 101 # add openmp support if not running on a mac 97 if sys.platform != 'darwin': 98 #COMPILE = "gcc-mp-4.7 -shared -fPIC -std=c99 -fopenmp -O2 -Wall %s -o %s -lm -lgomp" 99 COMPILE += " -fopenmp" 102 if sys.platform != "darwin": 103 CC.append("-fopenmp") 104 def compile_command(source, output): 105 return CC + ["%s"%source, "-o", "%s"%output, "-lm"] 100 106 101 107 # Windows-specific solution … … 111 117 ALLOW_SINGLE_PRECISION_DLLS = True 112 118 119 def compile(source, output): 120 command = compile_command(source=source, output=output) 121 command_str = " ".join('"%s"'%p if ' ' in p else p for p in command) 122 logging.info(command_str) 123 try: 124 subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT) 125 except subprocess.CalledProcessError as exc: 126 raise RuntimeError("compile failed.\n%s\n%s"%(command_str, exc.output)) 127 if not os.path.exists(output): 128 raise RuntimeError("compile failed. File is in %r"%source) 113 129 114 130 def dll_path(model_info, dtype="double"): … … 180 196 need_recompile = dll_time < newest_source 181 197 if need_recompile: 182 fid, filename = tempfile.mkstemp(suffix=".c", prefix=tempfile_prefix)183 198 source = generate.convert_type(source, dtype) 184 os.fdopen(fid, "w").write(source) 185 command = COMPILE%{"source":filename, "output":dll} 186 logging.info(command) 187 status = os.system(command) 188 if status != 0 or not os.path.exists(dll): 189 raise RuntimeError("compile failed. File is in %r"%filename) 190 else: 191 ## comment the following to keep the generated c file 192 os.unlink(filename) 193 #print("saving compiled file in %r"%filename) 199 fd, filename = tempfile.mkstemp(suffix=".c", prefix=tempfile_prefix) 200 with os.fdopen(fd, "w") as file: 201 file.write(source) 202 compile(source=filename, output=dll) 203 # comment the following to keep the generated c file 204 # Note: if there is a syntax error then compile raises an error 205 # and the source file will not be deleted. 206 os.unlink(filename) 207 #print("saving compiled file in %r"%filename) 194 208 return dll 195 209
Note: See TracChangeset
for help on using the changeset viewer.