// Copyright Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT #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 #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 getEXECZ(); Register::ValuePtr getEXEC(); Register::ValuePtr getTTMP6(); 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 Allocate scratch space for the specified scratch policy. * * @param policy The scratch policy to allocate for * @param size Number of bytes requested * @return Expression::ExpressionPtr The offset before this allocation */ Expression::ExpressionPtr allocateScratch(Operations::ScratchPolicy policy, Expression::ExpressionPtr size); /** * @brief Returns an expression representing how much scratch space is required (in bytes) * for the specified scratch policy. * * @param policy The scratch policy to query * @return Expression::ExpressionPtr */ Expression::ExpressionPtr getScratchAmount(Operations::ScratchPolicy policy) const; /** * @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; std::array(Operations::ScratchPolicy::Count)> m_scratchSizes; 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