Skip to content

Commit

Permalink
[DAPHNE-daphne-eu#830] Fix duplicate symbol linker issue
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
corepointer committed Oct 6, 2024
1 parent 40ca523 commit 214234d
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 175 deletions.
95 changes: 0 additions & 95 deletions src/runtime/local/kernels/BinaryOpCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <BinaryOpCode op, typename VTRes, typename VTLhs, typename VTRhs>
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<BinaryOpCode::Op, VT, VT, VT> = 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<BinaryOpCode::CONCAT, const char *, const char *, const char *> = true;
template <> constexpr bool supportsBinaryOp<BinaryOpCode::EQ, int64_t, const char *, const char *> = 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
1 change: 0 additions & 1 deletion src/runtime/local/kernels/CUDA/EwBinaryMat.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <runtime/local/datastructures/DenseMatrix.h>
#include <runtime/local/datastructures/Matrix.h>
#include <runtime/local/kernels/BinaryOpCode.h>
#include <runtime/local/kernels/EwBinarySca.h>

#include <cstddef>
#include <string>
Expand Down
7 changes: 2 additions & 5 deletions src/runtime/local/kernels/EwBinarySca.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <runtime/local/context/DaphneContext.h>
#include <runtime/local/datastructures/ValueTypeUtils.h>
#include <runtime/local/kernels/BinaryOpCode.h>
#include <runtime/local/kernels/SupportedBinaryOpCodes.h>

#include <algorithm>
#include <stdexcept>
Expand Down Expand Up @@ -183,5 +182,3 @@ template <> struct EwBinarySca<BinaryOpCode::CONCAT, const char *, const char *,
};

#undef MAKE_EW_BINARY_SCA

#endif // SRC_RUNTIME_LOCAL_KERNELS_EWBINARYSCA_H
6 changes: 2 additions & 4 deletions src/runtime/local/kernels/EwUnarySca.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* limitations under the License.
*/

#ifndef SRC_RUNTIME_LOCAL_KERNELS_EWUNARYSCA_H
#define SRC_RUNTIME_LOCAL_KERNELS_EWUNARYSCA_H
#pragma once

#include <runtime/local/context/DaphneContext.h>
#include <runtime/local/datastructures/ValueTypeUtils.h>
#include <runtime/local/kernels/UnaryOpCode.h>
#include <runtime/local/kernels/SupportedUnaryOpCodes.h>

#include <limits>
#include <sstream>
Expand Down Expand Up @@ -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
115 changes: 115 additions & 0 deletions src/runtime/local/kernels/SupportedBinaryOpCodes.h
Original file line number Diff line number Diff line change
@@ -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 <runtime/local/kernels/BinaryOpCode.h>

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 <BinaryOpCode op, typename VTRes, typename VTLhs, typename VTRhs> 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<BinaryOpCode::Op, VT, VT, VT> = 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<BinaryOpCode::CONCAT, const char *, const char *, const char *> = true;
template <> constexpr bool supportsBinaryOp<BinaryOpCode::EQ, int64_t, const char *, const char *> = 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
}
87 changes: 87 additions & 0 deletions src/runtime/local/kernels/SupportedUnaryOpCodes.h
Original file line number Diff line number Diff line change
@@ -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 <runtime/local/kernels/UnaryOpCode.h>

#include <cstdint>

// ****************************************************************************
// 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 <UnaryOpCode op, typename VTRes, typename VTArg> 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<UnaryOpCode::Op, VT, VT> = 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
}
Loading

0 comments on commit 214234d

Please sign in to comment.