Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/marian-nmt/intgemm/intgemm.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2020-08-17 14:06:29 +0300
committerKenneth Heafield <github@kheafield.com>2020-08-17 14:06:29 +0300
commitdcaf2c8ed96041c08a2b7eb8572ed62e7a256162 (patch)
treeb8c5b1785a0d1532daf07d0d75f0f37ca5d332e8
parentfdbf2df226482f383c5e629bb588121dc5e1dfb6 (diff)
Use more modern C++ headers
-rw-r--r--aligned.h1
-rw-r--r--avx2_gemm.h1
-rw-r--r--avx512_gemm.h5
-rw-r--r--benchmarks/benchmark_quantizer.cc2
-rw-r--r--example.cc7
-rw-r--r--interleave.h1
-rw-r--r--intgemm.h2
-rw-r--r--intrinsics.h1
-rw-r--r--sse2_gemm.h1
-rw-r--r--ssse3_gemm.h1
-rw-r--r--stats.inl2
-rw-r--r--test/kernels/multiply_sat_test.cc1
-rw-r--r--test/kernels/multiply_test.cc1
-rw-r--r--test/kernels/relu_test.cc1
-rw-r--r--test/kernels/rescale_test.cc1
-rw-r--r--test/kernels/upcast_test.cc1
-rw-r--r--test/multiply_test.cc4
-rw-r--r--test/prepare_b_quantized_transposed.cc2
-rw-r--r--test/prepare_b_transposed.cc2
-rw-r--r--test/quantize_test.cc10
-rw-r--r--test/test.cc10
-rw-r--r--test/test.h8
22 files changed, 26 insertions, 39 deletions
diff --git a/aligned.h b/aligned.h
index 8ad7242..7500a8c 100644
--- a/aligned.h
+++ b/aligned.h
@@ -1,7 +1,6 @@
#pragma once
#include <cstdlib>
#include <new>
-#include <stdlib.h>
#ifdef _MSC_VER
#include <malloc.h>
#endif
diff --git a/avx2_gemm.h b/avx2_gemm.h
index a929361..469bc5b 100644
--- a/avx2_gemm.h
+++ b/avx2_gemm.h
@@ -6,7 +6,6 @@
#include "types.h"
#include <cstdint>
-#include <stdint.h>
#include <cstring>
namespace intgemm {
diff --git a/avx512_gemm.h b/avx512_gemm.h
index 1ad3929..0e9049c 100644
--- a/avx512_gemm.h
+++ b/avx512_gemm.h
@@ -12,10 +12,7 @@
#include <cassert>
#include <cstddef>
#include <cstdint>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
/* AVX512 implementation.
* This uses INTGEMM_AVX512BW, INTGEMM_AVX512DQ, and might use AVX512VL
diff --git a/benchmarks/benchmark_quantizer.cc b/benchmarks/benchmark_quantizer.cc
index 16bf67f..fa9e6f6 100644
--- a/benchmarks/benchmark_quantizer.cc
+++ b/benchmarks/benchmark_quantizer.cc
@@ -14,7 +14,7 @@ namespace {
float MaxAbsoluteBaseline(const float *begin, const float *end) {
auto res = std::minmax_element(begin, end);
- return std::max(fabsf(*res.first), fabsf(*res.second));
+ return std::max(std::fabs(*res.first), std::fabs(*res.second));
}
void BenchmarkMaxAbsolute() {
diff --git a/example.cc b/example.cc
index 292bd6b..6d8187a 100644
--- a/example.cc
+++ b/example.cc
@@ -5,7 +5,7 @@
#include "callbacks.h"
#include <cassert>
-#include <math.h>
+#include <cmath>
#include <random>
int main() {
@@ -54,7 +54,7 @@ int main() {
// Do the actual multiply.
intgemm::Int16::Multiply(A_prepared.begin(), B_prepared.begin(), A_rows, width, B_cols, intgemm::callbacks::UnquantizeAndWrite(1.0f / (quant_mult * quant_mult), C.begin()));
// Sanity check. C will be row major.
- assert(fabsf(C[0] - top_left_reference) < 0.05f);
+ assert(std::fabs(C[0] - top_left_reference) < 0.05f);
}
// 8-bit multiplication.
@@ -73,6 +73,7 @@ int main() {
// Do the actual multiply.
intgemm::Int8::Multiply(A_prepared.begin(), B_prepared.begin(), A_rows, width, B_cols, intgemm::callbacks::UnquantizeAndWrite(1.0f / (quant_mult * quant_mult), C.begin()));
// Sanity check. C will be row major.
- assert(fabsf(C[0] - top_left_reference) < 0.05f);
+ assert(std::fabs(C[0] - top_left_reference) < 0.05f);
}
+ return 0;
}
diff --git a/interleave.h b/interleave.h
index 7ca66bc..2fef188 100644
--- a/interleave.h
+++ b/interleave.h
@@ -6,7 +6,6 @@
#include <algorithm>
#include <cassert>
-#include <stdint.h>
namespace intgemm {
diff --git a/intgemm.h b/intgemm.h
index db7d2fe..07463c0 100644
--- a/intgemm.h
+++ b/intgemm.h
@@ -39,9 +39,7 @@
* passing unquant_mult = \lambda / (A_quant_mult * B_quant_mult).
*/
-// Yes, both headers due to the debacle about int32_t
#include <cstdint>
-#include <stdint.h>
#include "intgemm_config.h"
#include "types.h"
diff --git a/intrinsics.h b/intrinsics.h
index bf79e43..e302450 100644
--- a/intrinsics.h
+++ b/intrinsics.h
@@ -9,7 +9,6 @@
#include <xmmintrin.h>
#include <cstdint>
-#include <stdint.h>
/*
* NOTE: Please keep intrinsics in alphabetical order.
diff --git a/sse2_gemm.h b/sse2_gemm.h
index 69f6741..d77d467 100644
--- a/sse2_gemm.h
+++ b/sse2_gemm.h
@@ -5,7 +5,6 @@
#include "types.h"
#include <cstdint>
-#include <stdint.h>
// 8 bit is in ssse3_gemm.h
diff --git a/ssse3_gemm.h b/ssse3_gemm.h
index fd3ab8c..8242ad1 100644
--- a/ssse3_gemm.h
+++ b/ssse3_gemm.h
@@ -6,7 +6,6 @@
#include "types.h"
#include <cstdint>
-#include <stdint.h>
#include <cstring>
// 16-bit is in sse2_gemm.h
diff --git a/stats.inl b/stats.inl
index 7fc7afb..d6a850e 100644
--- a/stats.inl
+++ b/stats.inl
@@ -54,7 +54,7 @@ INTGEMM_TARGET static inline float MaxAbsolute(const float *begin_float, const f
}
#else
for (const float *i = end_reg; i < end_float; ++i) {
- ret = std::max(ret, fabsf(*i));
+ ret = std::max(ret, std::fabs(*i));
}
#endif
return ret;
diff --git a/test/kernels/multiply_sat_test.cc b/test/kernels/multiply_sat_test.cc
index 444eae4..1f7496d 100644
--- a/test/kernels/multiply_sat_test.cc
+++ b/test/kernels/multiply_sat_test.cc
@@ -2,7 +2,6 @@
#include "../../aligned.h"
#include "../../kernels.h"
-#include <stdint.h>
#include <cstdint>
#include <cstddef>
#include <numeric>
diff --git a/test/kernels/multiply_test.cc b/test/kernels/multiply_test.cc
index ca8c54c..c5fbdab 100644
--- a/test/kernels/multiply_test.cc
+++ b/test/kernels/multiply_test.cc
@@ -3,7 +3,6 @@
#include "../../kernels.h"
#include <cstdint>
-#include <stdint.h>
#include <numeric>
namespace intgemm {
diff --git a/test/kernels/relu_test.cc b/test/kernels/relu_test.cc
index 3ad6dd8..820902f 100644
--- a/test/kernels/relu_test.cc
+++ b/test/kernels/relu_test.cc
@@ -2,7 +2,6 @@
#include "../../aligned.h"
#include "../../kernels.h"
-#include <stdint.h>
#include <cstdint>
#include <numeric>
diff --git a/test/kernels/rescale_test.cc b/test/kernels/rescale_test.cc
index ae13984..0272903 100644
--- a/test/kernels/rescale_test.cc
+++ b/test/kernels/rescale_test.cc
@@ -3,7 +3,6 @@
#include "../../kernels.h"
#include <cstdint>
-#include <stdint.h>
#include <numeric>
namespace intgemm {
diff --git a/test/kernels/upcast_test.cc b/test/kernels/upcast_test.cc
index cc782b5..0be3a93 100644
--- a/test/kernels/upcast_test.cc
+++ b/test/kernels/upcast_test.cc
@@ -3,7 +3,6 @@
#include "../../kernels.h"
#include <cstdint>
-#include <stdint.h>
#include <numeric>
namespace intgemm {
diff --git a/test/multiply_test.cc b/test/multiply_test.cc
index a1138a0..2db6dd3 100644
--- a/test/multiply_test.cc
+++ b/test/multiply_test.cc
@@ -187,8 +187,8 @@ TEST_CASE("Max", "[max]") {
}
void CompareMaxAbs(const float *begin, const float *end, float test, std::size_t offset) {
- float largest = fabs(*std::max_element(begin, end));
- float smallest = fabs(*std::min_element(begin, end));
+ float largest = std::fabs(*std::max_element(begin, end));
+ float smallest = std::fabs(*std::min_element(begin, end));
largest = std::max(largest, smallest);
CHECK_MESSAGE(largest == test, "Error: " << largest << " versus " << test << " in length " << (end - begin) << " offset " << offset);
}
diff --git a/test/prepare_b_quantized_transposed.cc b/test/prepare_b_quantized_transposed.cc
index 938cc28..cb155ed 100644
--- a/test/prepare_b_quantized_transposed.cc
+++ b/test/prepare_b_quantized_transposed.cc
@@ -5,9 +5,9 @@
#include "../sse2_gemm.h"
#include "../ssse3_gemm.h"
+#include <cmath>
#include <cstring>
#include <iostream>
-#include <math.h>
namespace intgemm {
namespace {
diff --git a/test/prepare_b_transposed.cc b/test/prepare_b_transposed.cc
index 5969724..231205c 100644
--- a/test/prepare_b_transposed.cc
+++ b/test/prepare_b_transposed.cc
@@ -5,9 +5,9 @@
#include "../sse2_gemm.h"
#include "../ssse3_gemm.h"
+#include <cmath>
#include <cstring>
#include <iostream>
-#include <math.h>
namespace intgemm {
namespace {
diff --git a/test/quantize_test.cc b/test/quantize_test.cc
index d2f6304..2eb693f 100644
--- a/test/quantize_test.cc
+++ b/test/quantize_test.cc
@@ -6,9 +6,9 @@
#include "../ssse3_gemm.h"
#include "../stats.h"
+#include <cmath>
#include <cstring>
#include <iostream>
-#include <math.h>
namespace intgemm {
namespace {
@@ -61,8 +61,8 @@ void testVectorMeanStd(int num_items, bool absolute=false) {
MeanStd reference = VectorMeanStd(inputVec, num_items, absolute);
MeanStd fast = Backend(inputVec.begin(), inputVec.end(), absolute);
- float meanDifference = fabsf(reference.mean - fast.mean);
- float stdDifference = fabsf(reference.stddev - fast.stddev);
+ float meanDifference = std::fabs(reference.mean - fast.mean);
+ float stdDifference = std::fabs(reference.stddev - fast.stddev);
float eps = 0.00002f; //Accumulating horizontal sums can lead to errors.
CHECK_MESSAGE(meanDifference <= eps, "Items: " << num_items << " Absolute: " << absolute << " Reference mean: " << reference.mean << " actual: " << fast.mean);
@@ -73,8 +73,8 @@ void testVectorMeanStd(int num_items, bool absolute=false) {
template <class I> bool IsOff(float from, I ref, I test) {
if (ref == test) return false;
if (ref - test > 1 && test - ref > 1) return true;
- float off_test = fabs((float)test - from);
- float off_ref = fabs((float)ref - from);
+ float off_test = std::fabs(static_cast<float>(test) - from);
+ float off_ref = std::fabs(static_cast<float>(ref) - from);
// Allow 0.5 to round either way.
if (off_test > 0.49 && off_test < 0.51 && off_ref > 0.49 && off_ref < 0.51) return false;
return true;
diff --git a/test/test.cc b/test/test.cc
index 3559738..45c27ad 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -1,6 +1,8 @@
#define CATCH_CONFIG_RUNNER
#include "test.h"
+#include <cmath>
+
int main(int argc, char ** argv) {
return Catch::Session().run(argc, argv);
}
@@ -13,13 +15,13 @@ void CompareMSE(const float *float_ref, const float *int_ref, const float *int_t
for (std::size_t i = 0; i < size; ++i) {
float int_diff = int_ref[i] - int_test[i];
float float_diff = float_ref[i] - int_test[i];
- CHECK_MESSAGE(fabs(int_diff) <= int_tolerance, test_info << "Inaccurate compared to int reference at " << i << ' ' << int_ref[i] << ' ' << int_test[i]);
- CHECK_MESSAGE(fabs(float_diff) <= float_tolerance, test_info << "Inaccurate compared to float reference at " << i << ' ' << float_ref[i] << ' ' << int_test[i]);
+ CHECK_MESSAGE(std::fabs(int_diff) <= int_tolerance, test_info << "Inaccurate compared to int reference at " << i << ' ' << int_ref[i] << ' ' << int_test[i]);
+ CHECK_MESSAGE(std::fabs(float_diff) <= float_tolerance, test_info << "Inaccurate compared to float reference at " << i << ' ' << float_ref[i] << ' ' << int_test[i]);
int_sum += int_diff * int_diff;
float_sum += float_diff * float_diff;
}
- CHECK_MESSAGE(fabs(sqrt(float_sum / size)) <= MSE_float_tolerance, test_info << "Float MSE = " << sqrt(float_sum / size));
- CHECK_MESSAGE(fabs(sqrt(int_sum / size)) <= MSE_int_tolerance, test_info << "Int MSE = " << sqrt(int_sum / size));
+ CHECK_MESSAGE(std::fabs(sqrt(float_sum / size)) <= MSE_float_tolerance, test_info << "Float MSE = " << sqrt(float_sum / size));
+ CHECK_MESSAGE(std::fabs(sqrt(int_sum / size)) <= MSE_int_tolerance, test_info << "Int MSE = " << sqrt(int_sum / size));
}
} // namespace intgemm
diff --git a/test/test.h b/test/test.h
index f145681..d83132d 100644
--- a/test/test.h
+++ b/test/test.h
@@ -6,7 +6,7 @@
#include "../intgemm.h"
#include "../aligned.h"
-#include <math.h>
+#include <cmath>
#include <sstream>
#include <iostream>
#include <iomanip>
@@ -18,7 +18,7 @@
#define CHECK_EPS(actual, expected, epsilon) \
do { \
- if (fabs((actual) - (expected)) < epsilon) { SUCCEED(); } \
+ if (std::fabs((actual) - (expected)) < epsilon) { SUCCEED(); } \
else { CHECK((actual) == (expected)); } \
} while(0)
@@ -39,8 +39,8 @@ void CompareEps(const Type* reference, const Type* actual, Index size, Type epsi
for (Index i = 0; i < size; ++i) {
INFO("Inaccurate at " << i << ' ' << reference[i] << ' ' << actual[i]);
// Ratio to maximum value.
- float threshold = epsilon * std::max<float>(0.01f, fabsf(reference[i]));
- CHECK(fabsf(reference[i] - actual[i]) < threshold);
+ float threshold = epsilon * std::max<float>(0.01f, std::fabs(reference[i]));
+ CHECK(std::fabs(reference[i] - actual[i]) < threshold);
}
}