/* * The MIT License (MIT) * * Copyright (c) 2015-2022 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. */ #ifndef MIGRAPHX_GUARD_MIGRAPHLIB_ARGUMENT_HPP #define MIGRAPHX_GUARD_MIGRAPHLIB_ARGUMENT_HPP #include #include #include #include #include #include // clang-format off namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { /** * @brief Arguments passed to instructions * * An `argument` can represent a raw buffer of data that either be referenced from another element * or it can be owned by the argument. * */ struct argument : raw_data { argument() = default; argument(const shape& s); template ()())>{})> argument(shape s, F d) : m_shape(std::move(s)) { assign_buffer([f = std::move(d)]() mutable { return reinterpret_cast(f()); }); } template argument(shape s, T* d) : m_shape(std::move(s)) { assign_buffer([d] { return reinterpret_cast(d); }); } template argument(shape s, std::shared_ptr d) : m_shape(std::move(s)) { assign_buffer([d] { return reinterpret_cast(d.get()); }); } argument(shape s, std::nullptr_t); argument(const std::vector& args); /// Provides a raw pointer to the data char* data() const; /// Whether data is available bool empty() const; const shape& get_shape() const; argument reshape(const shape& s) const; argument copy() const; /// Make copy of the argument that is always sharing the data argument share() const; std::vector get_sub_objects() const; /// Return the ith element argument element(std::size_t i) const; private: void assign_buffer(std::function d); struct data_t { std::function get = nullptr; std::vector sub = {}; data_t share() const; static data_t from_args(const std::vector& args); }; argument(const shape& s, const data_t& d); shape m_shape; data_t m_data{}; }; std::vector to_shapes(const std::vector& args); void migraphx_to_value(value& v, const argument& a); void migraphx_from_value(const value& v, argument& a); } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx // clang-format on #endif