/******************************************************************************* * * MIT License * * Copyright (C) 2022-2025 Advanced Micro Devices, Inc. All rights reserved. * * 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 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(rocisa::DataType) LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(TensileLite::ActivationType) namespace llvm { namespace yaml { namespace sn = TensileLite::Serialization; template struct Hide { T& _value; Hide(T& value) : _value(value) { } T& operator*() { return _value; } }; template struct has_SequenceTraits> { const static bool value = sn::has_SequenceTraits::value; }; template struct has_ScalarEnumerationTraits> { const static bool value = sn::has_EnumTraits::value; }; template struct has_MappingTraits, EmptyContext> { const static bool value = sn::has_EmptyMappingTraits::value; }; template struct has_CustomMappingTraits> { const static bool value = sn::has_CustomMappingTraits::value; }; template struct missingTraits : public std::integral_constant< bool, !has_ScalarEnumerationTraits::value && !has_ScalarBitSetTraits::value && !has_ScalarTraits::value && !has_BlockScalarTraits::value && !has_MappingTraits::value && !has_SequenceTraits::value && !has_CustomMappingTraits::value && !has_DocumentListTraits::value && !sn::has_SerializationTraits::value> { }; template typename std::enable_if::value, void>::type yamlize(IO& io, T& Val, bool b, EmptyContext& ctx) { Hide hide(Val); yamlize(io, hide, b, ctx); } template typename std::enable_if::value, Input&>::type operator>>(Input& input, T& Val) { Hide hide(Val); return input >> hide; } template typename std::enable_if::value, Output&>::type operator<<(Output& output, T& Val) { Hide hide(Val); return output << hide; } } // namespace yaml } // namespace llvm namespace TensileLite { namespace Serialization { template <> struct IOTraits { using IO = llvm::yaml::IO; template static void mapRequired(IO& io, const char* key, T& obj) { io.mapRequired(key, obj); } template static void mapRequired(IO& io, const char* key, T& obj, Context& ctx) { io.mapRequired(key, obj, ctx); } template static void mapOptional(IO& io, const char* key, T& obj) { io.mapOptional(key, obj); } template static void mapOptional(IO& io, const char* key, T& obj, Context& ctx) { io.mapOptional(key, obj, ctx); } static bool outputting(IO& io) { return io.outputting(); } static void setError(IO& io, std::string const& msg) { // throw std::runtime_error(msg); return io.setError(msg); } static void setContext(IO& io, void* ctx) { io.setContext(ctx); } static void* getContext(IO& io) { return io.getContext(); } template static void enumCase(IO& io, T& member, const char* key, T value) { io.enumCase(member, key, value); } }; } // namespace Serialization } // namespace TensileLite namespace llvm { namespace yaml { LLVM_YAML_STRONG_TYPEDEF(size_t, FooType); using mysize_t = std::conditional::value, FooType, size_t>::type; template <> struct ScalarTraits { static void output(const mysize_t& value, void* ctx, raw_ostream& stream) { uint64_t tmp = value; ScalarTraits::output(tmp, ctx, stream); } static StringRef input(StringRef str, void* ctx, mysize_t& value) { uint64_t tmp; auto rv = ScalarTraits::input(str, ctx, tmp); value = tmp; return rv; } static bool mustQuote(StringRef) { return false; } }; template struct MappingTraits> { static void mapping(IO& io, Hide& value) { sn::MappingTraits::mapping(io, *value); } static const bool flow = sn::MappingTraits::flow; }; template struct SequenceTraits> { using Impl = sn::SequenceTraits; using Value = typename Impl::Value; static size_t size(IO& io, Hide& t) { return Impl::size(io, *t); } static Value& element(IO& io, Hide& t, size_t index) { return Impl::element(io, *t, index); } static const bool flow = Impl::flow; }; template struct ScalarEnumerationTraits> { static void enumeration(IO& io, Hide& value) { sn::EnumTraits::enumeration(io, *value); } }; template struct CustomMappingTraits> { using Impl = sn::CustomMappingTraits; static void inputOne(IO& io, StringRef key, Hide& value) { Impl::inputOne(io, key.str(), *value); } static void output(IO& io, Hide& value) { Impl::output(io, *value); } }; template <> struct MappingTraits> { using obj = TensileLite::MasterContractionLibrary; static void mapping(IO& io, std::shared_ptr& o) { sn::PointerMappingTraits::mapping(io, o); } }; static_assert( sn::has_EmptyMappingTraits< std::shared_ptr>, IO>::value, "asdf2"); static_assert( sn::has_SerializationTraits< std::shared_ptr>, IO>::value, "asdf"); static_assert( !has_SequenceTraits>>>::value, "fdsa"); static_assert(has_MappingTraits>>, EmptyContext>::value, "fdsa"); static_assert( !missingTraits>>, EmptyContext>::value, "fdsa"); } // namespace yaml } // namespace llvm