Skip to content

Commit

Permalink
Fixes Apple build (#174)
Browse files Browse the repository at this point in the history
* fix apple

* fix env

* another try

* sse3 skip

* fix windows build

* fix build issue

* fix windows build
  • Loading branch information
xadupre authored May 20, 2024
1 parent 0ec74c0 commit 08d8766
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 6 deletions.
8 changes: 8 additions & 0 deletions _doc/api/validation_cpu.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ _validation

.. autofunction:: onnx_extended.validation.cpu._validation.benchmark_cache_tree

.. autofunction:: onnx_extended.validation.cpu._validation.double2float_rn

.. autofunction:: onnx_extended.validation.cpu._validation.murmurhash3_bytes_s32

.. autofunction:: onnx_extended.validation.cpu._validation.float2half_rn

.. autofunction:: onnx_extended.validation.cpu._validation.half2float

.. autofunction:: onnx_extended.validation.cpu._validation.has_sse3
6 changes: 6 additions & 0 deletions _unittests/ut_validation/test_cpu_fpemu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
using namespace cpu_fpemu;

void test_cast() {

#if defined(__SSSE3__)

float f = 1.f;
double d = 1.f;
float ff = __double2float_rn(d);
ASSERT_THROW(f == ff);
unsigned short u = __float2half_rn(f);
float bu = __half2float(u);
ASSERT_THROW(f == bu);

#endif

}

int main(int, char**) {
Expand Down
13 changes: 8 additions & 5 deletions _unittests/ut_validation/test_cpu_fpemu.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import unittest
from onnx_extended.ext_test_case import ExtTestCase
from onnx_extended.validation.cpu._validation import (
double2float_rn,
float2half_rn,
half2float,
)
from onnx_extended.validation.cpu._validation import has_sse3


class TestCpuFpEmu(ExtTestCase):
@unittest.skipIf(not has_sse3(), "SSE3 not available")
def test_cast(self):
from onnx_extended.validation.cpu._validation import (
double2float_rn,
float2half_rn,
half2float,
)

self.assertEqual(double2float_rn(1), 1)
self.assertEqual(half2float(float2half_rn(1)), 1)

Expand Down
16 changes: 16 additions & 0 deletions onnx_extended/validation/cpu/_validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ The code is `benchmark_cache_tree
:return: hash
)pbdoc");

#if defined(__SSSE3__)

m.def(
"has_sse3", []() -> bool { return true; },
R"pbdoc(Tells if SSE3 instructions are available.
They are needed to convert floart to half and half to float.)pbdoc");

m.def("double2float_rn", &cpu_fpemu::__double2float_rn, py::arg("d"),
R"pbdoc(Converts a double into float.)pbdoc");

Expand All @@ -96,6 +103,15 @@ The code is `benchmark_cache_tree
m.def("half2float", &cpu_fpemu::__half2float, py::arg("d"),
R"pbdoc(Converts a half represented as an unsigned short into float.)pbdoc");

#else

m.def(
"has_sse3", []() -> bool { return false; },
R"pbdoc(Tells if SSE3 instructions are available.
They are needed to convert floart to half and half to float.)pbdoc");

#endif

m.def("sparse_struct_to_dense", &sparse_struct_to_dense, py::arg("v"),
R"pbdoc(Converts a sparse structure stored in a float tensor
into a dense vector.)pbdoc");
Expand Down
8 changes: 8 additions & 0 deletions onnx_extended/validation/cpu/cpu_fpemu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@

#pragma once

#if defined(__SSSE3__)

#include <immintrin.h>

#endif

namespace cpu_fpemu {

#if defined(__SSSE3__)

inline float __double2float_rn(double inval) {
float out[4] = {0};
__m128 vout = _mm_cvtpd_ps(_mm_set1_pd(inval));
Expand Down Expand Up @@ -47,4 +53,6 @@ inline float __half2float(unsigned short h_val) { return _cvtsh_ss(h_val); }

#endif

#endif

} // namespace cpu_fpemu
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,17 @@ archs = ["x86_64"]
build = "cp*"
skip = "pypy* *musllinux* cp36-* cp37-* cp38-* cp39-* cp312-* cp313-* cp314-*"
manylinux-x86_64-image = "manylinux_2_28"
before-build = "pip install auditwheel-symbols abi3audit"
before-build = "pip install auditwheel-symbols abi3audit;python -c 'import sysconfig;print(sysconfig.get_platform())'"
build-verbosity = 1
repair-wheel-command = "auditwheel-symbols --manylinux 2_28 {wheel} ; abi3audit {wheel} ; auditwheel repair -w {dest_dir} {wheel} || exit 0"
test-command = "yum list installed&&python -m pip install onnxruntime&&python -c \"import onnx_extended;onnx_extended.check_installation(val=True,ortops=True)\"&&python -c \"import onnx_extended;onnx_extended.check_installation(val=True,ortcy=True,verbose=True)\""

[tool.cibuildwheel.macos]
archs = ["x86_64"]
build = "cp*"
before-build = "brew install llvm libomp"
skip = "pypy* pp* cp36-* cp37-* cp38-* cp39-* cp312-* cp313-* cp314-*"
# environment="LDFLAGS='-L/opt/homebrew/opt/llvm/lib -L/opt/homebrew/opt/libomp/lib' CPPFLAGS='-I/opt/homebrew/opt/llvm/include -I/opt/homebrew/opt/libomp/include'"

[tool.cibuildwheel.windows]
archs = ["AMD64"]
Expand Down

0 comments on commit 08d8766

Please sign in to comment.