Unverified Commit 9d3fb0b5 authored by Ted Themistokleous's avatar Ted Themistokleous Committed by GitHub
Browse files

Merge branch 'develop' into enable_navi_32_ci

parents 9c91c08d aeb9f78c
......@@ -35,7 +35,7 @@ struct module;
/**
* Rewrite pooling to reduce_mean
*/
struct rewrite_pooling
struct MIGRAPHX_EXPORT rewrite_pooling
{
std::string name() const { return "rewrite_pooling"; }
void apply(module& m) const;
......
......@@ -35,7 +35,7 @@ struct module;
/**
* Rewrite quantization ops to equivalent operators
*/
struct rewrite_quantization
struct MIGRAPHX_EXPORT rewrite_quantization
{
std::string name() const { return "rewrite_quantization"; }
void apply(module& m) const;
......
......@@ -39,7 +39,7 @@ struct module;
/**
* Rewrite rnn to gemm and add.
*/
struct rewrite_rnn
struct MIGRAPHX_EXPORT rewrite_rnn
{
std::string name() const { return "rewrite_rnn"; }
void apply(module& m) const;
......
......@@ -37,7 +37,7 @@ struct module;
/**
* Schedule instructions for concurrent execution
*/
struct schedule
struct MIGRAPHX_EXPORT schedule
{
schedule_model model{};
bool enable = true;
......
......@@ -63,7 +63,7 @@ struct schedule_model
#ifdef TYPE_ERASED_DECLARATION
// Type-erased interface for:
struct schedule_model
struct MIGRAPHX_EXPORT schedule_model
{
//
std::size_t concurrency() const;
......@@ -99,7 +99,7 @@ struct schedule_model
{
using std::swap;
auto* derived = this->any_cast<PrivateDetailTypeErasedT>();
if(derived and private_detail_te_handle_mem_var.unique())
if(derived and private_detail_te_handle_mem_var.use_count() == 1)
{
*derived = std::forward<PrivateDetailTypeErasedT>(value);
}
......@@ -274,7 +274,7 @@ struct schedule_model
private_detail_te_handle_base_type& private_detail_te_get_handle()
{
assert(private_detail_te_handle_mem_var != nullptr);
if(not private_detail_te_handle_mem_var.unique())
if(private_detail_te_handle_mem_var.use_count() > 1)
private_detail_te_handle_mem_var = private_detail_te_handle_mem_var->clone();
return *private_detail_te_handle_mem_var;
}
......
/*
* The MIT License (MIT)
*
* Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (c) 2015-2023 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
......@@ -43,7 +43,7 @@ inline namespace MIGRAPHX_INLINE_NS {
struct value;
struct shape_impl;
struct shape
struct MIGRAPHX_EXPORT shape
{
// Add new types here
......@@ -85,7 +85,7 @@ struct shape
{
};
struct dynamic_dimension
struct MIGRAPHX_EXPORT dynamic_dimension
{
std::size_t min = 0;
std::size_t max = 0;
......@@ -100,22 +100,28 @@ struct shape
bool is_fixed() const;
bool has_optimal() const;
friend bool operator==(const dynamic_dimension& x, const dynamic_dimension& y);
friend bool operator!=(const dynamic_dimension& x, const dynamic_dimension& y);
friend std::ostream& operator<<(std::ostream& os, const dynamic_dimension& x);
MIGRAPHX_EXPORT friend bool operator==(const dynamic_dimension& x,
const dynamic_dimension& y);
MIGRAPHX_EXPORT friend bool operator!=(const dynamic_dimension& x,
const dynamic_dimension& y);
MIGRAPHX_EXPORT friend std::ostream& operator<<(std::ostream& os,
const dynamic_dimension& x);
// compare to fixed std::size_t dimension
friend bool operator==(const dynamic_dimension& x, const std::size_t& y);
friend bool operator==(const std::size_t& x, const dynamic_dimension& y);
friend bool operator!=(const dynamic_dimension& x, const std::size_t& y);
friend bool operator!=(const std::size_t& x, const dynamic_dimension& y);
MIGRAPHX_EXPORT friend bool operator==(const dynamic_dimension& x, const std::size_t& y);
MIGRAPHX_EXPORT friend bool operator==(const std::size_t& x, const dynamic_dimension& y);
MIGRAPHX_EXPORT friend bool operator!=(const dynamic_dimension& x, const std::size_t& y);
MIGRAPHX_EXPORT friend bool operator!=(const std::size_t& x, const dynamic_dimension& y);
// add and subtract fixed std::size_t dimension
dynamic_dimension& operator+=(const std::size_t& x);
dynamic_dimension& operator-=(const std::size_t& x);
friend dynamic_dimension operator+(const dynamic_dimension& x, const std::size_t& y);
friend dynamic_dimension operator+(const std::size_t& x, const dynamic_dimension& y);
friend dynamic_dimension operator-(const dynamic_dimension& x, const std::size_t& y);
MIGRAPHX_EXPORT friend dynamic_dimension operator+(const dynamic_dimension& x,
const std::size_t& y);
MIGRAPHX_EXPORT friend dynamic_dimension operator+(const std::size_t& x,
const dynamic_dimension& y);
MIGRAPHX_EXPORT friend dynamic_dimension operator-(const dynamic_dimension& x,
const std::size_t& y);
};
static const std::vector<type_t>& types();
......@@ -234,6 +240,10 @@ struct shape
template <class Iterator>
std::size_t index(Iterator start, Iterator last) const
{
if(this->dynamic())
{
MIGRAPHX_THROW("SHAPE: index() called on dynamic shape");
}
assert(std::distance(start, last) <= this->lens().size());
assert(this->lens().size() == this->strides().size());
return std::inner_product(start, last, this->strides().begin(), std::size_t{0}); // NOLINT
......@@ -286,9 +296,9 @@ struct shape
// convert the shape to a static one setting any non-fixed dynamic_dimensions to x
shape to_static(std::size_t x) const;
friend bool operator==(const shape& x, const shape& y);
friend bool operator!=(const shape& x, const shape& y);
friend std::ostream& operator<<(std::ostream& os, const shape& x);
MIGRAPHX_EXPORT friend bool operator==(const shape& x, const shape& y);
MIGRAPHX_EXPORT friend bool operator!=(const shape& x, const shape& y);
MIGRAPHX_EXPORT friend std::ostream& operator<<(std::ostream& os, const shape& x);
template <class T>
struct as
......@@ -396,8 +406,8 @@ struct shape
std::shared_ptr<const shape_impl> impl;
};
void migraphx_to_value(value& v, const shape& s);
void migraphx_from_value(const value& v, shape& s);
MIGRAPHX_EXPORT void migraphx_to_value(value& v, const shape& s);
MIGRAPHX_EXPORT void migraphx_from_value(const value& v, shape& s);
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
......
......@@ -35,7 +35,7 @@ struct module;
/**
* Simplify many algebraic instructions to more efficient versions.
*/
struct simplify_algebra
struct MIGRAPHX_EXPORT simplify_algebra
{
std::string name() const { return "simplify_algebra"; }
void apply(module& m) const;
......
......@@ -36,7 +36,7 @@ struct module;
* Inserts quantized operators in place of dq->quantizable_op->q
* then removes remaining fake quantization (q->dq pairs)
*/
struct simplify_qdq
struct MIGRAPHX_EXPORT simplify_qdq
{
std::string name() const { return "simplify_qdq"; }
void apply(module& m) const;
......
......@@ -36,7 +36,7 @@ struct module;
/**
* Eliminate redundant reshapes.
*/
struct simplify_reshapes
struct MIGRAPHX_EXPORT simplify_reshapes
{
std::string name() const { return "simplify_reshapes"; }
void apply(module& m) const;
......
......@@ -36,7 +36,7 @@ inline namespace MIGRAPHX_INLINE_NS {
* Split dynamic dimension over submodules if exactly one dimension in the parameter list is
* dynamic.
*/
struct split_single_dyn_dim
struct MIGRAPHX_EXPORT split_single_dyn_dim
{
std::string name() const { return "split_single_dyn_dim"; }
void apply(module_pass_manager&) const;
......
......@@ -35,7 +35,7 @@ inline namespace MIGRAPHX_INLINE_NS {
struct sqlite_impl;
struct sqlite
struct MIGRAPHX_EXPORT sqlite
{
sqlite() = default;
static sqlite read(const fs::path& p);
......
......@@ -62,7 +62,7 @@ struct stream_model
#ifdef TYPE_ERASED_DECLARATION
// Type-erased interface for:
struct stream_model
struct MIGRAPHX_EXPORT stream_model
{
//
std::size_t get_nstream() const;
......@@ -100,7 +100,7 @@ struct stream_model
{
using std::swap;
auto* derived = this->any_cast<PrivateDetailTypeErasedT>();
if(derived and private_detail_te_handle_mem_var.unique())
if(derived and private_detail_te_handle_mem_var.use_count() == 1)
{
*derived = std::forward<PrivateDetailTypeErasedT>(value);
}
......@@ -288,7 +288,7 @@ struct stream_model
private_detail_te_handle_base_type& private_detail_te_get_handle()
{
assert(private_detail_te_handle_mem_var != nullptr);
if(not private_detail_te_handle_mem_var.unique())
if(private_detail_te_handle_mem_var.use_count() > 1)
private_detail_te_handle_mem_var = private_detail_te_handle_mem_var->clone();
return *private_detail_te_handle_mem_var;
}
......
......@@ -127,7 +127,7 @@ supported_segments target_find_supported(T&, const_module_ref, support_metric)
#ifdef TYPE_ERASED_DECLARATION
// Type-erased interface for:
struct target
struct MIGRAPHX_EXPORT target
{
//
std::string name() const;
......@@ -167,7 +167,7 @@ struct target
{
using std::swap;
auto* derived = this->any_cast<PrivateDetailTypeErasedT>();
if(derived and private_detail_te_handle_mem_var.unique())
if(derived and private_detail_te_handle_mem_var.use_count() == 1)
{
*derived = std::forward<PrivateDetailTypeErasedT>(value);
}
......@@ -428,7 +428,7 @@ struct target
private_detail_te_handle_base_type& private_detail_te_get_handle()
{
assert(private_detail_te_handle_mem_var != nullptr);
if(not private_detail_te_handle_mem_var.unique())
if(private_detail_te_handle_mem_var.use_count() > 1)
private_detail_te_handle_mem_var = private_detail_te_handle_mem_var->clone();
return *private_detail_te_handle_mem_var;
}
......
......@@ -26,6 +26,7 @@
#include <migraphx/program.hpp>
#include <migraphx/config.hpp>
#include <migraphx/tf/export.h>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
......@@ -41,9 +42,10 @@ struct tf_options
};
/// Create a program from a tf pb file (default is nhwc format)
program parse_tf(const std::string& name, const tf_options& options = tf_options{});
MIGRAPHX_TF_EXPORT program parse_tf(const std::string& name,
const tf_options& options = tf_options{});
std::vector<std::string> get_tf_operators();
MIGRAPHX_TF_EXPORT std::vector<std::string> get_tf_operators();
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
......
......@@ -30,7 +30,7 @@
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
struct tmp_dir
struct MIGRAPHX_EXPORT tmp_dir
{
fs::path path;
tmp_dir(const std::string& prefix = "");
......
......@@ -141,7 +141,7 @@ To try_convert_value(const From& x)
return detail::try_convert_value_impl<To>(rank<3>{}, x);
}
struct value
struct MIGRAPHX_EXPORT value
{
// clang-format off
#define MIGRAPHX_VISIT_VALUE_TYPES(m) \
......@@ -453,14 +453,14 @@ struct value
std::vector<literal_to_string<To>>{default_value.begin(), default_value.end()});
}
friend bool operator==(const value& x, const value& y);
friend bool operator!=(const value& x, const value& y);
friend bool operator<(const value& x, const value& y);
friend bool operator<=(const value& x, const value& y);
friend bool operator>(const value& x, const value& y);
friend bool operator>=(const value& x, const value& y);
MIGRAPHX_EXPORT friend bool operator==(const value& x, const value& y);
MIGRAPHX_EXPORT friend bool operator!=(const value& x, const value& y);
MIGRAPHX_EXPORT friend bool operator<(const value& x, const value& y);
MIGRAPHX_EXPORT friend bool operator<=(const value& x, const value& y);
MIGRAPHX_EXPORT friend bool operator>(const value& x, const value& y);
MIGRAPHX_EXPORT friend bool operator>=(const value& x, const value& y);
friend std::ostream& operator<<(std::ostream& os, const value& d);
MIGRAPHX_EXPORT friend std::ostream& operator<<(std::ostream& os, const value& d);
std::size_t hash() const;
......
......@@ -35,6 +35,7 @@
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace verify {
// Compute the value of a range
template <class R>
......@@ -196,6 +197,7 @@ bool verify_range(const R1& r1, const R2& r2, double tolerance = 80, double* out
return error <= threshold;
}
} // namespace verify
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
#endif
......@@ -31,6 +31,7 @@
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
MIGRAPHX_EXPORT
bool verify_args(const std::string& name,
const argument& ref_arg,
const argument& target_arg,
......
......@@ -64,10 +64,7 @@ void instruction::replace(const shape& r)
result = r;
for(auto&& ins : output)
{
if(ins->name() == "@return")
continue;
assert(ins->name().front() != '@');
assert(ins->name() == "@return" or ins->name().front() != '@');
ins->recompute_shape();
}
}
......@@ -122,10 +119,6 @@ bool instruction::valid() const
{
computed = result;
}
else if(op.name() == "@return")
{
computed = {};
}
else
{
try
......@@ -145,6 +138,7 @@ bool instruction::valid() const
}
shape instruction::get_shape() const { return result; }
const literal& instruction::get_literal() const
{
assert(op.name() == "@literal");
......@@ -467,7 +461,7 @@ operation instruction::normalized_operator() const
if(this->need_normalization())
{
auto s = this->inputs().front()->get_shape();
if(not normalize_attributes(o, s.max_lens()))
if(not normalize_attributes(o, s))
return this->get_operator();
}
return o;
......
......@@ -460,11 +460,11 @@ instruction_ref module::add_parameter(std::string name, shape s)
instruction_ref module::add_return(std::vector<instruction_ref> args)
{
impl->push_back({builtin::returns{}, {}, std::move(args)});
shape instr_shape = compute_shape(builtin::returns{}, args);
impl->push_back({builtin::returns{}, instr_shape, std::move(args)});
auto result = std::prev(impl->instructions.end());
instruction::backreference(result);
assert(result->valid(begin()));
return result;
}
......@@ -1011,9 +1011,17 @@ std::vector<module_ref> module::get_sub_modules(bool shallow) const
module& module::sort()
{
auto implicit_deps = calc_implicit_deps();
fix([&](auto self, auto ins) {
this->move_instruction(ins, this->begin());
for(auto child : ins->inputs())
auto ins_inputs = ins->inputs();
if(implicit_deps.find(ins) != implicit_deps.end())
{
auto ins_implict_inputs = implicit_deps.at(ins);
ins_inputs.insert(
ins_inputs.end(), ins_implict_inputs.begin(), ins_implict_inputs.end());
}
for(auto child : ins_inputs)
{
if(not contains(this->impl->instructions, child))
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment