"vscode:/vscode.git/clone" did not exist on "0433b7aa5e6fa177fd7e382c6fbfd0a4f902332a"
Commit 3272b22e authored by Shucai Xiao's avatar Shucai Xiao
Browse files

clang format

parent 94e3a2e4
......@@ -94,9 +94,7 @@ void set_nhwc(tf_options& options, bool is_nhwc) { options.is_nhwc = is_nhwc; }
void set_default_dim_value(tf_options& options, size_t value) { options.batch_size = value; }
void set_input_parameter_shape(onnx_options& options,
const char* name,
std::vector<int> dims)
void set_input_parameter_shape(onnx_options& options, const char* name, std::vector<int> dims)
{
options.map_input_dims[std::string(name)] = std::move(dims);
}
......@@ -855,8 +853,9 @@ migraphx_operation_name(char* out, int out_size, migraphx_operation_t operation)
if(operation == nullptr)
MIGRAPHX_THROW(migraphx_status_bad_param, "Bad parameter operation: Null pointer");
auto&& api_result = (operation->object).name();
auto* it = std::copy_n(api_result.begin(), std::min(static_cast<int>(api_result.size()), out_size - 1), out);
*it = '\0';
auto* it = std::copy_n(
api_result.begin(), std::min(static_cast<int>(api_result.size()), out_size - 1), out);
*it = '\0';
});
return api_error_result;
}
......
......@@ -235,9 +235,7 @@ struct shape : MIGRAPHX_CONST_HANDLE_BASE(shape)
this->make_handle(&migraphx_shape_create, type, plengths.data(), plengths.size());
}
shape(migraphx_shape_datatype_t type,
std::vector<int> plengths,
std::vector<int> pstrides)
shape(migraphx_shape_datatype_t type, std::vector<int> plengths, std::vector<int> pstrides)
{
this->make_handle(&migraphx_shape_create_with_strides,
type,
......@@ -699,8 +697,7 @@ inline program parse_onnx(const char* filename)
}
/// Parse a buffer of memory as an onnx file
inline program
parse_onnx_buffer(const void* data, int size, const migraphx::onnx_options& options)
inline program parse_onnx_buffer(const void* data, int size, const migraphx::onnx_options& options)
{
return program(
make<migraphx_program>(&migraphx_parse_onnx_buffer, data, size, options.get_handle_ptr()),
......
......@@ -61,8 +61,8 @@ void argument::assign_buffer(std::function<char*()> d)
assert(offset == s.bytes());
// cppcheck-suppress variableScope
int i = 0;
m_data = fix<data_t>([&](auto self, auto ss) {
int i = 0;
m_data = fix<data_t>([&](auto self, auto ss) {
data_t result;
if(ss.sub_shapes().empty())
{
......
......@@ -86,7 +86,7 @@ cpp_generator::function& cpp_generator::function::set_generic_types(const module
struct cpp_generator_impl
{
std::stringstream fs{};
int function_count = 0;
int function_count = 0;
std::function<std::string(std::string)> fmap = nullptr;
std::function<std::string(shape)> fresult = nullptr;
std::unordered_map<std::string, std::string> point_op_map = {};
......
......@@ -14,7 +14,7 @@ std::ptrdiff_t bidistance(const Range& r, Iterator start, Iterator last)
{
auto start_forward = start;
auto start_backwards = start;
int n = 0;
int n = 0;
while(start_forward != last and start_backwards != last)
{
n++;
......
......@@ -37,7 +37,7 @@ struct loader
std::string model;
std::string file;
std::string file_type;
int batch = 1;
int batch = 1;
bool is_nhwc = true;
unsigned trim = 0;
bool optimize = false;
......
......@@ -15,7 +15,7 @@ void gemm(tensor_view<T> cmat, tensor_view<T> amat, tensor_view<T> bmat, F alpha
int n_dims = cmat.get_shape().lens().size();
int dim_0 = n_dims - 2;
int dim_1 = n_dims - 1;
auto k = amat.get_shape().lens()[dim_1];
auto k = amat.get_shape().lens()[dim_1];
assert(amat.get_shape().lens()[dim_1] == bmat.get_shape().lens()[dim_0]);
assert(cmat.get_shape().lens()[dim_0] == amat.get_shape().lens()[dim_0]);
......
......@@ -15,8 +15,7 @@ struct file_options
program load(const std::string& filename, const file_options& options = file_options{});
program load_buffer(const std::vector<char>& buffer, const file_options& options = file_options{});
program
load_buffer(const char* buffer, int size, const file_options& options = file_options{});
program load_buffer(const char* buffer, int size, const file_options& options = file_options{});
void save(const program& p,
const std::string& filename,
......
......@@ -61,7 +61,7 @@ struct gather
{
argument result{output_shape};
// negative axis means counting dimensions from back
auto lens = args[0].get_shape().lens();
auto lens = args[0].get_shape().lens();
int axis_dim_size = lens[axis];
// max dimension in axis
visit_all(result, args[0])([&](auto output, auto data) {
......
......@@ -83,9 +83,9 @@ struct loop
const auto& iter_stat = iter_state.at(i);
const auto& scan_out = concatenated_outputs.at(i);
auto* in_data = iter_stat.data();
auto* out_data = scan_out.data();
int out_size = iter_stat.get_shape().bytes();
auto* in_data = iter_stat.data();
auto* out_data = scan_out.data();
int out_size = iter_stat.get_shape().bytes();
assert((iter + 1) * out_size <= scan_out.get_shape().bytes());
std::copy(in_data, in_data + out_size, out_data + iter * out_size);
}
......
......@@ -135,8 +135,8 @@ struct nonmaxsuppression
result.visit([&](auto out) { std::fill(out.begin(), out.end(), 0); });
int max_output_boxes_per_class = 0;
float iou_threshold = 0.0f;
float score_threshold = 0.0f;
float iou_threshold = 0.0f;
float score_threshold = 0.0f;
if(args.size() > 2)
{
......@@ -174,7 +174,7 @@ struct nonmaxsuppression
auto bidx = idx[0];
auto cidx = idx[1];
int score_offset = (bidx * class_num + cidx) * box_num;
int score_offset = (bidx * class_num + cidx) * box_num;
const float* batch_boxes = boxes + bidx * box_num * 4;
std::priority_queue<std::pair<float, int64_t>> sorted_boxes;
auto insert_to_sorted_boxes =
......
......@@ -57,7 +57,7 @@ struct pooling
const shape& input = inputs.at(0);
auto input_lens = input.lens();
int kdims = input_lens.size() - 2;
int kdims = input_lens.size() - 2;
auto input_size = inputs[0].lens().size();
auto padding_size = padding.size();
if(not(input_size == padding_size / 2 + 2 or input_size == padding_size + 2))
......
......@@ -13,20 +13,17 @@ template <class... Ts>
auto par_dfor(Ts... xs)
{
return [=](auto f) {
using array_type = std::array<int, sizeof...(Ts)>;
array_type lens = {{static_cast<int>(xs)...}};
auto n = std::accumulate(lens.begin(), lens.end(), 1, std::multiplies<int>{});
using array_type = std::array<int, sizeof...(Ts)>;
array_type lens = {{static_cast<int>(xs)...}};
auto n = std::accumulate(lens.begin(), lens.end(), 1, std::multiplies<int>{});
const int min_grain = 8;
if(n > 2 * min_grain)
{
array_type strides;
strides.fill(1);
std::partial_sum(lens.rbegin(),
lens.rend() - 1,
strides.rbegin() + 1,
std::multiplies<int>());
auto size =
std::accumulate(lens.begin(), lens.end(), 1, std::multiplies<int>());
std::partial_sum(
lens.rbegin(), lens.rend() - 1, strides.rbegin() + 1, std::multiplies<int>());
auto size = std::accumulate(lens.begin(), lens.end(), 1, std::multiplies<int>());
par_for(size, min_grain, [&](int i) {
array_type indices;
std::transform(strides.begin(),
......
......@@ -67,8 +67,7 @@ struct program
void finalize();
void
perf_report(std::ostream& os, int n, parameter_map params, int batch = 1) const;
void perf_report(std::ostream& os, int n, parameter_map params, int batch = 1) const;
void mark(const parameter_map& params, marker&& m);
......
......@@ -10,11 +10,11 @@ inline namespace MIGRAPHX_INLINE_NS {
/// struct to pass in tf options to parser
struct tf_options
{
bool is_nhwc = false;
bool is_nhwc = false;
int batch_size = 1;
/// Explicitly specify the dims of an input
std::unordered_map<std::string, std::vector<int>> map_input_dims = {};
std::vector<std::string> output_node_names = {};
std::vector<std::string> output_node_names = {};
};
/// Create a program from a tf pb file (default is nhwc format)
......
......@@ -20,12 +20,11 @@ struct parse_gru : op_parser<parse_gru>
std::vector<instruction_ref> args) const
{
migraphx::shape input_shape = args[0]->get_shape();
int hidden_size = args[2]->get_shape().lens()[2];
int hidden_size = args[2]->get_shape().lens()[2];
if(contains(info.attributes, "hidden_size"))
{
int hidden_size_att =
parser.parse_value(info.attributes.at("hidden_size")).at<int>();
int hidden_size_att = parser.parse_value(info.attributes.at("hidden_size")).at<int>();
if(hidden_size != hidden_size_att)
{
MIGRAPHX_THROW("GRU: hidden size mismatch in input and attribute");
......
......@@ -103,12 +103,11 @@ struct parse_lstm : op_parser<parse_lstm>
std::vector<instruction_ref> args) const
{
migraphx::shape input_shape = args[0]->get_shape();
int hidden_size = args[2]->get_shape().lens()[2];
int hidden_size = args[2]->get_shape().lens()[2];
if(contains(info.attributes, "hidden_size"))
{
int hidden_size_att =
parser.parse_value(info.attributes.at("hidden_size")).at<int>();
int hidden_size_att = parser.parse_value(info.attributes.at("hidden_size")).at<int>();
if(hidden_size != hidden_size_att)
{
MIGRAPHX_THROW("LSTM: hidden size mismatch in input and attribute");
......
......@@ -45,10 +45,7 @@ const auto& get_original_idx_op(const std::string& mode)
{
using original_idx_op = std::function<double(int, int, int, double)>;
static std::unordered_map<std::string, original_idx_op> const idx_ops = {
{"half_pixel",
[=](int, int, int idx, double scale) {
return (idx + 0.5) / scale - 0.5;
}},
{"half_pixel", [=](int, int, int idx, double scale) { return (idx + 0.5) / scale - 0.5; }},
{"pytorch_half_pixel",
[=](int, int l_out, int idx, double scale) {
return l_out > 1 ? (idx + 0.5) / scale - 0.5 : 0.0;
......@@ -57,11 +54,9 @@ const auto& get_original_idx_op(const std::string& mode)
[=](int l_in, int l_out, int idx, double) {
return (l_out == 1) ? 0.0 : (1.0 * idx * (l_in - 1.0) / (l_out - 1.0));
}},
{"asymmetric",
[=](int, int, int idx, double scale) { return idx / scale; }},
{"tf_half_pixel_for_nn", [=](int, int, int idx, double scale) {
return (idx + 0.5) / scale;
}}};
{"asymmetric", [=](int, int, int idx, double scale) { return idx / scale; }},
{"tf_half_pixel_for_nn",
[=](int, int, int idx, double scale) { return (idx + 0.5) / scale; }}};
if(!contains(idx_ops, mode))
{
......@@ -251,20 +246,19 @@ struct parse_resize : op_parser<parse_resize>
": ranks of input and scale are different!");
}
std::transform(in_lens.begin(),
in_lens.end(),
vec_scale.begin(),
out_lens.begin(),
[&](auto idx, auto scale) {
return static_cast<int>(idx * scale);
});
std::transform(
in_lens.begin(),
in_lens.end(),
vec_scale.begin(),
out_lens.begin(),
[&](auto idx, auto scale) { return static_cast<int>(idx * scale); });
}
}
}
shape out_s{in_s.type(), out_lens};
int out_elements = out_s.elements();
auto idx_op = get_original_idx_op(coord_trans_mode);
auto idx_op = get_original_idx_op(coord_trans_mode);
// reshape input to one-dimension
std::vector<int64_t> rsp_lens = {static_cast<int64_t>(in_s.elements())};
......
......@@ -20,12 +20,11 @@ struct parse_rnn : op_parser<parse_rnn>
std::vector<instruction_ref> args) const
{
migraphx::shape input_shape = args[0]->get_shape();
int hidden_size = args[1]->get_shape().lens()[1];
int hidden_size = args[1]->get_shape().lens()[1];
if(contains(info.attributes, "hidden_size"))
{
int hidden_size_att =
parser.parse_value(info.attributes.at("hidden_size")).at<int>();
int hidden_size_att = parser.parse_value(info.attributes.at("hidden_size")).at<int>();
if(hidden_size != hidden_size_att)
{
MIGRAPHX_THROW("RNN: hidden size mismatch in input and attribute");
......
......@@ -36,13 +36,13 @@ void memory_coloring_impl::run()
bool memory_coloring_impl::allocate(interval_ptr interval)
{
shape s = interval->result;
shape s = interval->result;
int size = s.bytes();
if(size == 0)
return false;
int element_size = (s.elements() == 0 ? 4 : (size / s.elements()));
live_range& segment = interval->segment;
int vn = segment.vn;
int element_size = (s.elements() == 0 ? 4 : (size / s.elements()));
live_range& segment = interval->segment;
int vn = segment.vn;
std::priority_queue<live_range*, std::vector<live_range*>, ordering> conflict_queue;
std::unordered_map<long long, live_range*> offset2_live;
offset2_live.clear();
......@@ -75,8 +75,8 @@ bool memory_coloring_impl::allocate(interval_ptr interval)
int offset = 0;
while(!conflict_queue.empty())
{
live_range* range = conflict_queue.top();
int iter_offset = range->offset;
live_range* range = conflict_queue.top();
int iter_offset = range->offset;
if(offset > iter_offset)
{
offset = std::max(offset, iter_offset + range->size);
......
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