Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use tccbox instead of tinycc #615

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
python -m pip install --upgrade pip
python -m pip install wheel setuptools
python -m pip install mako
python -m pip install numpy scipy matplotlib docutils pytest sphinx bumps==0.* unittest-xml-reporting tinycc siphash24
python -m pip install numpy scipy matplotlib docutils pytest sphinx bumps==0.* unittest-xml-reporting tccbox siphash24

- name: setup pyopencl on Linux + macOS
if: ${{ matrix.os != 'windows-latest' }}
Expand Down
22 changes: 2 additions & 20 deletions sasmodels/kernel_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,8 @@
#else // !__cplusplus
#include <inttypes.h> // C99 guarantees that int32_t types is here
#include <stdio.h>
#if defined(__TINYC__)
typedef int int32_t;
#include <math.h>
// TODO: check isnan is correct
inline double _isnan(double x) { return x != x; } // hope this doesn't optimize away!
#undef isnan
#define isnan(x) _isnan(x)
// Defeat the double->float conversion since we don't have tgmath
inline SAS_DOUBLE trunc(SAS_DOUBLE x) { return x>=0?floor(x):-floor(-x); }
inline SAS_DOUBLE fmin(SAS_DOUBLE x, SAS_DOUBLE y) { return x>y ? y : x; }
inline SAS_DOUBLE fmax(SAS_DOUBLE x, SAS_DOUBLE y) { return x<y ? y : x; }
#define NEED_ERF
#define NEED_EXPM1
#define NEED_TGAMMA
#define NEED_CBRT
// expf missing from windows?
#define expf exp
#else
#include <tgmath.h> // C99 type-generic math, so sin(float) => sinf
#endif
#define NEED_ERF
#include <tgmath.h> // C99 type-generic math, so sin(float) => sinf
// MSVC doesn't support C99, so no need for dllexport on C99 branch
#define kernel
#define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0)
Expand Down
22 changes: 17 additions & 5 deletions sasmodels/kerneldll.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@
import numpy as np # type: ignore

try:
import tinycc
import tccbox
except ImportError:
tinycc = None
tccbox = None

from . import generate
from .kernel import KernelModel, Kernel
Expand Down Expand Up @@ -112,7 +112,7 @@
if "SAS_COMPILER" in os.environ:
COMPILER = os.environ["SAS_COMPILER"]
elif os.name == 'nt':
if tinycc is not None:
if tccbox is not None:
COMPILER = "tinycc"
elif "VCINSTALLDIR" in os.environ:
# If vcvarsall.bat has been called, then VCINSTALLDIR is in the
Expand Down Expand Up @@ -147,6 +147,7 @@
pass
def compile_command(source, output):
"""unix compiler command"""
print(compiler + [source, "-o", output] + LIBS)
krzywon marked this conversation as resolved.
Show resolved Hide resolved
return compiler + [source, "-o", output] + LIBS
elif COMPILER == "msvc":
# Call vcvarsall.bat before compiling to set path, headers, libs, etc.
Expand All @@ -166,7 +167,18 @@ def compile_command(source, output):
return CC + ["/Tp%s"%source] + LN + ["/OUT:%s"%output]
elif COMPILER == "tinycc":
# TinyCC compiler.
CC = [tinycc.TCC] + "-shared -rdynamic -Wall".split()
include = tccbox.tcc_dist_dir()
krzywon marked this conversation as resolved.
Show resolved Hide resolved
CC = [
tccbox.tcc_bin_path(),
"-nostdinc",
"-std=c99",
f"-L{tccbox.tcc_lib_dir()}",
f"-L{joinpath(tccbox.tcc_lib_dir(), 'tcc')}",
f"-I{tccbox.tcc_dist_dir()}/include",
"-shared",
"-rdynamic",
"-Wall",
]
def compile_command(source, output):
"""tinycc compiler command"""
return CC + [source, "-o", output]
Expand Down Expand Up @@ -291,7 +303,7 @@ def make_dll(source, model_info, dtype=F64, system=False):
# Comment the following to keep the generated C file.
# Note: If there is a syntax error then compile raises an error
# and the source file will not be deleted.
os.unlink(filename)
# os.unlink(filename)
krzywon marked this conversation as resolved.
Show resolved Hide resolved
#print("saving compiled file in %r"%filename)
else:
logging.debug("make_dll: cache hit for %s", dll)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def find_version(package):
long_description = fid.read()

if sys.platform=='win32' or sys.platform=='cygwin':
install_requires.append('tinycc')
install_requires.append('tccbox')

setup(
name='sasmodels',
Expand Down
Loading