Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make argument constructor explicit #2346

Merged
merged 6 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/include/migraphx/argument.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct MIGRAPHX_EXPORT argument : raw_data<argument>
{
argument() = default;

argument(const shape& s);
explicit argument(const shape& s);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
explicit argument(const shape& s);
// explicit to protect against passing argument to a function that only needs a shape
explicit argument(const shape& s);


template <class F, MIGRAPHX_REQUIRES(std::is_pointer<decltype(std::declval<F>()())>{})>
argument(shape s, F d)
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/allocate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,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}};
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/include/migraphx/op/pooling.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_))
{
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/targets/gpu/include/migraphx/gpu/convolution.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ struct miopen_convolution
// MIOpen has APIs to pass pre-allocated buffers starting from rocm-5.6
preallocate = true;
#endif
auto x = preallocate ? to_gpu(generate_argument(x_shape)) : inputs[0];
auto w = preallocate ? to_gpu(generate_argument(w_shape)) : inputs[1];
auto y = preallocate ? allocate_gpu(output_shape) : inputs[2];
auto x = preallocate ? to_gpu(generate_argument(x_shape)) : argument{inputs[0]};
auto w = preallocate ? to_gpu(generate_argument(w_shape)) : argument{inputs[1]};
auto y = preallocate ? allocate_gpu(output_shape) : argument{inputs[2]};
auto workspace =
preallocate ? allocate_gpu(workspace_shape) : migraphx::argument(workspace_shape);

Expand Down
2 changes: 1 addition & 1 deletion test/eliminate_allocation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct allocate
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
return migraphx::argument{output_shape};
}
};

Expand Down
4 changes: 2 additions & 2 deletions test/eliminate_concat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct concat
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
return migraphx::argument{output_shape};
}
};

Expand Down Expand Up @@ -104,7 +104,7 @@ struct allocate
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
return migraphx::argument{output_shape};
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/memory_coloring_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ struct allocate
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
return migraphx::argument{output_shape};
}
};

Expand Down
2 changes: 1 addition & 1 deletion test/normalize_ops_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct normalize_test_op
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
return migraphx::argument{output_shape};
}
};

Expand Down
4 changes: 2 additions & 2 deletions test/replace_allocate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ struct allocate_no_out : migraphx::auto_register_op<allocate_no_out>
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
return migraphx::argument{output_shape};
}
};

Expand All @@ -78,7 +78,7 @@ struct allocate_with_out : migraphx::auto_register_op<allocate_with_out>
const migraphx::shape& output_shape,
const std::vector<migraphx::argument>&) const
{
return {output_shape};
return migraphx::argument{output_shape};
}
};

Expand Down
Loading