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
144 lines
4.6 KiB
C++
144 lines
4.6 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <rocRoller/KernelGraph/Transforms/CleanArguments.hpp>
|
|
|
|
#include <rocRoller/AssemblyKernel.hpp>
|
|
#include <rocRoller/CommandSolution.hpp>
|
|
#include <rocRoller/Expression.hpp>
|
|
#include <rocRoller/ExpressionTransformations.hpp>
|
|
|
|
#include <rocRoller/KernelGraph/KernelGraph.hpp>
|
|
#include <rocRoller/KernelGraph/Visitors.hpp>
|
|
|
|
#include <rocRoller/Operations/Command.hpp>
|
|
|
|
namespace rocRoller
|
|
{
|
|
namespace KernelGraph
|
|
{
|
|
namespace Expression = rocRoller::Expression;
|
|
using namespace ControlGraph;
|
|
using namespace CoordinateGraph;
|
|
using namespace Expression;
|
|
|
|
/**
|
|
* Visitor for cleaning all of the Dimensions within a graph.
|
|
*/
|
|
struct CleanArgumentsVisitor
|
|
{
|
|
CleanArgumentsVisitor(KernelGraph const& graph, ContextPtr context, CommandPtr command)
|
|
: m_graph(graph)
|
|
, m_kernel(context->kernel())
|
|
, m_command(command)
|
|
, m_context(context)
|
|
{
|
|
}
|
|
|
|
ExpressionPtr cleanExpr(ExpressionPtr expr)
|
|
{
|
|
return FastArithmetic(m_context)(expr);
|
|
}
|
|
|
|
template <CCoordinateTransformEdge T>
|
|
rocRoller::KernelGraph::CoordinateGraph::Edge visitCoordinateEdge(int tag,
|
|
T const& edge)
|
|
{
|
|
return edge;
|
|
}
|
|
|
|
template <CDataFlowEdge T>
|
|
rocRoller::KernelGraph::CoordinateGraph::Edge visitCoordinateEdge(int tag,
|
|
T const& edge)
|
|
{
|
|
return edge;
|
|
}
|
|
|
|
template <CCoordinateTransformEdge Dim, Graph::Direction Dir>
|
|
bool hasConnectedDimension(int tag)
|
|
{
|
|
auto pred
|
|
= [this](int tag) { return m_graph.coordinates.get<Dim>(tag).has_value(); };
|
|
|
|
return !m_graph.coordinates.getNeighbours<Dir>(tag).filter(pred).empty();
|
|
}
|
|
|
|
template <CDimension T>
|
|
Dimension visitDimension(int tag, T const& dim)
|
|
{
|
|
auto d = dim;
|
|
|
|
d.size = cleanExpr(dim.size);
|
|
d.stride = cleanExpr(dim.stride);
|
|
d.offset = cleanExpr(dim.offset);
|
|
|
|
if constexpr(std::same_as<User, T>)
|
|
{
|
|
if(!m_kernel->hasArgument(dim.argumentName))
|
|
{
|
|
auto arg = findArgumentByName(m_command, dim.argumentName);
|
|
AssertFatal(arg, ShowValue(dim.argumentName));
|
|
|
|
m_kernel->addCommandArgument(arg);
|
|
}
|
|
}
|
|
|
|
return d;
|
|
}
|
|
|
|
Operation visitOperation(int tag, Assign const& op)
|
|
{
|
|
auto cleanOp = op;
|
|
cleanOp.expression = cleanExpr(op.expression);
|
|
return cleanOp;
|
|
}
|
|
|
|
Operation visitOperation(int tag, ConditionalOp const& op)
|
|
{
|
|
auto cleanOp = op;
|
|
cleanOp.condition = cleanExpr(op.condition);
|
|
return cleanOp;
|
|
}
|
|
|
|
Operation visitOperation(int tag, AssertOp const& op)
|
|
{
|
|
auto cleanOp = op;
|
|
cleanOp.condition = cleanExpr(op.condition);
|
|
return cleanOp;
|
|
}
|
|
|
|
Operation visitOperation(int tag, ForLoopOp const& op)
|
|
{
|
|
auto cleanOp = op;
|
|
cleanOp.condition = cleanExpr(op.condition);
|
|
return cleanOp;
|
|
}
|
|
|
|
template <COperation T>
|
|
Operation visitOperation(int tag, T const& op)
|
|
{
|
|
return op;
|
|
}
|
|
|
|
private:
|
|
KernelGraph const& m_graph;
|
|
AssemblyKernelPtr m_kernel;
|
|
CommandPtr m_command;
|
|
ContextPtr m_context;
|
|
};
|
|
static_assert(CCoordinateEdgeVisitor<CleanArgumentsVisitor>);
|
|
|
|
/**
|
|
* Rewrite HyperGraph to make sure no more CommandArgument
|
|
* values are present within the graph.
|
|
*/
|
|
KernelGraph CleanArguments::apply(KernelGraph const& k)
|
|
{
|
|
rocRoller::Log::getLogger()->debug("KernelGraph::cleanArguments()");
|
|
auto visitor = CleanArgumentsVisitor(k, m_context, m_command);
|
|
return rewriteDimensions(k, visitor);
|
|
}
|
|
|
|
}
|
|
}
|