Unverified Commit 40fbef9b authored by Ted Themistokleous's avatar Ted Themistokleous Committed by GitHub
Browse files

Merge branch 'develop' into threaded_nms

parents d164b151 aeb9f78c
......@@ -34,22 +34,76 @@ inline namespace MIGRAPHX_INLINE_NS {
struct module;
struct operation;
/**
* Broadcasting works by comparing the shapes element-wise starting with
* the trailing (right-most) dimensions and working leftwards. This is equivalent
* to what is done in NumPy.
* example 1:
* s0 = (3,2,4,5) and s1 = (2,1,1)
* In this case we need to broadcast (:,1,1) portion of
* s1 plus broadcast the 1st dimension of s0
* giving output_lens = (3,2,4,5)
*
* example 2:
* s0 = (3,2,1,5) and s1 = (2,7,5)
* In this case we need to broadcast the (:,:,1:,:) axis
* of s0 plus the 1st dimension of s1 giving
* output_lens = (3,2,7,5)
*
* example 3:
* s0 = (4, 1, 1) and s1 = (3, 4)
* output_lens = (4, 3, 4)
*/
MIGRAPHX_EXPORT
std::vector<std::size_t> compute_broadcasted_lens(std::vector<std::size_t> s0,
std::vector<std::size_t> s1);
MIGRAPHX_EXPORT
std::vector<shape::dynamic_dimension> compute_broadcasted_dyn_dims(shape s0, shape s1);
MIGRAPHX_EXPORT
shape common_shape(const std::vector<shape>& shapes);
std::vector<instruction_ref>
/**
* @brief Compute the common (broadcasted) dimensions of a list of fixed shapes
*/
MIGRAPHX_EXPORT
std::vector<std::size_t> compute_common_lens(const std::vector<shape>& shapes);
/**
* @ brief Compute the common (broadcasted) dynamic dimensions of a list of dynamic shapes
*/
MIGRAPHX_EXPORT
std::vector<shape::dynamic_dimension> compute_common_dyn_dims(const std::vector<shape>& shapes);
/**
* @brief Creates and adds instructions to convert input arguments to common shapes and types
* by adding multi-broadcast and type convert operations. This is a utility function for creating
* operations where the shape and type of inputs need to match. It supports both dynamic and
* static-shaped arguments.
*
* @param m containing module for instruction
* @param ins insertion location in instruction list
* @param inputs instructions to use as argument list; also, the shapes
* attached to each instruction_ref are considered for broadcasting
* @return std::vector<instruction_ref> a modified argument list
*/
MIGRAPHX_EXPORT std::vector<instruction_ref>
insert_common_args(module& m, instruction_ref ins, std::vector<instruction_ref> inputs);
MIGRAPHX_EXPORT
std::vector<instruction_ref> add_common_args(module& m, std::vector<instruction_ref> inputs);
MIGRAPHX_EXPORT
instruction_ref insert_common_op(module& m,
instruction_ref ins,
const operation& op,
std::vector<instruction_ref> inputs);
/**
* @brief Wrapper for insert_common_args() which inserts operation at the end of the module.
*/
MIGRAPHX_EXPORT
instruction_ref add_common_op(module& m, const operation& op, std::vector<instruction_ref> inputs);
} // namespace MIGRAPHX_INLINE_NS
......
......@@ -40,9 +40,6 @@ struct compile_options
bool fast_math = true;
bool exhaustive_tune = false;
/// Use the split_single_dyn_dim pass
bool split_single_dyn_dim = false;
tracer trace{};
};
......
......@@ -41,7 +41,7 @@ struct src_file
std::size_t len() const { return content.second - content.first; }
};
struct src_compiler
struct MIGRAPHX_EXPORT src_compiler
{
std::string compiler = "c++";
std::string flags = "";
......
......@@ -56,7 +56,7 @@ struct concat_optimization
#ifdef TYPE_ERASED_DECLARATION
// Type-erased interface for:
struct concat_optimization
struct MIGRAPHX_EXPORT concat_optimization
{
//
std::string name() const;
......@@ -88,7 +88,7 @@ struct concat_optimization
{
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);
}
......@@ -233,7 +233,7 @@ struct concat_optimization
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;
}
......
......@@ -24,6 +24,8 @@
#ifndef MIGRAPHX_GUARD_CONFIG_HPP
#define MIGRAPHX_GUARD_CONFIG_HPP
#include <migraphx/export.h>
#if !defined(MIGRAPHX_USE_CLANG_TIDY) && !defined(DOXYGEN)
#ifdef BUILD_DEV
......
......@@ -80,7 +80,7 @@ void finish_on_context(T&, any_ptr)
#ifdef TYPE_ERASED_DECLARATION
// Type-erased interface for:
struct context
struct MIGRAPHX_EXPORT context
{
// (optional)
value to_value() const;
......@@ -118,7 +118,7 @@ struct context
{
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);
}
......@@ -373,7 +373,7 @@ struct context
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;
}
......
......@@ -30,7 +30,7 @@
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
std::string convert_to_json(const std::string& str);
MIGRAPHX_EXPORT std::string convert_to_json(const std::string& str);
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
......
......@@ -40,7 +40,7 @@ struct shape;
struct cpp_generator_impl;
struct cpp_generator
struct MIGRAPHX_EXPORT cpp_generator
{
using generate_module_callback = std::function<std::string(
instruction_ref, const std::unordered_map<instruction_ref, std::string>&)>;
......@@ -50,7 +50,7 @@ struct cpp_generator
std::string type;
};
struct function
struct MIGRAPHX_EXPORT function
{
std::vector<param> params = {};
std::string body = "";
......@@ -78,6 +78,7 @@ struct cpp_generator
function& set_types(const module& m, const std::function<std::string(shape)>& parse);
function& set_generic_types(const module& m);
function& add_generic_param(const std::string& pname);
function& unused_param(const std::string& pname);
};
cpp_generator();
......
......@@ -37,7 +37,7 @@ struct program;
/**
* Remove instructions where the output is not used.
*/
struct dead_code_elimination
struct MIGRAPHX_EXPORT dead_code_elimination
{
std::string name() const { return "dead_code_elimination"; }
void apply(module& m) const;
......
......@@ -34,15 +34,15 @@ inline namespace MIGRAPHX_INLINE_NS {
struct module;
struct dominator_info
struct MIGRAPHX_EXPORT dominator_info
{
bool strictly_dominate(instruction_ref ins1, instruction_ref ins2);
std::unordered_map<instruction_ref, instruction_ref> ins2idom;
};
dominator_info compute_dominator(module& m);
// dominator_info compute_dominator_naive(const module& m);
MIGRAPHX_EXPORT dominator_info compute_dominator(module& m);
// MIGRAPHX_EXPORT dominator_info compute_dominator_naive(const module& m);
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
......
......@@ -26,6 +26,7 @@
#include <migraphx/config.hpp>
#include <migraphx/filesystem.hpp>
#include <migraphx/optional.hpp>
#include <functional>
#include <memory>
#include <vector>
......@@ -35,7 +36,7 @@ inline namespace MIGRAPHX_INLINE_NS {
struct dynamic_loader_impl;
struct dynamic_loader
struct MIGRAPHX_EXPORT dynamic_loader
{
template <class T>
static fs::path path(T* address)
......@@ -43,6 +44,9 @@ struct dynamic_loader
return path(reinterpret_cast<void*>(address));
}
static fs::path path(void* address);
static optional<dynamic_loader> try_load(const fs::path& p);
dynamic_loader() = default;
dynamic_loader(const fs::path& p);
......
......@@ -37,7 +37,7 @@ struct module;
* Remove memory allocations. This will create a parameter which is the max of all memory used in
* the program.
*/
struct eliminate_allocation
struct MIGRAPHX_EXPORT eliminate_allocation
{
std::string allocation_op{};
std::size_t alignment = 32;
......
......@@ -36,7 +36,7 @@ struct module;
/**
* Remove identical instructions.
*/
struct eliminate_common_subexpression
struct MIGRAPHX_EXPORT eliminate_common_subexpression
{
std::string name() const { return "eliminate_common_subexpression"; }
void apply(module& m) const;
......
......@@ -37,7 +37,7 @@ struct module;
/**
* Remove concat operators by having each operator can write to different chunk of memory.
*/
struct eliminate_concat
struct MIGRAPHX_EXPORT eliminate_concat
{
concat_optimization concat_opt;
std::string name() const { return "eliminate_concat"; }
......
......@@ -36,7 +36,7 @@ struct module;
/**
* Remove contiguous instructions by checking if the operator can use non-standard shapes.
*/
struct eliminate_contiguous
struct MIGRAPHX_EXPORT eliminate_contiguous
{
std::string op_name;
std::string name() const { return "eliminate_contiguous"; }
......
......@@ -38,7 +38,7 @@ struct module;
* Remove data types. This will instert convert operators so the data type
* is not used by any operator.
*/
struct eliminate_data_type
struct MIGRAPHX_EXPORT eliminate_data_type
{
std::set<shape::type_t> types;
shape::type_t target_type;
......
......@@ -38,7 +38,7 @@ struct module;
* preserve the semantics of previous program state, therefore dead code elimination
* should not be used afterwards.
*/
struct eliminate_identity
struct MIGRAPHX_EXPORT eliminate_identity
{
std::string name() const { return "eliminate_identity"; }
void apply(module& m) const;
......
......@@ -39,7 +39,7 @@ struct module;
* Remove pads if they can be written as an
* attribute to another op (im2col, convolution, pooling)
*/
struct eliminate_pad
struct MIGRAPHX_EXPORT eliminate_pad
{
std::string name() const { return "eliminate_pad"; }
......
......@@ -38,13 +38,13 @@ inline namespace MIGRAPHX_INLINE_NS {
static const char* value() { return #x; } \
}; // NOLINT
bool enabled(const char* name);
bool disabled(const char* name);
std::vector<std::string> env(const char* name);
MIGRAPHX_EXPORT bool enabled(const char* name);
MIGRAPHX_EXPORT bool disabled(const char* name);
MIGRAPHX_EXPORT std::vector<std::string> env(const char* name);
std::size_t value_of(const char* name, std::size_t fallback = 0);
MIGRAPHX_EXPORT std::size_t value_of(const char* name, std::size_t fallback = 0);
std::string string_value_of(const char* name, std::string fallback = "");
MIGRAPHX_EXPORT std::string string_value_of(const char* name, std::string fallback = "");
template <class T>
bool enabled(T)
......
......@@ -31,11 +31,13 @@
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
std::vector<char> read_buffer(const std::string& filename, size_t offset = 0, size_t nbytes = 0);
std::string read_string(const std::string& filename);
MIGRAPHX_EXPORT std::vector<char>
read_buffer(const std::string& filename, size_t offset = 0, size_t nbytes = 0);
MIGRAPHX_EXPORT std::string read_string(const std::string& filename);
void write_buffer(const std::string& filename, const char* buffer, std::size_t size);
void write_buffer(const std::string& filename, const std::vector<char>& buffer);
MIGRAPHX_EXPORT void
write_buffer(const std::string& filename, const char* buffer, std::size_t size);
MIGRAPHX_EXPORT void write_buffer(const std::string& filename, const std::vector<char>& buffer);
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
......
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