diff options
author | Kenneth Heafield <github@kheafield.com> | 2021-07-24 01:14:57 +0300 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2021-07-24 01:14:57 +0300 |
commit | e39842f7d1ba745b576056391c708b1dd763a058 (patch) | |
tree | 88fd751155a0d32d5553d416bfc63c4d1472293f | |
parent | 6228d016ecc63470d2dbb76bd4ab7b0abe097993 (diff) |
Support -fno-exceptions. Fixes #91
-rw-r--r-- | .github/workflows/ubuntu-noexceptions.yml | 25 | ||||
-rw-r--r-- | intgemm/aligned.h | 16 | ||||
-rw-r--r-- | intgemm/intgemm.cc | 15 | ||||
-rw-r--r-- | intgemm/intgemm.h | 34 |
4 files changed, 71 insertions, 19 deletions
diff --git a/.github/workflows/ubuntu-noexceptions.yml b/.github/workflows/ubuntu-noexceptions.yml new file mode 100644 index 0000000..ddbe216 --- /dev/null +++ b/.github/workflows/ubuntu-noexceptions.yml @@ -0,0 +1,25 @@ +name: Ubuntu + +on: + push: + branches: [master, static] + pull_request: + branches: [master, static] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: cmake + run: | + cmake -E make_directory build + cd build + cmake -DCMAKE_CXX_FLAGS=-fno-exceptions .. + - name: Compile + working-directory: build + run: cmake --build . -j2 + - name: Test + working-directory: build + run: ctest -j2 diff --git a/intgemm/aligned.h b/intgemm/aligned.h index 6fda369..112aeee 100644 --- a/intgemm/aligned.h +++ b/intgemm/aligned.h @@ -5,6 +5,10 @@ #include <malloc.h> #endif +#if defined(_MSC_VER) ? !defined(_HAS_EXCEPTIONS) : !defined(__EXCEPTIONS) +#include <cstdlib> +#endif + // Aligned simple vector. namespace intgemm { @@ -17,10 +21,20 @@ template <class T> class AlignedVector { : size_(size) { #ifdef _MSC_VER mem_ = static_cast<T*>(_aligned_malloc(size * sizeof(T), alignment)); - if (!mem_) throw std::bad_alloc(); + if (!mem_) { +# ifdef __EXCEPTIONS + throw std::bad_alloc(); +# else + std::abort(); +# endif + } #else if (posix_memalign(reinterpret_cast<void **>(&mem_), alignment, size * sizeof(T))) { +# ifdef __EXCEPTIONS throw std::bad_alloc(); +# else + std::abort(); +# endif } #endif } diff --git a/intgemm/intgemm.cc b/intgemm/intgemm.cc index 9b38e08..dfb54f3 100644 --- a/intgemm/intgemm.cc +++ b/intgemm/intgemm.cc @@ -105,12 +105,23 @@ CPUType GetCPUID() { const CPUType kCPU = GetCPUID(); -float Unsupported_MaxAbsolute(const float * /*begin*/, const float * /*end*/) { +void UnsupportedCPUError() { +#if defined(_MSC_VER) ? defined(_HAS_EXCEPTIONS) : defined(__EXCEPTIONS) throw UnsupportedCPU(); +#else + std::cerr << "intgemm does not support this CPU" << std::endl; + abort(); +#endif +} + +float Unsupported_MaxAbsolute(const float * /*begin*/, const float * /*end*/) { + UnsupportedCPUError(); + return 0.0f; } MeanStd Unsupported_VectorMeanStd(const float * /*begin*/, const float * /*end*/, bool /*absolute*/) { - throw UnsupportedCPU(); + UnsupportedCPUError(); + return MeanStd(); } void (*Int16::Quantize)(const float *input, int16_t *output, float quant_mult, Index size) = ChooseCPU(AVX512BW::Kernels16::Quantize, AVX512BW::Kernels16::Quantize, AVX2::Kernels16::Quantize, SSE2::Kernels16::Quantize, SSE2::Kernels16::Quantize, Unsupported_16bit::Quantize); diff --git a/intgemm/intgemm.h b/intgemm/intgemm.h index 977210d..bcd3be6 100644 --- a/intgemm/intgemm.h +++ b/intgemm/intgemm.h @@ -64,62 +64,64 @@ namespace intgemm { +void UnsupportedCPUError(); + struct Unsupported_16bit { static void Quantize(const float *, int16_t *, float, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void PrepareB(const float *, int16_t *, float, Index, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void PrepareBQuantizedTransposed(const int16_t *, int16_t *, Index, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void PrepareBTransposed(const float *, int16_t *, float, Index, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void SelectColumnsB(const int16_t *, int16_t *, Index, const Index *, const Index *) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } template <typename Callback> static void Multiply(const int16_t *, const int16_t *, Index, Index, Index, Callback) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } constexpr static const char *const kName = "16-bit Unsupported"; }; struct Unsupported_8bit { static void Quantize(const float *, int8_t *, float, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void QuantizeU(const float *, uint8_t *, float, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void PrepareA(const float *, int8_t *, float, Index, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void PrepareBQuantizedTransposed(const int8_t *, int8_t *, Index, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void PrepareBTransposed(const float *, int8_t *, float, Index, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void PrepareB(const float *, int8_t *, float, Index, Index) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } template<class Callback> static void PrepareBias(const int8_t *, Index, Index, Callback) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } static void SelectColumnsB(const int8_t *, int8_t *, Index, const Index *, const Index *) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } template <typename Callback> static void Multiply(const int8_t *, const int8_t *, Index, Index, Index, Callback) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } template<class Callback> static void Multiply8Shift(const uint8_t *, const int8_t *, Index, Index, Index, Callback) { - throw UnsupportedCPU(); + UnsupportedCPUError(); } constexpr static const char *const kName = "8-bit Unsupported"; |