// Copyright Advanced Micro Devices, Inc., or its affiliates. // SPDX-License-Identifier: MIT #include #include #ifdef ROCROLLER_USE_HIP #include #endif #include #include #include #include #include #ifdef ROCROLLER_EMBED_ARCH_DEF #include CMRC_DECLARE(rocRoller); #endif namespace rocRoller { std::string GPUArchitecture::writeYaml(std::map const& input) { rocRoller::GPUArchitecturesStruct tmp; tmp.architectures = input; return Serialization::toYAML(tmp); } std::map GPUArchitecture::readYaml(std::string const& input) { auto archStruct = Serialization::readYAMLFile(input); return archStruct.architectures; } std::string GPUArchitecture::writeMsgpack(std::map const& input) { std::stringstream buffer; msgpack::pack(buffer, input); return buffer.str(); } std::map GPUArchitecture::readMsgpack(std::string const& input) { try { std::ifstream ifs(input); std::string buffer((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); msgpack::object_handle oh = msgpack::unpack(buffer.data(), buffer.size()); msgpack::object const& obj = oh.get(); auto rv = obj.as>(); return rv; } catch(const std::exception& e) { Throw("GPUArchitecture::readMsgpack(", input, ") failed: ", e.what()); } } std::map GPUArchitecture::readEmbeddedMsgpack() { #ifdef ROCROLLER_EMBED_ARCH_DEF try { auto fs = cmrc::rocRoller::get_filesystem(); auto fd = fs.open("resources/GPUArchitecture_def.msgpack"); msgpack::object_handle oh = msgpack::unpack( fd.begin(), reinterpret_cast(fd.end()) - reinterpret_cast(fd.begin())); msgpack::object const& obj = oh.get(); auto rv = obj.as>(); return rv; } catch(const std::exception& e) { Throw("GPUArchitecture::readEmbeddedMsgpack() failed: ", e.what()); } #else Throw( "GPUArchitecture::readEmbeddedMsgpack() failed: no embedded architecture definitions"); #endif } bool GPUArchitecture::isSupportedConstantValue(Register::ValuePtr value) const { if(value->regType() != Register::Type::Literal) return false; return std::visit([this](auto val) -> bool { return this->isSupportedConstantValue(val); }, value->getLiteralValue()); } }