From ffa28b85988b5b52c99e91d91cbd35f9b40b279e Mon Sep 17 00:00:00 2001 From: Mark Dokter Date: Tue, 24 Sep 2024 17:14:44 +0200 Subject: [PATCH] [DAPHNE-#830] Fix duplicate symbol linker issue Compiling with Clang/LLD complains about duplicate symbols of supportsUnaryOp and supportsBinaryOp. The definition of supportsBinaryOp would need to be declared static if left i the BinaryOpCode.h header which is included in several places. Since this definition is not allowed and there is only one use, it is moved to its own file. --- src/runtime/local/kernels/BinaryOpCode.h | 95 --------------- src/runtime/local/kernels/CUDA/EwBinaryMat.h | 1 - src/runtime/local/kernels/EwBinarySca.h | 7 +- src/runtime/local/kernels/EwUnarySca.h | 6 +- .../local/kernels/SupportedBinaryOpCodes.h | 115 ++++++++++++++++++ .../local/kernels/SupportedUnaryOpCodes.h | 87 +++++++++++++ src/runtime/local/kernels/UnaryOpCode.h | 70 ----------- 7 files changed, 206 insertions(+), 175 deletions(-) create mode 100644 src/runtime/local/kernels/SupportedBinaryOpCodes.h create mode 100644 src/runtime/local/kernels/SupportedUnaryOpCodes.h diff --git a/src/runtime/local/kernels/BinaryOpCode.h b/src/runtime/local/kernels/BinaryOpCode.h index ad2db6642..3f7194775 100644 --- a/src/runtime/local/kernels/BinaryOpCode.h +++ b/src/runtime/local/kernels/BinaryOpCode.h @@ -68,98 +68,3 @@ static std::string_view binary_op_codes[] = { "BITWISE_AND", // Strings. "CONCAT"}; - -// **************************************************************************** -// Specification which binary ops should be supported on which value types -// **************************************************************************** - -/** - * @brief Template constant specifying if the given binary operation - * should be supported on arguments of the given value types. - * - * @tparam VTRes The result value type. - * @tparam VTLhs The left-hand-side argument value type. - * @tparam VTRhs The right-hand-side argument value type. - * @tparam op The binary operation. - */ -template -static constexpr bool supportsBinaryOp = false; - -// Macros for concisely specifying which binary operations should be -// supported on which value types. - -// Generates code specifying that the binary operation `Op` should be supported -// on the value type `VT` (for the result and the two arguments, for -// simplicity). -#define SUPPORT(Op, VT) template <> constexpr bool supportsBinaryOp = true; - -// Generates code specifying that all binary operations of a certain category -// should be supported on the given value type `VT` (for the result and the two -// arguments, for simplicity). -#define SUPPORT_ARITHMETIC(VT) \ - /* Arithmetic. */ \ - SUPPORT(ADD, VT) \ - SUPPORT(SUB, VT) \ - SUPPORT(MUL, VT) \ - SUPPORT(DIV, VT) \ - SUPPORT(POW, VT) \ - SUPPORT(MOD, VT) \ - SUPPORT(LOG, VT) -#define SUPPORT_EQUALITY(VT) \ - /* Comparisons. */ \ - SUPPORT(EQ, VT) \ - SUPPORT(NEQ, VT) -#define SUPPORT_COMPARISONS(VT) \ - /* Comparisons. */ \ - SUPPORT(LT, VT) \ - SUPPORT(LE, VT) \ - SUPPORT(GT, VT) \ - SUPPORT(GE, VT) \ - /* Min/max. */ \ - SUPPORT(MIN, VT) \ - SUPPORT(MAX, VT) -#define SUPPORT_LOGICAL(VT) \ - /* Logical. */ \ - SUPPORT(AND, VT) \ - SUPPORT(OR, VT) -#define SUPPORT_BITWISE(VT) \ - /* Bitwise. */ \ - SUPPORT(BITWISE_AND, VT) - -// Generates code specifying that all binary operations typically supported on a -// certain category of value types should be supported on the given value type -// `VT` (for the result and the two arguments, for simplicity). -#define SUPPORT_NUMERIC_FP(VT) \ - SUPPORT_ARITHMETIC(VT) \ - SUPPORT_EQUALITY(VT) \ - SUPPORT_COMPARISONS(VT) \ - SUPPORT_LOGICAL(VT) -#define SUPPORT_NUMERIC_INT(VT) \ - SUPPORT_ARITHMETIC(VT) \ - SUPPORT_EQUALITY(VT) \ - SUPPORT_COMPARISONS(VT) \ - SUPPORT_LOGICAL(VT) \ - SUPPORT_BITWISE(VT) - -// Concise specification of which binary operations should be supported on -// which value types. -SUPPORT_NUMERIC_FP(double) -SUPPORT_NUMERIC_FP(float) -SUPPORT_NUMERIC_INT(int64_t) -SUPPORT_NUMERIC_INT(int32_t) -SUPPORT_NUMERIC_INT(int8_t) -SUPPORT_NUMERIC_INT(uint64_t) -SUPPORT_NUMERIC_INT(uint32_t) -SUPPORT_NUMERIC_INT(uint8_t) -template <> constexpr bool supportsBinaryOp = true; -template <> constexpr bool supportsBinaryOp = true; - -// Undefine helper macros. -#undef SUPPORT -#undef SUPPORT_ARITHMETIC -#undef SUPPORT_EQUALITY -#undef SUPPORT_COMPARISONS -#undef SUPPORT_LOGICAL -#undef SUPPORT_BITWISE -#undef SUPPORT_NUMERIC_FP -#undef SUPPORT_NUMERIC_INT diff --git a/src/runtime/local/kernels/CUDA/EwBinaryMat.h b/src/runtime/local/kernels/CUDA/EwBinaryMat.h index 8af182cef..1b44ce48d 100644 --- a/src/runtime/local/kernels/CUDA/EwBinaryMat.h +++ b/src/runtime/local/kernels/CUDA/EwBinaryMat.h @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/src/runtime/local/kernels/EwBinarySca.h b/src/runtime/local/kernels/EwBinarySca.h index 0fa1768db..3dc67ccee 100644 --- a/src/runtime/local/kernels/EwBinarySca.h +++ b/src/runtime/local/kernels/EwBinarySca.h @@ -14,12 +14,11 @@ * limitations under the License. */ -#ifndef SRC_RUNTIME_LOCAL_KERNELS_EWBINARYSCA_H -#define SRC_RUNTIME_LOCAL_KERNELS_EWBINARYSCA_H +#pragma once #include #include -#include +#include #include #include @@ -183,5 +182,3 @@ template <> struct EwBinarySca #include #include +#include #include #include @@ -182,5 +182,3 @@ MAKE_EW_UNARY_SCA(UnaryOpCode::ISNAN, std::isnan(arg)); #undef MAKE_EW_UNARY_SCA_CLOSED_DOMAIN_ERROR #undef MAKE_EW_UNARY_SCA_OPEN_DOMAIN_ERROR #undef MAKE_EW_UNARY_SCA - -#endif // SRC_RUNTIME_LOCAL_KERNELS_EWUNARYSCA_H \ No newline at end of file diff --git a/src/runtime/local/kernels/SupportedBinaryOpCodes.h b/src/runtime/local/kernels/SupportedBinaryOpCodes.h new file mode 100644 index 000000000..707057eb4 --- /dev/null +++ b/src/runtime/local/kernels/SupportedBinaryOpCodes.h @@ -0,0 +1,115 @@ +/* +* Copyright 2024 The DAPHNE Consortium +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#pragma once + +#include + +namespace { +// **************************************************************************** +// Specification which binary ops should be supported on which value types +// **************************************************************************** + +/** + * @brief Template constant specifying if the given binary operation + * should be supported on arguments of the given value types. + * + * @tparam VTRes The result value type. + * @tparam VTLhs The left-hand-side argument value type. + * @tparam VTRhs The right-hand-side argument value type. + * @tparam op The binary operation. + */ +template constexpr bool supportsBinaryOp = false; + +// Macros for concisely specifying which binary operations should be +// supported on which value types. + +// Generates code specifying that the binary operation `Op` should be supported +// on the value type `VT` (for the result and the two arguments, for +// simplicity). +#define SUPPORT(Op, VT) template <> constexpr bool supportsBinaryOp = true; + +// Generates code specifying that all binary operations of a certain category +// should be supported on the given value type `VT` (for the result and the two +// arguments, for simplicity). +#define SUPPORT_ARITHMETIC(VT) \ + /* Arithmetic. */ \ + SUPPORT(ADD, VT) \ + SUPPORT(SUB, VT) \ + SUPPORT(MUL, VT) \ + SUPPORT(DIV, VT) \ + SUPPORT(POW, VT) \ + SUPPORT(MOD, VT) \ + SUPPORT(LOG, VT) +#define SUPPORT_EQUALITY(VT) \ + /* Comparisons. */ \ + SUPPORT(EQ, VT) \ + SUPPORT(NEQ, VT) +#define SUPPORT_COMPARISONS(VT) \ + /* Comparisons. */ \ + SUPPORT(LT, VT) \ + SUPPORT(LE, VT) \ + SUPPORT(GT, VT) \ + SUPPORT(GE, VT) \ + /* Min/max. */ \ + SUPPORT(MIN, VT) \ + SUPPORT(MAX, VT) +#define SUPPORT_LOGICAL(VT) \ + /* Logical. */ \ + SUPPORT(AND, VT) \ + SUPPORT(OR, VT) +#define SUPPORT_BITWISE(VT) \ + /* Bitwise. */ \ + SUPPORT(BITWISE_AND, VT) + +// Generates code specifying that all binary operations typically supported on a +// certain category of value types should be supported on the given value type +// `VT` (for the result and the two arguments, for simplicity). +#define SUPPORT_NUMERIC_FP(VT) \ + SUPPORT_ARITHMETIC(VT) \ + SUPPORT_EQUALITY(VT) \ + SUPPORT_COMPARISONS(VT) \ + SUPPORT_LOGICAL(VT) +#define SUPPORT_NUMERIC_INT(VT) \ + SUPPORT_ARITHMETIC(VT) \ + SUPPORT_EQUALITY(VT) \ + SUPPORT_COMPARISONS(VT) \ + SUPPORT_LOGICAL(VT) \ + SUPPORT_BITWISE(VT) + +// Concise specification of which binary operations should be supported on +// which value types. +SUPPORT_NUMERIC_FP(double) +SUPPORT_NUMERIC_FP(float) +SUPPORT_NUMERIC_INT(int64_t) +SUPPORT_NUMERIC_INT(int32_t) +SUPPORT_NUMERIC_INT(int8_t) +SUPPORT_NUMERIC_INT(uint64_t) +SUPPORT_NUMERIC_INT(uint32_t) +SUPPORT_NUMERIC_INT(uint8_t) +template <> constexpr bool supportsBinaryOp = true; +template <> constexpr bool supportsBinaryOp = true; + +// Undefine helper macros. +#undef SUPPORT +#undef SUPPORT_ARITHMETIC +#undef SUPPORT_EQUALITY +#undef SUPPORT_COMPARISONS +#undef SUPPORT_LOGICAL +#undef SUPPORT_BITWISE +#undef SUPPORT_NUMERIC_FP +#undef SUPPORT_NUMERIC_INT +} \ No newline at end of file diff --git a/src/runtime/local/kernels/SupportedUnaryOpCodes.h b/src/runtime/local/kernels/SupportedUnaryOpCodes.h new file mode 100644 index 000000000..79116021e --- /dev/null +++ b/src/runtime/local/kernels/SupportedUnaryOpCodes.h @@ -0,0 +1,87 @@ +/* +* Copyright 2024 The DAPHNE Consortium +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. + */ + +#pragma once + +#include + +#include + +// **************************************************************************** +// Specification which unary ops should be supported on which value types +// **************************************************************************** +namespace { +/** + * @brief Template constant specifying if the given unary operation + * should be supported on arguments of the given value type. + * + * @tparam op The unary operation. + * @tparam VTRes The result value type. + * @tparam VTArg The argument value type. + */ +template constexpr bool supportsUnaryOp = false; + +// Macros for concisely specifying which unary operations should be +// supported on which value types. + +// Generates code specifying that the unary operation `Op` should be supported +// on the value type `VT` (for both the result and the argument, for +// simplicity). +#define SUPPORT(Op, VT) template <> constexpr bool supportsUnaryOp = true; + +// Generates code specifying that all unary operations typically supported on +// numeric value types should be supported on the given value type `VT` +// (for both the result and the argument, for simplicity). +#define SUPPORT_NUMERIC(VT) \ + /* Arithmetic/general math. */ \ + SUPPORT(MINUS, VT) \ + SUPPORT(ABS, VT) \ + SUPPORT(SIGN, VT) \ + SUPPORT(SQRT, VT) \ + SUPPORT(EXP, VT) \ + SUPPORT(LN, VT) \ + /* Trigonometric/hyperbolic. */ \ + SUPPORT(SIN, VT) \ + SUPPORT(COS, VT) \ + SUPPORT(TAN, VT) \ + SUPPORT(ASIN, VT) \ + SUPPORT(ACOS, VT) \ + SUPPORT(ATAN, VT) \ + SUPPORT(SINH, VT) \ + SUPPORT(COSH, VT) \ + SUPPORT(TANH, VT) \ + /* Rounding. */ \ + SUPPORT(FLOOR, VT) \ + SUPPORT(CEIL, VT) \ + SUPPORT(ROUND, VT) \ + /* Comparison */ \ + SUPPORT(ISNAN, VT) + +// Concise specification of which unary operations should be supported on +// which value types. +SUPPORT_NUMERIC(double) +SUPPORT_NUMERIC(float) +SUPPORT_NUMERIC(int64_t) +SUPPORT_NUMERIC(int32_t) +SUPPORT_NUMERIC(int8_t) +SUPPORT_NUMERIC(uint64_t) +SUPPORT_NUMERIC(uint32_t) +SUPPORT_NUMERIC(uint8_t) + +// Undefine helper macros. +#undef SUPPORT +#undef SUPPORT_NUMERIC +} \ No newline at end of file diff --git a/src/runtime/local/kernels/UnaryOpCode.h b/src/runtime/local/kernels/UnaryOpCode.h index 9a327b94b..22528ea07 100644 --- a/src/runtime/local/kernels/UnaryOpCode.h +++ b/src/runtime/local/kernels/UnaryOpCode.h @@ -14,9 +14,6 @@ * limitations under the License. */ -#ifndef SRC_RUNTIME_LOCAL_KERNELS_UNARYOPCODE_H -#define SRC_RUNTIME_LOCAL_KERNELS_UNARYOPCODE_H - #pragma once // **************************************************************************** @@ -65,70 +62,3 @@ static std::string_view unary_op_codes[] = { "FLOOR", "CEIL", "ROUND", // Comparison. "ISNAN"}; - -// **************************************************************************** -// Specification which unary ops should be supported on which value types -// **************************************************************************** - -/** - * @brief Template constant specifying if the given unary operation - * should be supported on arguments of the given value type. - * - * @tparam op The unary operation. - * @tparam VTRes The result value type. - * @tparam VTArg The argument value type. - */ -template static constexpr bool supportsUnaryOp = false; - -// Macros for concisely specifying which unary operations should be -// supported on which value types. - -// Generates code specifying that the unary operation `Op` should be supported -// on the value type `VT` (for both the result and the argument, for -// simplicity). -#define SUPPORT(Op, VT) template <> constexpr bool supportsUnaryOp = true; - -// Generates code specifying that all unary operations typically supported on -// numeric value types should be supported on the given value type `VT` -// (for both the result and the argument, for simplicity). -#define SUPPORT_NUMERIC(VT) \ - /* Arithmetic/general math. */ \ - SUPPORT(MINUS, VT) \ - SUPPORT(ABS, VT) \ - SUPPORT(SIGN, VT) \ - SUPPORT(SQRT, VT) \ - SUPPORT(EXP, VT) \ - SUPPORT(LN, VT) \ - /* Trigonometric/hyperbolic. */ \ - SUPPORT(SIN, VT) \ - SUPPORT(COS, VT) \ - SUPPORT(TAN, VT) \ - SUPPORT(ASIN, VT) \ - SUPPORT(ACOS, VT) \ - SUPPORT(ATAN, VT) \ - SUPPORT(SINH, VT) \ - SUPPORT(COSH, VT) \ - SUPPORT(TANH, VT) \ - /* Rounding. */ \ - SUPPORT(FLOOR, VT) \ - SUPPORT(CEIL, VT) \ - SUPPORT(ROUND, VT) \ - /* Comparison */ \ - SUPPORT(ISNAN, VT) - -// Concise specification of which unary operations should be supported on -// which value types. -SUPPORT_NUMERIC(double) -SUPPORT_NUMERIC(float) -SUPPORT_NUMERIC(int64_t) -SUPPORT_NUMERIC(int32_t) -SUPPORT_NUMERIC(int8_t) -SUPPORT_NUMERIC(uint64_t) -SUPPORT_NUMERIC(uint32_t) -SUPPORT_NUMERIC(uint8_t) - -// Undefine helper macros. -#undef SUPPORT -#undef SUPPORT_NUMERIC - -#endif // SRC_RUNTIME_LOCAL_KERNELS_UNARYOPCODE_H