// Copyright Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT /** */ #pragma once #include #include #include #include #include #include #include #include #include #include namespace rocRoller { struct Command : public std::enable_shared_from_this { public: using OperationList = std::vector>; Command(); explicit Command(bool sync); ~Command(); Command(Command const& rhs); Command(Command&& rhs); Operations::OperationTag addOperation(std::shared_ptr op); template Operations::OperationTag addOperation(T&& op); CommandArgumentPtr allocateArgument(VariableType variableType, Operations::OperationTag const&, ArgumentType argType, DataDirection direction = DataDirection::ReadWrite); CommandArgumentPtr allocateArgument(VariableType variableType, Operations::OperationTag const&, ArgumentType argType, DataDirection direction, std::string const& name); std::vector allocateArgumentVector(DataType dataType, int length, Operations::OperationTag const& tag, ArgumentType argType, DataDirection direction = DataDirection::ReadWrite); std::vector allocateArgumentVector(DataType dataType, int length, Operations::OperationTag const& tag, ArgumentType argType, DataDirection direction, std::string const& name); std::shared_ptr findTag(Operations::OperationTag const& tag) const; template T getOperation(Operations::OperationTag const& tag) const; Operations::OperationTag getNextTag() const; Operations::OperationTag allocateTag(); OperationList const& operations() const; std::string toString() const; std::string toString(const unsigned char*) const; std::string argInfo() const; /** * Returns a list of all of the CommandArguments within a Command. */ std::vector getArguments() const; /** * NOTE: Debugging & testing purposes only. * * Reads the values of each of the command arguments out of `args` and returns them in * a map based on the name of each argument. */ std::map readArguments(RuntimeArguments const& args) const; /** * Returns the expected workItemCount for a command. * This is determined by finding the sizes for the first T_LOAD_LINEAR * command appearing in the command object. */ std::array createWorkItemCount() const; CommandArguments createArguments() const; static std::string toYAML(Command const&); static Command fromYAML(std::string const& str); bool operator==(Command const& rhs) const; private: template friend struct rocRoller::Serialization::MappingTraits; /// Does this command need to synchronize before continuing the calling CPU thread? bool m_sync = false; OperationList m_operations; std::map> m_tagMap; ArgumentOffsetMap m_argOffsetMap; std::vector m_commandArgs; Operations::OperationTag m_nextTagValue{0}; int m_runtimeArgsOffset = 0; }; std::ostream& operator<<(std::ostream& stream, Command const& command); } #include