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
99 lines
3.8 KiB
C++
99 lines
3.8 KiB
C++
// Copyright Advanced Micro Devices, Inc., or its affiliates.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#pragma once
|
|
|
|
#include <rocRoller/Context.hpp>
|
|
#include <rocRoller/GPUArchitecture/GPUInstructionInfo.hpp>
|
|
#include <rocRoller/Scheduling/Scheduling.hpp>
|
|
|
|
namespace rocRoller
|
|
{
|
|
namespace Scheduling
|
|
{
|
|
class AllocatingObserver
|
|
{
|
|
public:
|
|
AllocatingObserver() {}
|
|
AllocatingObserver(ContextPtr context)
|
|
: m_context(context)
|
|
{
|
|
}
|
|
|
|
InstructionStatus peek(Instruction const& inst) const
|
|
{
|
|
auto ctx = m_context.lock();
|
|
InstructionStatus rv;
|
|
|
|
// Remaining registers after this instruction:
|
|
// currently remaining - newly allocated
|
|
for(int i = 0; i < static_cast<int>(Register::Type::Count); i++)
|
|
{
|
|
auto regType = static_cast<Register::Type>(i);
|
|
auto allocator = ctx->allocator(regType);
|
|
|
|
if(allocator)
|
|
rv.remainingRegisters[i] = allocator->currentlyFree();
|
|
}
|
|
|
|
for(auto alloc : inst.allocations())
|
|
{
|
|
if(alloc)
|
|
{
|
|
// Determine amount of new registers that will be allocated
|
|
|
|
auto regIdx = static_cast<size_t>(alloc->regType());
|
|
AssertFatal(regIdx < rv.allocatedRegisters.size(),
|
|
ShowValue(regIdx),
|
|
ShowValue(rv.allocatedRegisters.size()));
|
|
rv.allocatedRegisters.at(regIdx) += alloc->registerCount();
|
|
|
|
// Determine new highwater mark by simulating the allocation
|
|
|
|
auto allocator = ctx->allocator(alloc->regType());
|
|
auto const& arch = m_context.lock()->targetArchitecture();
|
|
auto newRegs
|
|
= allocator->findFree(alloc->registerCount(), alloc->options(), arch);
|
|
if(newRegs.size() > 0)
|
|
{
|
|
int myHWM = std::max(0, newRegs.back() - allocator->maxUsed());
|
|
|
|
AssertFatal(regIdx < rv.highWaterMarkRegistersDelta.size(),
|
|
ShowValue(regIdx),
|
|
ShowValue(rv.highWaterMarkRegistersDelta.size()));
|
|
rv.highWaterMarkRegistersDelta.at(regIdx)
|
|
= std::max(myHWM, rv.highWaterMarkRegistersDelta.at(regIdx));
|
|
}
|
|
|
|
rv.outOfRegisters.set(alloc->regType(),
|
|
rv.outOfRegisters[alloc->regType()]
|
|
|| alloc->registerCount() > 0 && newRegs.empty());
|
|
rv.remainingRegisters[regIdx] -= alloc->registerCount();
|
|
}
|
|
}
|
|
return rv;
|
|
}
|
|
|
|
//> Add any waitcnt or nop instructions needed before `inst` if it were to be scheduled now.
|
|
//> Throw an exception if it can't be scheduled now.
|
|
void modify(Instruction& inst) const
|
|
{
|
|
inst.allocateNow();
|
|
}
|
|
|
|
//> This instruction _will_ be scheduled now, record any side effects.
|
|
void observe(Instruction const& inst) {}
|
|
|
|
constexpr static bool required(GPUArchitectureTarget const& target)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
std::weak_ptr<Context> m_context;
|
|
};
|
|
|
|
static_assert(CObserverConst<AllocatingObserver>);
|
|
}
|
|
}
|