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
120 lines
4.0 KiB
C++
120 lines
4.0 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <rocRoller/AssemblyKernelArgument.hpp>
|
|
#include <rocRoller/CodeGen/ArgumentLoader.hpp>
|
|
#include <rocRoller/Context.hpp>
|
|
#include <rocRoller/Expression.hpp>
|
|
#include <rocRoller/ReplaceKernelArgs.hpp>
|
|
|
|
namespace rocRoller
|
|
{
|
|
namespace Expression
|
|
{
|
|
struct ReplaceKernelArgsVisitor
|
|
{
|
|
ReplaceKernelArgsVisitor(ContextPtr const& context)
|
|
: m_context(context)
|
|
{
|
|
}
|
|
|
|
Generator<Instruction> operator()(AssemblyKernelArgumentPtr const& expr)
|
|
{
|
|
auto iter = m_values.find(expr->getName());
|
|
if(iter != m_values.end())
|
|
{
|
|
m_lastResult = iter->second;
|
|
co_return;
|
|
}
|
|
|
|
Register::ValuePtr reg;
|
|
co_yield m_context->argLoader()->getValue(expr->getName(), reg);
|
|
|
|
auto exp = std::make_shared<Expression>(reg);
|
|
m_values[expr->getName()] = exp;
|
|
m_lastResult = exp;
|
|
}
|
|
|
|
template <CUnary T>
|
|
Generator<Instruction> operator()(T expr)
|
|
{
|
|
co_yield call(expr.arg);
|
|
m_lastResult = std::make_shared<Expression>(expr);
|
|
}
|
|
|
|
template <CBinary T>
|
|
Generator<Instruction> operator()(T expr)
|
|
{
|
|
co_yield call(expr.lhs);
|
|
co_yield call(expr.rhs);
|
|
m_lastResult = std::make_shared<Expression>(expr);
|
|
}
|
|
|
|
template <CTernary T>
|
|
Generator<Instruction> operator()(T expr)
|
|
{
|
|
co_yield call(expr.lhs);
|
|
co_yield call(expr.r1hs);
|
|
co_yield call(expr.r2hs);
|
|
m_lastResult = std::make_shared<Expression>(expr);
|
|
}
|
|
|
|
template <CNary T>
|
|
Generator<Instruction> operator()(T expr)
|
|
{
|
|
for(auto&& operand : expr.operands)
|
|
{
|
|
co_yield call(operand);
|
|
}
|
|
m_lastResult = std::make_shared<Expression>(std::move(expr));
|
|
}
|
|
|
|
Generator<Instruction> operator()(ScaledMatrixMultiply expr)
|
|
{
|
|
co_yield call(expr.matA);
|
|
co_yield call(expr.matB);
|
|
co_yield call(expr.matC);
|
|
co_yield call(expr.scaleA);
|
|
co_yield call(expr.scaleB);
|
|
m_lastResult = std::make_shared<Expression>(expr);
|
|
}
|
|
|
|
template <CIsAnyOf<CommandArgumentValue,
|
|
CommandArgumentPtr,
|
|
PositionalArgument,
|
|
Register::ValuePtr,
|
|
DataFlowTag,
|
|
WaveTilePtr> T>
|
|
Generator<Instruction> operator()(T expr)
|
|
{
|
|
m_lastResult = std::make_shared<Expression>(expr);
|
|
co_return;
|
|
}
|
|
|
|
Generator<Instruction> call(ExpressionPtr& dst, ExpressionPtr const& src)
|
|
{
|
|
co_yield std::visit(*this, *src);
|
|
dst = m_lastResult;
|
|
}
|
|
|
|
Generator<Instruction> call(ExpressionPtr& inout)
|
|
{
|
|
co_yield call(inout, inout);
|
|
}
|
|
|
|
private:
|
|
ContextPtr m_context;
|
|
std::map<std::string, ExpressionPtr> m_values;
|
|
ExpressionPtr m_lastResult = nullptr;
|
|
};
|
|
|
|
Generator<Instruction> replaceKernelArgs(ContextPtr const& context,
|
|
ExpressionPtr& dst,
|
|
ExpressionPtr const& src)
|
|
{
|
|
ReplaceKernelArgsVisitor visitor(context);
|
|
co_yield visitor.call(dst, src);
|
|
}
|
|
}
|
|
}
|