Unverified Commit a6fa5e4b authored by Chris Austen's avatar Chris Austen Committed by GitHub
Browse files

Merge branch 'develop' into enable_navi_32_ci

parents b7a7cd3c 7604ecf5
......@@ -62,10 +62,9 @@ const int auto_register<Action, T>::static_register = auto_register_action<Actio
#define MIGRAPHX_AUTO_REGISTER_NAME_DETAIL(x) migraphx_auto_register_##x
#define MIGRAPHX_AUTO_REGISTER_NAME(x) MIGRAPHX_AUTO_REGISTER_NAME_DETAIL(x)
// NOLINTNEXTLINE
#define MIGRAPHX_AUTO_REGISTER(...) \
void MIGRAPHX_AUTO_REGISTER_NAME(__LINE__)(migraphx::auto_register<__VA_ARGS__> x = \
migraphx::auto_register<__VA_ARGS__>{}) \
__attribute__((unused));
#define MIGRAPHX_AUTO_REGISTER(...) \
[[maybe_unused]] void MIGRAPHX_AUTO_REGISTER_NAME(__LINE__)( \
migraphx::auto_register<__VA_ARGS__> x = migraphx::auto_register<__VA_ARGS__>{});
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
......
......@@ -37,8 +37,18 @@ inline namespace MIGRAPHX_INLINE_NS {
struct src_file
{
fs::path path;
std::pair<const char*, const char*> content;
std::size_t len() const { return content.second - content.first; }
std::string_view content;
src_file() = default;
src_file(fs::path file_path, std::string_view file_content)
: path{std::move(file_path)}, content{file_content}
{
}
explicit src_file(const std::pair<std::string_view, std::string_view>& pair)
: path{pair.first}, content{pair.second}
{
}
};
struct MIGRAPHX_EXPORT src_compiler
......
......@@ -25,6 +25,7 @@
#define MIGRAPHX_GUARD_CONFIG_HPP
#include <migraphx/export.h>
#include <ciso646>
#if !defined(MIGRAPHX_USE_CLANG_TIDY) && !defined(DOXYGEN)
......
......@@ -38,12 +38,14 @@ struct dynamic_loader_impl;
struct MIGRAPHX_EXPORT dynamic_loader
{
#ifndef _WIN32
template <class T>
static fs::path path(T* address)
{
return path(reinterpret_cast<void*>(address));
}
static fs::path path(void* address);
#endif
static optional<dynamic_loader> try_load(const fs::path& p);
......
......@@ -29,6 +29,17 @@
#if defined(CPPCHECK)
#define MIGRAPHX_HAS_FILESYSTEM 1
#define MIGRAPHX_HAS_FILESYSTEM_TS 1
#elif defined(_WIN32)
#if _MSC_VER >= 1920
#define MIGRAPHX_HAS_FILESYSTEM 1
#define MIGRAPHX_HAS_FILESYSTEM_TS 0
#elif _MSC_VER >= 1900
#define MIGRAPHX_HAS_FILESYSTEM 0
#define MIGRAPHX_HAS_FILESYSTEM_TS 1
#else
#define MIGRAPHX_HAS_FILESYSTEM 0
#define MIGRAPHX_HAS_FILESYSTEM_TS 0
#endif
#elif defined(__has_include)
#if __has_include(<filesystem>) && __cplusplus >= 201703L
#define MIGRAPHX_HAS_FILESYSTEM 1
......
......@@ -27,9 +27,6 @@
#include <algorithm>
#include <cmath>
#include <numeric>
#ifdef _MSC_VER
#include <iso646.h>
#endif
#include <migraphx/requires.hpp>
#include <migraphx/config.hpp>
......
......@@ -48,7 +48,7 @@ constexpr T normalize(unsigned long z)
template <class T, MIGRAPHX_REQUIRES(is_signed<T>{} and not is_floating_point<T>{})>
constexpr T normalize(unsigned long z)
{
const auto max = 1UL << (sizeof(T) * 5);
const auto max = 1ULL << (sizeof(T) * 5);
const auto half_max = max / 2;
return half_max - (z % max);
}
......@@ -58,7 +58,7 @@ template <class T,
not std::is_same<T, bool>{})>
constexpr T normalize(unsigned long z)
{
const auto max = 1UL << (sizeof(T) * 5);
const auto max = 1ULL << (sizeof(T) * 5);
return z % max;
}
......
/*
* 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
......@@ -27,12 +27,42 @@
#include <list>
#include <functional>
#include <migraphx/config.hpp>
#include <migraphx/requires.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
struct instruction;
#if defined(_WIN32) && !defined(NDEBUG)
struct instruction_ref : std::list<instruction>::iterator
{
using instruction_iter = std::list<instruction>::iterator;
using instruction_const_iter = std::list<instruction>::const_iterator;
instruction_ref() = default;
instruction_ref(const instruction_iter& other) : instruction_iter(other) {}
template <class T,
class U,
MIGRAPHX_REQUIRES(std::is_same<T, instruction_ref>{} or
std::is_same<U, instruction_ref>{})>
friend bool operator==(const T& x, const U& y)
{
return x._Unwrapped()._Ptr == y._Unwrapped()._Ptr;
}
template <class T,
class U,
MIGRAPHX_REQUIRES(std::is_same<T, instruction_ref>{} or
std::is_same<U, instruction_ref>{})>
friend bool operator!=(const T& x, const U& y)
{
return not(x == y);
}
};
#else
using instruction_ref = std::list<instruction>::iterator;
#endif
MIGRAPHX_EXPORT migraphx::instruction* as_address(const instruction_ref& ins) noexcept;
......@@ -65,4 +95,8 @@ struct equal_to<migraphx::instruction_ref> // NOLINT
} // namespace std
#ifdef _MSC_VER
#include <migraphx/instruction.hpp>
#endif
#endif
......@@ -33,6 +33,7 @@
#include <migraphx/type_name.hpp>
#include <migraphx/source_location.hpp>
#include <migraphx/config.hpp>
#include <array>
#include <unordered_map>
#include <unordered_set>
......
......@@ -52,6 +52,7 @@ using dependent_type = typename select_dependent_type<T, Ts...>::type;
* \param attr_val the normalize_axes attributes from the operator
* \param prefix error message prefix
*/
MIGRAPHX_EXPORT
std::vector<int64_t> normalize_axes(const std::vector<int64_t>& axes,
const shape& input_shape,
const value& attr_val,
......@@ -67,6 +68,7 @@ std::vector<int64_t> normalize_axes(const std::vector<int64_t>& axes,
* \param attr_val the normalize_axes attributes from the operator
* \param prefix error message prefix
*/
MIGRAPHX_EXPORT
std::vector<int64_t> normalize_indices(const std::vector<int64_t>& indices,
const std::vector<int64_t>& axes,
const shape& input_shape,
......
......@@ -33,6 +33,19 @@ namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace op {
/**
* Static allocate:
* No inputs: `allocate()`
* `this.s` attribute set to the static output shape of the buffer.
*
* Dynamic allocate:
* One input: `allocate(output_dims)`
* `output_dims` are the output buffer dimensions and has a static shape.
* Either `this.s` or `this.buf_type` must be set to calculate the dynamic output shape at compute
* time. If `this.buf_type` is set, the compute_shape() of allocate at compile time will have
* dynamic_dimensions from {0, max_int} with rank = output_dims.ndim(). If `this.s` is set then the
* compute_shape() will output `this.s`; `this.s` should be a dynamic shape.
*/
struct allocate
{
shape s{};
......@@ -75,13 +88,13 @@ struct allocate
{
if(args.empty())
{
return {output_shape};
return argument{output_shape};
}
else
{
std::vector<std::size_t> output_dims(output_shape.ndim());
args.at(0).visit([&](auto a) { output_dims.assign(a.begin(), a.end()); });
return {shape{buf_type, output_dims}};
return argument{shape{buf_type, output_dims}};
}
}
};
......
/*
* 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
......@@ -31,6 +31,7 @@
#include <migraphx/value.hpp>
#include <migraphx/op/normalize_attribute.hpp>
#include <migraphx/dyn_output.hpp>
#include <migraphx/float_equal.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
......@@ -38,12 +39,13 @@ namespace op {
struct argmax
{
int64_t axis = 0;
int64_t axis = 0;
bool select_last_index = false;
template <class Self, class F>
static auto reflect(Self& self, F f)
{
return pack(f(self.axis, "axis"));
return pack(f(self.axis, "axis"), f(self.select_last_index, "select_last_index"));
}
value attributes() const
......@@ -87,6 +89,10 @@ struct argmax
max_val = cur_val;
max_index = i;
}
else if(select_last_index and float_equal(max_val, cur_val))
{
max_index = i;
}
}
return max_index;
}
......
/*
* 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
......@@ -30,6 +30,7 @@
#include <migraphx/config.hpp>
#include <migraphx/value.hpp>
#include <migraphx/op/normalize_attribute.hpp>
#include <migraphx/float_equal.hpp>
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
......@@ -38,11 +39,12 @@ namespace op {
struct argmin
{
int64_t axis = 0;
bool select_last_index = false;
template <class Self, class F>
static auto reflect(Self& self, F f)
{
return pack(f(self.axis, "axis"));
return pack(f(self.axis, "axis"), f(self.select_last_index, "select_last_index"));
}
value attributes() const
......@@ -78,6 +80,10 @@ struct argmin
min_val = cur_val;
min_index = i;
}
else if(select_last_index and float_equal(min_val, cur_val))
{
min_index = i;
}
}
return min_index;
......
......@@ -68,7 +68,7 @@ struct convert : unary<convert>
auto y = x;
shape::visit(type, [&](auto as) {
// clamping value between target_type's max and min doesn't work for NaNs,
if(std::isnan(x))
if(std::isnan(static_cast<double>(x)))
{
y = as.nan();
}
......
......@@ -35,7 +35,7 @@ struct isnan : unary<isnan>
{
auto apply() const
{
return [](auto x) { return std::isnan(x); };
return [](auto x) { return std::isnan(static_cast<double>(x)); };
}
std::string name() const { return "isnan"; }
......
......@@ -24,6 +24,7 @@
#ifndef MIGRAPHX_GUARD_OPERATORS_NONMAXSUPPRESSION_HPP
#define MIGRAPHX_GUARD_OPERATORS_NONMAXSUPPRESSION_HPP
#include <array>
#include <cmath>
#include <queue>
#include <cstdint>
......
......@@ -411,7 +411,7 @@ struct pooling
// for dynamic GlobalPooling, there's no padding
kernel_dims.insert(kernel_dims.end(), input_lens.begin() + 2, input_lens.end());
output_shape = dyn_out.computed_shape;
result = dyn_out.computed_shape;
result = argument{dyn_out.computed_shape};
}
else if((padding_mode != op::padding_mode_t::default_))
{
......@@ -439,7 +439,7 @@ struct pooling
{
kernel_dims = this->lengths;
output_shape = dyn_out.computed_shape;
result = dyn_out.computed_shape;
result = argument{dyn_out.computed_shape};
}
// Perform the computation and populate result
......
......@@ -77,11 +77,26 @@ struct random_uniform
using type = typename decltype(output)::value_type;
if constexpr(std::is_integral<type>{})
{
// default range for all integer types is
// (0, std::uniform_int_distribution<type>::max()).
// Todo: enable different ranges
std::uniform_int_distribution<type> dis;
std::generate(output.begin(), output.end(), [&] { return dis(gen); });
#ifdef _MSC_VER
// According to the C++ specification, the effect is undefined if the result type
// for the generator is not one of short, int, long, long long, unsigned short,
// unsigned int, unsigned long, or unsigned long long. See
// https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution.
if constexpr(sizeof(type) == 1)
{
std::uniform_int_distribution<int> dis{std::numeric_limits<type>::min(),
std::numeric_limits<type>::max()};
std::generate(output.begin(), output.end(), [&] { return dis(gen); });
}
else
#endif
{
// default range for all integer types is
// (0, std::uniform_int_distribution<type>::max()).
// Todo: enable different ranges
std::uniform_int_distribution<type> dis;
std::generate(output.begin(), output.end(), [&] { return dis(gen); });
}
}
else
{
......
......@@ -36,6 +36,22 @@ namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
namespace op {
/**
* 1 input version:
* reshape(input_data)
* this.dims = output_dims
* Makes a copy of input_data to the output shape.
*
* 2 input version:
* reshape(input_data, output_buffer)
* this.dims = unset
* Copies input_data to output_buffer; output_buffer already has the output shape.
* This version will not fail gracefully if the input shape and output_buffer shape are
* incompatible. There's a throw that will catch when the number of elements do not match at
* runtime. This version should only be used for dynamic reshapes (output dimensions only known at
* runtime). If output_buffer has a static shape during compile/parse, you can use the 1 input
* version.
*/
struct reshape
{
std::vector<int64_t> dims;
......@@ -215,32 +231,56 @@ struct reshape
shape compute_shape(std::vector<shape> inputs) const
{
check_shapes{inputs, *this, true}.has(1);
check_shapes{inputs, *this, true}.has(1, 2);
auto n_neg_dims = std::count(dims.begin(), dims.end(), -1);
if(n_neg_dims > 1)
MIGRAPHX_THROW("reshape: Dimensions for reshape can only have one -1 dim");
auto s0 = inputs.front();
if(s0.dynamic())
if(inputs.size() == 1)
{
return dyn_compute_shape(s0);
if(s0.dynamic())
{
return dyn_compute_shape(s0);
}
else
{
return static_compute_shape(inputs, n_neg_dims);
}
}
else
{
return static_compute_shape(inputs, n_neg_dims);
return inputs.back();
}
}
argument compute(const dyn_output& dyn_out, std::vector<argument> args) const
{
assert(dyn_out.computed_shape.standard());
argument result{dyn_out.computed_shape};
if(args.size() == 1)
{
argument result{dyn_out.computed_shape};
visit_all(result, args[0])([&](auto output, auto input) {
std::copy(input.begin(), input.end(), output.begin());
});
return result;
visit_all(result, args[0])([&](auto output, auto input) {
std::copy(input.begin(), input.end(), output.begin());
});
return result;
}
else
{
// 2 arg
if(args[0].get_shape().elements() != args[1].get_shape().elements())
{
MIGRAPHX_THROW("Reshape: Number of elements must match at runtime. Input: " +
std::to_string(args[0].get_shape().elements()) +
" Output buffer: " + std::to_string(args[1].get_shape().elements()));
}
visit_all(args[1], args[0])([&](auto output, auto input) {
std::copy(input.begin(), input.end(), output.begin());
});
return args[1];
}
}
};
......
......@@ -33,6 +33,7 @@
#include <migraphx/dfor.hpp>
#include <migraphx/ranges.hpp>
#include <migraphx/shape_for_each.hpp>
#include <array>
#include <cmath>
#include <numeric>
#include <utility>
......
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