CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
123 lines
4.1 KiB
C++
123 lines
4.1 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <rocRoller/Expression.hpp>
|
|
#include <rocRoller/Expression_evaluate_detail.hpp>
|
|
|
|
namespace rocRoller::Expression::EvaluateDetail
|
|
{
|
|
template <>
|
|
struct OperationEvaluatorVisitor<AddShiftL>
|
|
{
|
|
CommandArgumentValue call(CommandArgumentValue const& lhs,
|
|
CommandArgumentValue const& r1hs,
|
|
CommandArgumentValue const& r2hs) const
|
|
{
|
|
auto sum = evaluateOp(Add{}, lhs, r1hs);
|
|
return evaluateOp(ShiftL{}, sum, r2hs);
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct OperationEvaluatorVisitor<ShiftLAdd>
|
|
{
|
|
CommandArgumentValue call(CommandArgumentValue const& lhs,
|
|
CommandArgumentValue const& r1hs,
|
|
CommandArgumentValue const& r2hs) const
|
|
{
|
|
auto temp = evaluateOp(ShiftL{}, lhs, r1hs);
|
|
return evaluateOp(Add{}, temp, r2hs);
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct OperationEvaluatorVisitor<MultiplyAdd>
|
|
{
|
|
CommandArgumentValue call(CommandArgumentValue const& lhs,
|
|
CommandArgumentValue const& r1hs,
|
|
CommandArgumentValue const& r2hs) const
|
|
{
|
|
auto product = evaluateOp(Multiply{}, lhs, r1hs);
|
|
return evaluateOp(Add{}, product, r2hs);
|
|
}
|
|
};
|
|
|
|
struct ToBoolVisitor
|
|
{
|
|
template <typename T>
|
|
constexpr bool operator()(T const& val)
|
|
{
|
|
Throw<FatalError>("Invalid bool type: ", typeName<T>());
|
|
return 0;
|
|
}
|
|
|
|
template <std::integral T>
|
|
constexpr bool operator()(T const& val)
|
|
{
|
|
return val != 0;
|
|
}
|
|
|
|
bool call(CommandArgumentValue const& val)
|
|
{
|
|
return std::visit(*this, val);
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct OperationEvaluatorVisitor<Conditional>
|
|
{
|
|
|
|
CommandArgumentValue call(CommandArgumentValue const& lhs,
|
|
CommandArgumentValue const& r1hs,
|
|
CommandArgumentValue const& r2hs) const
|
|
{
|
|
AssertFatal(r1hs.index() == r2hs.index(),
|
|
"Types of each conditional option must match!",
|
|
ShowValue(r1hs),
|
|
ShowValue(r2hs));
|
|
|
|
if(ToBoolVisitor().call(lhs))
|
|
{
|
|
return r1hs;
|
|
}
|
|
else
|
|
{
|
|
return r2hs;
|
|
}
|
|
}
|
|
};
|
|
|
|
template <>
|
|
struct OperationEvaluatorVisitor<MatrixMultiply>
|
|
{
|
|
CommandArgumentValue call(CommandArgumentValue const& lhs,
|
|
CommandArgumentValue const& r1hs,
|
|
CommandArgumentValue const& r2hs) const
|
|
{
|
|
Throw<FatalError>("Matrix multiply present in runtime expression.");
|
|
}
|
|
};
|
|
|
|
template <CTernary T>
|
|
__attribute__((noinline)) CommandArgumentValue evaluateOp(T const& op,
|
|
CommandArgumentValue const& lhs,
|
|
CommandArgumentValue const& r1hs,
|
|
CommandArgumentValue const& r2hs)
|
|
{
|
|
auto visitor = OperationEvaluatorVisitor<T>();
|
|
return visitor.call(lhs, r1hs, r2hs);
|
|
}
|
|
|
|
#define INSTANTIATE_TERNARY_OP(Op) \
|
|
template CommandArgumentValue evaluateOp<Op>(Op const& op, \
|
|
CommandArgumentValue const& lhs, \
|
|
CommandArgumentValue const& r1hs, \
|
|
CommandArgumentValue const& r2hs)
|
|
|
|
INSTANTIATE_TERNARY_OP(AddShiftL);
|
|
INSTANTIATE_TERNARY_OP(Conditional);
|
|
INSTANTIATE_TERNARY_OP(MatrixMultiply);
|
|
INSTANTIATE_TERNARY_OP(MultiplyAdd);
|
|
INSTANTIATE_TERNARY_OP(ShiftLAdd);
|
|
}
|