Compare commits
6 Commits
fix-compil
...
update-cud
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a10cad3dd | ||
|
|
2c2a59d6d6 | ||
|
|
a1f2dd6c4d | ||
|
|
3dcca92b79 | ||
|
|
8df4bbf54e | ||
|
|
716f323b26 |
@@ -7,5 +7,4 @@ repos:
|
|||||||
rev: v0.6.13
|
rev: v0.6.13
|
||||||
hooks:
|
hooks:
|
||||||
- id: cmake-format
|
- id: cmake-format
|
||||||
- id: cmake-lint
|
- id: cmake-lint
|
||||||
args: [--disabled-codes=C0301]
|
|
||||||
@@ -12,11 +12,6 @@ option(TRIGDX_BUILD_TESTS "Build tests" ON)
|
|||||||
option(TRIGDX_BUILD_BENCHMARKS "Build tests" ON)
|
option(TRIGDX_BUILD_BENCHMARKS "Build tests" ON)
|
||||||
option(TRIGDX_BUILD_PYTHON "Build Python interface" ON)
|
option(TRIGDX_BUILD_PYTHON "Build Python interface" ON)
|
||||||
|
|
||||||
# Add compiler flags
|
|
||||||
set(CMAKE_CXX_FLAGS
|
|
||||||
"${CMAKE_CXX_FLAGS} -Wall -Wnon-virtual-dtor -Wduplicated-branches -Wvla -Wpointer-arith -Wextra -Wno-unused-parameter"
|
|
||||||
)
|
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
|
||||||
configure_file(
|
configure_file(
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/cmake/trigdx_config.hpp.in
|
${CMAKE_CURRENT_SOURCE_DIR}/cmake/trigdx_config.hpp.in
|
||||||
|
|||||||
@@ -8,16 +8,5 @@ if(NOT pybind11_FOUND)
|
|||||||
FetchContent_MakeAvailable(pybind11)
|
FetchContent_MakeAvailable(pybind11)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Needed to set ${Python_VERSION_MAJOR} and ${Python_VERSION_MINOR}
|
|
||||||
find_package(Python REQUIRED)
|
|
||||||
|
|
||||||
pybind11_add_module(pytrigdx bindings.cpp)
|
pybind11_add_module(pytrigdx bindings.cpp)
|
||||||
target_link_libraries(pytrigdx PRIVATE trigdx)
|
target_link_libraries(pytrigdx PRIVATE trigdx)
|
||||||
set_target_properties(pytrigdx PROPERTIES OUTPUT_NAME "trigdx")
|
|
||||||
|
|
||||||
set(PYTHON_SITE_PACKAGES
|
|
||||||
"${CMAKE_INSTALL_LIBDIR}/python${Python_VERSION_MAJOR}.${Python_VERSION_MINOR}/site-packages/trigdx"
|
|
||||||
)
|
|
||||||
|
|
||||||
install(TARGETS pytrigdx DESTINATION ${PYTHON_SITE_PACKAGES})
|
|
||||||
install(FILES __init__.py DESTINATION ${PYTHON_SITE_PACKAGES})
|
|
||||||
|
|||||||
@@ -1,16 +0,0 @@
|
|||||||
from .trigdx import Reference, Lookup16K, Lookup32K, LookupAVX16K, LookupAVX32K
|
|
||||||
|
|
||||||
try:
|
|
||||||
from .trigdx import MKL
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
from .trigdx import GPU
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
from .trigdx import LookupXSIMD16K, LookupXSIMD32K
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
@@ -72,9 +72,7 @@ void bind_backend(py::module &m, const char *name) {
|
|||||||
.def("compute_sincosf", &compute_sincos<float>);
|
.def("compute_sincosf", &compute_sincos<float>);
|
||||||
}
|
}
|
||||||
|
|
||||||
PYBIND11_MODULE(trigdx, m) {
|
PYBIND11_MODULE(pytrigdx, m) {
|
||||||
m.doc() = "TrigDx python bindings";
|
|
||||||
|
|
||||||
py::class_<Backend, std::shared_ptr<Backend>>(m, "Backend")
|
py::class_<Backend, std::shared_ptr<Backend>>(m, "Backend")
|
||||||
.def("init", &Backend::init);
|
.def("init", &Backend::init);
|
||||||
|
|
||||||
@@ -93,4 +91,4 @@ PYBIND11_MODULE(trigdx, m) {
|
|||||||
bind_backend<LookupXSIMDBackend<16384>>(m, "LookupXSIMD16K");
|
bind_backend<LookupXSIMDBackend<16384>>(m, "LookupXSIMD16K");
|
||||||
bind_backend<LookupXSIMDBackend<32768>>(m, "LookupXSIMD32K");
|
bind_backend<LookupXSIMDBackend<32768>>(m, "LookupXSIMD32K");
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -20,8 +20,8 @@ template <std::size_t NR_SAMPLES> struct lookup_table {
|
|||||||
cos_values[i] = cosf(i * PI_FRAC);
|
cos_values[i] = cosf(i * PI_FRAC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::array<float, NR_SAMPLES> sin_values;
|
|
||||||
std::array<float, NR_SAMPLES> cos_values;
|
std::array<float, NR_SAMPLES> cos_values;
|
||||||
|
std::array<float, NR_SAMPLES> sin_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <std::size_t NR_SAMPLES> struct cosf_dispatcher {
|
template <std::size_t NR_SAMPLES> struct cosf_dispatcher {
|
||||||
@@ -33,6 +33,7 @@ template <std::size_t NR_SAMPLES> struct cosf_dispatcher {
|
|||||||
|
|
||||||
constexpr uint_fast32_t VL = b_type::size;
|
constexpr uint_fast32_t VL = b_type::size;
|
||||||
const uint_fast32_t VS = n - n % VL;
|
const uint_fast32_t VS = n - n % VL;
|
||||||
|
const uint_fast32_t Q_PI = NR_SAMPLES / 4U;
|
||||||
const b_type scale = b_type::broadcast(lookup_table_.SCALE);
|
const b_type scale = b_type::broadcast(lookup_table_.SCALE);
|
||||||
const b_type pi_frac = b_type::broadcast(lookup_table_.PI_FRAC);
|
const b_type pi_frac = b_type::broadcast(lookup_table_.PI_FRAC);
|
||||||
const m_type mask = m_type::broadcast(lookup_table_.MASK);
|
const m_type mask = m_type::broadcast(lookup_table_.MASK);
|
||||||
@@ -41,7 +42,7 @@ template <std::size_t NR_SAMPLES> struct cosf_dispatcher {
|
|||||||
const b_type term2 = b_type::broadcast(lookup_table_.TERM2); // 1/2!
|
const b_type term2 = b_type::broadcast(lookup_table_.TERM2); // 1/2!
|
||||||
const b_type term3 = b_type::broadcast(lookup_table_.TERM3); // 1/3!
|
const b_type term3 = b_type::broadcast(lookup_table_.TERM3); // 1/3!
|
||||||
const b_type term4 = b_type::broadcast(lookup_table_.TERM4); // 1/4!
|
const b_type term4 = b_type::broadcast(lookup_table_.TERM4); // 1/4!
|
||||||
|
const m_type quarter_pi = m_type::broadcast(Q_PI);
|
||||||
uint_fast32_t i;
|
uint_fast32_t i;
|
||||||
for (i = 0; i < VS; i += VL) {
|
for (i = 0; i < VS; i += VL) {
|
||||||
const b_type vx = b_type::load(a + i, Tag());
|
const b_type vx = b_type::load(a + i, Tag());
|
||||||
@@ -59,7 +60,7 @@ template <std::size_t NR_SAMPLES> struct cosf_dispatcher {
|
|||||||
const b_type dx4 = xsimd::mul(dx2, dx);
|
const b_type dx4 = xsimd::mul(dx2, dx);
|
||||||
const b_type t2 = xsimd::mul(dx2, term2);
|
const b_type t2 = xsimd::mul(dx2, term2);
|
||||||
const b_type t3 = xsimd::mul(dx3, term3);
|
const b_type t3 = xsimd::mul(dx3, term3);
|
||||||
const b_type t4 = xsimd::mul(dx4, term4);
|
const b_type t4 = xsimd::mul(dx4, term3);
|
||||||
|
|
||||||
const b_type cosdx = xsimd::add(xsimd::sub(term1, t2), t4);
|
const b_type cosdx = xsimd::add(xsimd::sub(term1, t2), t4);
|
||||||
|
|
||||||
@@ -97,6 +98,7 @@ template <std::size_t NR_SAMPLES> struct sinf_dispatcher {
|
|||||||
|
|
||||||
constexpr uint_fast32_t VL = b_type::size;
|
constexpr uint_fast32_t VL = b_type::size;
|
||||||
const uint_fast32_t VS = n - n % VL;
|
const uint_fast32_t VS = n - n % VL;
|
||||||
|
const uint_fast32_t Q_PI = NR_SAMPLES / 4U;
|
||||||
const b_type scale = b_type::broadcast(lookup_table_.SCALE);
|
const b_type scale = b_type::broadcast(lookup_table_.SCALE);
|
||||||
const b_type pi_frac = b_type::broadcast(lookup_table_.PI_FRAC);
|
const b_type pi_frac = b_type::broadcast(lookup_table_.PI_FRAC);
|
||||||
const m_type mask = m_type::broadcast(lookup_table_.MASK);
|
const m_type mask = m_type::broadcast(lookup_table_.MASK);
|
||||||
@@ -105,7 +107,7 @@ template <std::size_t NR_SAMPLES> struct sinf_dispatcher {
|
|||||||
const b_type term2 = b_type::broadcast(lookup_table_.TERM2); // 1/2!
|
const b_type term2 = b_type::broadcast(lookup_table_.TERM2); // 1/2!
|
||||||
const b_type term3 = b_type::broadcast(lookup_table_.TERM3); // 1/3!
|
const b_type term3 = b_type::broadcast(lookup_table_.TERM3); // 1/3!
|
||||||
const b_type term4 = b_type::broadcast(lookup_table_.TERM4); // 1/4!
|
const b_type term4 = b_type::broadcast(lookup_table_.TERM4); // 1/4!
|
||||||
|
const m_type quarter_pi = m_type::broadcast(Q_PI);
|
||||||
uint_fast32_t i;
|
uint_fast32_t i;
|
||||||
for (i = 0; i < VS; i += VL) {
|
for (i = 0; i < VS; i += VL) {
|
||||||
const b_type vx = b_type::load(a + i, Tag());
|
const b_type vx = b_type::load(a + i, Tag());
|
||||||
@@ -118,7 +120,7 @@ template <std::size_t NR_SAMPLES> struct sinf_dispatcher {
|
|||||||
const b_type dx4 = xsimd::mul(dx2, dx);
|
const b_type dx4 = xsimd::mul(dx2, dx);
|
||||||
const b_type t2 = xsimd::mul(dx2, term2);
|
const b_type t2 = xsimd::mul(dx2, term2);
|
||||||
const b_type t3 = xsimd::mul(dx3, term3);
|
const b_type t3 = xsimd::mul(dx3, term3);
|
||||||
const b_type t4 = xsimd::mul(dx4, term4);
|
const b_type t4 = xsimd::mul(dx4, term3);
|
||||||
|
|
||||||
const b_type cosdx = xsimd::add(xsimd::sub(term1, t2), t4);
|
const b_type cosdx = xsimd::add(xsimd::sub(term1, t2), t4);
|
||||||
const b_type sindx = xsimd::sub(dx, t3);
|
const b_type sindx = xsimd::sub(dx, t3);
|
||||||
@@ -158,6 +160,7 @@ template <std::size_t NR_SAMPLES> struct sin_cosf_dispatcher {
|
|||||||
|
|
||||||
constexpr uint_fast32_t VL = b_type::size;
|
constexpr uint_fast32_t VL = b_type::size;
|
||||||
const uint_fast32_t VS = n - n % VL;
|
const uint_fast32_t VS = n - n % VL;
|
||||||
|
const uint_fast32_t Q_PI = NR_SAMPLES / 4U;
|
||||||
const b_type scale = b_type::broadcast(lookup_table_.SCALE);
|
const b_type scale = b_type::broadcast(lookup_table_.SCALE);
|
||||||
const m_type mask = m_type::broadcast(lookup_table_.MASK);
|
const m_type mask = m_type::broadcast(lookup_table_.MASK);
|
||||||
const b_type pi_frac = b_type::broadcast(lookup_table_.PI_FRAC);
|
const b_type pi_frac = b_type::broadcast(lookup_table_.PI_FRAC);
|
||||||
@@ -167,6 +170,7 @@ template <std::size_t NR_SAMPLES> struct sin_cosf_dispatcher {
|
|||||||
const b_type term3 = b_type::broadcast(lookup_table_.TERM3); // 1/3!
|
const b_type term3 = b_type::broadcast(lookup_table_.TERM3); // 1/3!
|
||||||
const b_type term4 = b_type::broadcast(lookup_table_.TERM4); // 1/4!
|
const b_type term4 = b_type::broadcast(lookup_table_.TERM4); // 1/4!
|
||||||
|
|
||||||
|
const m_type quarter_pi = m_type::broadcast(Q_PI);
|
||||||
uint_fast32_t i;
|
uint_fast32_t i;
|
||||||
for (i = 0; i < VS; i += VL) {
|
for (i = 0; i < VS; i += VL) {
|
||||||
const b_type vx = b_type::load(a + i, Tag());
|
const b_type vx = b_type::load(a + i, Tag());
|
||||||
@@ -179,7 +183,7 @@ template <std::size_t NR_SAMPLES> struct sin_cosf_dispatcher {
|
|||||||
const b_type dx4 = xsimd::mul(dx2, dx);
|
const b_type dx4 = xsimd::mul(dx2, dx);
|
||||||
const b_type t2 = xsimd::mul(dx2, term2);
|
const b_type t2 = xsimd::mul(dx2, term2);
|
||||||
const b_type t3 = xsimd::mul(dx3, term3);
|
const b_type t3 = xsimd::mul(dx3, term3);
|
||||||
const b_type t4 = xsimd::mul(dx4, term4);
|
const b_type t4 = xsimd::mul(dx4, term3);
|
||||||
|
|
||||||
idx = xsimd::bitwise_and(idx, mask);
|
idx = xsimd::bitwise_and(idx, mask);
|
||||||
b_type sinv = b_type::gather(lookup_table_.sin_values.data(), idx);
|
b_type sinv = b_type::gather(lookup_table_.sin_values.data(), idx);
|
||||||
|
|||||||
Reference in New Issue
Block a user