/******************************************************************************* * * MIT License * * Copyright 2024-2025 AMD ROCm(TM) Software * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * *******************************************************************************/ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include class ContextFixture; namespace rocRoller { class Context : public std::enable_shared_from_this { public: Context(); ~Context(); static ContextPtr ForDefaultHipDevice(std::string const& kernelName, KernelOptions const& kernelOpts = {}); static ContextPtr ForHipDevice(int deviceIdx, std::string const& kernelName, KernelOptions const& kernelOpts = {}); static ContextPtr ForTarget(GPUArchitectureTarget const& arch, std::string const& kernelName, KernelOptions const& kernelOpts = {}); static ContextPtr ForTarget(GPUArchitecture const& arch, std::string const& kernelName, KernelOptions const& kernelOpts = {}); Scheduling::InstructionStatus peek(Instruction const& inst); void schedule(Instruction& inst); template void schedule(T const& insts); template void schedule(T&& insts); std::shared_ptr allocator(Register::Type registerType); Register::ValuePtr getM0(); Register::ValuePtr getVCC(); Register::ValuePtr getVCC_LO(); Register::ValuePtr getVCC_HI(); Register::ValuePtr getSCC(); Register::ValuePtr getExec(); Register::ValuePtr getTTMP7(); Register::ValuePtr getTTMP9(); Register::ValuePtr getSpecial(Register::Type t); std::shared_ptr observer() const; AssemblyKernelPtr kernel() const; std::shared_ptr argLoader() const; std::shared_ptr instructions() const; std::shared_ptr mem() const; std::shared_ptr copier() const; std::shared_ptr brancher() const; std::shared_ptr crasher() const; KernelOptions const& kernelOptions(); std::shared_ptr random() const; void setRandomSeed(int seed); std::string assemblyFileName() const; LabelAllocatorPtr labelAllocator() const; std::shared_ptr ldsAllocator() const; RegTagManPtr registerTagManager() const; GPUArchitecture const& targetArchitecture() const; int hipDeviceIndex() const; void setKernel(AssemblyKernelPtr); /** * @brief Returns an expression representing how much scratch space is required (in bytes) * * @return Expression::ExpressionPtr */ Expression::ExpressionPtr getScratchAmount() const; /** * @brief Allocate more scratch space * * @param size Number of bytes requested */ void allocateScratch(Expression::ExpressionPtr size); /** * @brief Get register scope manager. */ std::shared_ptr getScopeManager() const; /** * @brief Set register scope manager. */ void setScopeManager(std::shared_ptr); friend class ::ContextFixture; private: static ContextPtr Create(int deviceIndex, GPUArchitecture const& arch, std::string const& kernelName, KernelOptions const& kernelOpts); void scheduleCopy(Instruction const& inst); // If we are generating code for a real Hip device, refers to its // device index. int m_hipDeviceIdx = -1; GPUArchitecture m_targetArch; RegTagManPtr m_registerTagMan; std::array, static_cast(Register::Type::Count)> m_allocators; std::shared_ptr m_observer; AssemblyKernelPtr m_kernel; std::shared_ptr m_argLoader; std::shared_ptr m_instructions; std::shared_ptr m_mem; LabelAllocatorPtr m_labelAllocator; std::shared_ptr m_ldsAllocator; Expression::ExpressionPtr m_scratchAllocator; std::shared_ptr m_copier; std::shared_ptr m_brancher; std::shared_ptr m_crasher; std::shared_ptr m_random; std::shared_ptr m_scope; std::string m_assemblyFileName; KernelOptions m_kernelOptions; }; std::ostream& operator<<(std::ostream&, ContextPtr const&); } #include