Commit 087c205e authored by Paul's avatar Paul
Browse files

Merge from develop

parents a3a9e469 e15b8333
CheckOptions:
- key: bugprone-unused-return-value.CheckedFunctions
value: '::std::async;::std::launder;::std::remove;::std::remove_if;::std::unique;::std::unique_ptr::release;::std::basic_string::empty;::std::vector::empty;::std::find;::std::find_if;::std::find_if_not;::std::all_of;::std::any_of;::std::none_of;::std::count;::std::count_if;::std::mismatch;::std::find_end;::std::find_first_of;::std::adjacent_find;::std::search;::std::search_n;::std::nth_element;::std::lower_bound;::std::upper_bound;::std::binary_search;::std::equal_range;::std::max;::std::max_element;::std::min;::std::min_element;::std::minmax;::std::minmax_element;::std::equal;::std::lexicographical_compare;::std::accumulate;::std::inner_product'
- key: cppcoreguidelines-macro-usage.AllowedRegexp
value: 'DEBUG|FALLTHROUGH|_THROW|_REQUIRES|_DECLARE_|_VISIT_|_GENERATE_|_DETAIL_|_MANAGE_PTR|_MATCHER|DEVICE_SHARED'
- key: modernize-loop-convert.MinConfidence
value: risky
- key: modernize-loop-convert.NamingStyle
value: lower_case
- key: performance-unnecessary-copy-initialization.AllowedTypes
value: 'shape'
- key: performance-unnecessary-value-param.AllowedTypes
value: 'shape'
- key: readability-function-size.BranchThreshold
value: '15'
- key: readability-function-size.LineThreshold
......
......@@ -52,6 +52,7 @@ rocm_enable_clang_tidy(
-clang-analyzer-optin.performance.Padding
-clang-diagnostic-deprecated-declarations
-clang-diagnostic-extern-c-compat
-clang-diagnostic-disabled-macro-expansion
-clang-diagnostic-unused-command-line-argument
-cppcoreguidelines-pro-bounds-array-to-pointer-decay
-cppcoreguidelines-pro-bounds-constant-array-index
......@@ -70,13 +71,12 @@ rocm_enable_clang_tidy(
-hicpp-explicit-conversions
-hicpp-no-array-decay
-hicpp-special-member-functions
-hicpp-uppercase-literal-suffix
-hicpp-use-override
# This check is broken
-hicpp-use-auto
-llvm-header-guard
-llvm-include-order
-misc-macro-parentheses
-modernize-use-auto
-modernize-use-override
-modernize-pass-by-value
-modernize-use-default-member-init
......@@ -84,7 +84,12 @@ rocm_enable_clang_tidy(
-readability-braces-around-statements
-readability-else-after-return
-readability-named-parameter
-readability-uppercase-literal-suffix,
-*-avoid-c-arrays
-*-explicit-constructor
-*-magic-numbers
-*-non-private-member-variables-in-classes
-*-use-auto
-*-use-emplace
-*-use-equals-default
ERRORS
......@@ -94,6 +99,7 @@ rocm_enable_clang_tidy(
".*hpp"
EXTRA_ARGS
-DMIGRAPHX_USE_CLANG_TIDY
"-Dmain\\\\(...\\\\)=main\\\\(__VA_ARGS__\\\\) // NOLINT"
)
include(ROCMCppCheck)
......@@ -111,7 +117,9 @@ rocm_enable_cppcheck(
passedByValue
unusedStructMember
functionStatic
functionConst
functionConst:*program.*
shadowFunction
shadowVar
definePrefix:*test/include/test.hpp
FORCE
INCONCLUSIVE
......@@ -124,6 +132,7 @@ rocm_enable_cppcheck(
${CMAKE_CURRENT_SOURCE_DIR}/src/include
${CMAKE_CURRENT_SOURCE_DIR}/src/targets/cpu/include
${CMAKE_CURRENT_SOURCE_DIR}/src/targets/miopen/include
${CMAKE_CURRENT_SOURCE_DIR}/test/include
DEFINE
CPPCHECK=1
)
......@@ -136,6 +145,7 @@ rocm_create_package(
DESCRIPTION "AMD's graph optimizer"
MAINTAINER "Paul Fultz II <paul.fultz@amd.com>"
LDCONFIG
PTH
DEPENDS miopen-hip rocblas hip_hcc half
)
......
......@@ -50,7 +50,7 @@ RUN pip install cget
RUN pip install https://github.com/pfultz2/rclone/archive/master.tar.gz
# Install hcc
RUN rclone -b sanitizer1 https://github.com/RadeonOpenCompute/hcc.git /hcc
RUN rclone -b roc-2.0.x -c 757fb492517b80e7c86338af5fc1a43d63cb25a9 https://github.com/RadeonOpenCompute/hcc.git /hcc
RUN cget -p $PREFIX install hcc,/hcc
# Use hcc
......
......@@ -8,10 +8,16 @@ def rocmtestnode(variant, name, body) {
mkdir build
cd build
CXX=${compiler} CXXFLAGS='-Werror -Wno-fallback' cmake ${flags} ..
CTEST_PARALLEL_LEVEL=32 make -j32 all doc check
CTEST_PARALLEL_LEVEL=32 make -j32 generate all doc package check
"""
echo cmd
sh cmd
if (compiler == "hcc") {
// Only archive from master or develop
if (env.BRANCH_NAME == "develop" || env.BRANCH_NAME == "master") {
archiveArtifacts artifacts: "build/*.deb", allowEmptyArchive: true, fingerprint: true
}
}
}
node(name) {
stage("checkout ${variant}") {
......@@ -73,7 +79,7 @@ rocmtest tidy: rocmnode('rocmtest') { cmake_build ->
rm -rf build
mkdir build
cd build
CXX='clang++-5.0' cmake ..
CXX=hcc cmake ..
make -j8 -k analyze
'''
}
......@@ -95,11 +101,16 @@ rocmtest tidy: rocmnode('rocmtest') { cmake_build ->
stage('Clang Debug') {
// TODO: Enanle integer
def sanitizers = "undefined"
cmake_build("hcc", "-DCMAKE_BUILD_TYPE=debug -DCMAKE_CXX_FLAGS_DEBUG='-g -fno-omit-frame-pointer -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}'")
def debug_flags = "-g -fno-omit-frame-pointer -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}"
cmake_build("hcc", "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_PYTHON=Off -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'")
}
stage('Clang Release') {
cmake_build("hcc", "-DCMAKE_BUILD_TYPE=release")
}
stage('Clang Release Python 3') {
cmake_build("hcc", "-DCMAKE_BUILD_TYPE=release -DPYTHON_EXECUTABLE=/usr/local/bin/python3")
}
}, gcc5: rocmnode('rocmtest') { cmake_build ->
stage('GCC 5 Debug') {
cmake_build("g++-5", "-DCMAKE_BUILD_TYPE=debug")
......@@ -113,6 +124,19 @@ rocmtest tidy: rocmnode('rocmtest') { cmake_build ->
def cmake_linker_flags = "-DCMAKE_EXE_LINKER_FLAGS='${linker_flags}' -DCMAKE_SHARED_LINKER_FLAGS='${linker_flags}'"
// TODO: Add bounds-strict
def sanitizers = "undefined,address"
cmake_build("g++-7", "-DCMAKE_BUILD_TYPE=debug ${cmake_linker_flags} -DCMAKE_CXX_FLAGS_DEBUG='-g -fno-omit-frame-pointer -fsanitize-address-use-after-scope -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}'")
def debug_flags = "-g -fprofile-arcs -ftest-coverage -fno-omit-frame-pointer -fsanitize-address-use-after-scope -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}"
cmake_build("g++-7", "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_PYTHON=Off ${cmake_linker_flags} -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'")
}
stage('Codecov') {
env.CODECOV_TOKEN="8545af1c-f90b-4345-92a5-0d075503ca56"
sh '''
cd build
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
lcov --list coverage.info
curl -s https://codecov.io/bash | bash
echo "Uploaded"
'''
}
}
......@@ -8,6 +8,7 @@ AMD's graph optimization engine.
* [HIP](https://github.com/ROCm-Developer-Tools/HIP) for running on the GPU
* [Protobuf](https://github.com/google/protobuf) for reading [onxx](https://github.com/onnx/onnx) files
* [Half](http://half.sourceforge.net/) - IEEE 754-based half-precision floating point library
* [pybind11](https://pybind11.readthedocs.io/en/stable/) - for python bindings
## Installing the dependencies
......
ignore:
- "test/"
......@@ -38,7 +38,15 @@
<message>
<id>definePrefix</id>
<severity>style</severity>
<summary>Macros must be prefixed with MIGRAPH_</summary>
<summary>Macros must be prefixed with MIGRAPHX_</summary>
</message>
</rule>
<rule>
<pattern>mutable \w+</pattern>
<message>
<id>MutableVariable</id>
<severity>style</severity>
<summary>Do not create mutable variables.</summary>
</message>
</rule>
<rule>
......@@ -74,7 +82,7 @@
</message>
</rule>
<rule>
<pattern>(fclose|free|hipFree) \(</pattern>
<pattern>\\W(fclose|free|hipFree|hipHostFree|hipFreeArray|hipMemFree|hipStreamDestroy|hipEventDestroy|hipArrayDestroy|hipCtxDestroy|hipDestroyTextureObject|hipDestroySurfaceObject) \(</pattern>
<message>
<id>useManagePointer</id>
<severity>style</severity>
......
pfultz2/rocm-recipes
pcre
danmar/cppcheck@f965e5873 -DHAVE_RULES=1
ROCm-Developer-Tools/HIP@3c7f5dbce24802ec4237e615038daff2909a2e8e
# python/cpython@v3.6.6 -X autotools -H sha256:92aa914572c695c0aeb01b0a214813f414da4b51a371234df514a74761f2bb36
danmar/cppcheck@681cb7dd909d1bfe41796b7616e43265177b9464 -DHAVE_RULES=1
ROCm-Developer-Tools/HIP@fc22ef991ce7cb15821c8ccb4f03cdfc3e7e43cf
python/cpython@v3.6.6 -X autotools -H sha256:92aa914572c695c0aeb01b0a214813f414da4b51a371234df514a74761f2bb36
-f requirements.txt
......@@ -11,6 +11,7 @@ add_library(migraphx
eliminate_contiguous.cpp
eliminate_concat.cpp
fwd_conv_batchnorm_rewrite.cpp
rewrite_rnn.cpp
env.cpp
generate.cpp
instruction.cpp
......@@ -35,6 +36,7 @@ target_include_directories(migraphx SYSTEM PUBLIC $<BUILD_INTERFACE:${HALF_INCLU
set(PACKAGE_DEPENDS)
add_subdirectory(onnx)
add_subdirectory(py)
add_subdirectory(targets/cpu)
if(MIGRAPHX_ENABLE_GPU)
list(APPEND PACKAGE_DEPENDS MIOpen rocblas)
......
......@@ -12,7 +12,7 @@ void auto_contiguous::apply(program& p) const
for(auto ins : iterator_for(p))
{
shape s = ins->get_shape();
if(not s.standard())
if(not s.standard() and s.elements() != 0)
{
auto c = p.insert_instruction(std::next(ins), op::contiguous{}, ins);
p.replace_instruction(ins, c);
......
......@@ -13,7 +13,7 @@ struct match_const_add
return match::name("add")(match::args(match::name("@literal"), match::name("@literal")));
}
void apply(program& p, match::matcher_result r) const
void apply(program& p, const match::matcher_result& r) const
{
auto ins = r.result;
auto arg1 = ins->inputs().at(0)->get_literal();
......
......@@ -41,8 +41,9 @@ void dead_code_elimination::apply(program& p) const
// Skip the last instruction
if(i == last)
break;
// Skip instruction with empty shape as output unless its a builtin
if(i->get_shape().elements() == 0 and not(i->name().front() == '@'))
// Skip instruction with empty shape as output unless its a builtin or undefined
if(i->get_shape().elements() == 0 and not(i->name().front() == '@') and
not(i->name() == "undefined"))
continue;
assert(bidistance(p, i, last) > 0);
fix([&](auto self, auto leaf) {
......
......@@ -13,8 +13,6 @@ inline namespace MIGRAPHX_INLINE_NS {
void eliminate_allocation::apply(program& p) const
{
assert(alignment > 0);
if(!enabled(MIGRAPHX_DISABLE_MEMORY_COLORING{}))
return;
std::size_t n = 0;
std::vector<std::pair<instruction_ref, std::size_t>> allocs;
......@@ -27,13 +25,16 @@ void eliminate_allocation::apply(program& p) const
std::size_t padding = (alignment - (size % alignment)) % alignment;
n += size + padding;
}
auto mem = p.add_parameter("memory", shape{shape::int8_type, {n}});
for(auto&& pp : allocs)
if(n > 0)
{
auto ins = pp.first;
auto s = ins->get_shape();
auto offset = pp.second;
p.replace_instruction(ins, op::load{s, offset}, mem);
auto mem = p.add_parameter("memory", shape{shape::int8_type, {n}});
for(auto&& pp : allocs)
{
auto ins = pp.first;
auto s = ins->get_shape();
auto offset = pp.second;
p.replace_instruction(ins, op::load{s, offset}, mem);
}
}
}
......
......@@ -36,14 +36,17 @@ void eliminate_concat::apply(program& p) const
// Where are the allocations for the tensors to be concatenated?
std::vector<instruction_ref> allocations;
for(auto ins2 = ins->inputs().begin(); ins2 != ins->inputs().end() - 1; ins2++)
{
auto last2 = (*ins2)->inputs().back();
if(last2->name() == concat_opt.allocate())
{
allocations.push_back(last2);
}
}
std::transform(
ins->inputs().begin(),
std::prev(ins->inputs().end()),
std::back_inserter(allocations),
[&](instruction_ref x) { return instruction::get_output_alias(x, true); });
if(std::any_of(allocations.begin(), allocations.end(), [&](auto x) {
return x->name() != concat_opt.allocate();
}))
continue;
// Need to sort the allocations, so that we know where to
// insert the "super"-allocation
std::sort(
......@@ -51,15 +54,15 @@ void eliminate_concat::apply(program& p) const
return std::distance(p.begin(), x) < std::distance(p.begin(), y);
});
// Move "super" allocation to the front
auto first = allocations.front();
auto super = p.move_instruction(last, first);
auto first = allocations.front();
auto super = p.move_instruction(last, first);
// Replace each allocation with a load
std::size_t offset = 0;
for(auto x : allocations)
for(auto alloc : allocations)
{
migraphx::op::load op{x->get_shape(), offset};
// migraphx::op::load op{x->get_shape(), 0};
p.replace_instruction(x, op, {super});
offset += x->get_shape().bytes();
op::load op{alloc->get_shape(), offset};
p.replace_instruction(alloc, op, {super});
offset += alloc->get_shape().bytes();
}
std::vector<instruction_ref> args = {super};
std::copy(ins->inputs().begin(), ins->inputs().end() - 1, std::back_inserter(args));
......
......@@ -27,6 +27,13 @@ void eliminate_contiguous::apply(program& p) const
{
for(auto ins : iterator_for(p))
{
// skip the reshape operator for now, since there is a bug
// for the transpose followed by a reshape
if(ins->name() == "reshape")
{
continue;
}
// Make a copy so we can modify it while we iterate
auto args = ins->inputs();
for(auto arg : ins->inputs())
......
......@@ -5,6 +5,10 @@
namespace migraphx {
inline namespace MIGRAPHX_INLINE_NS {
// Forward declare any_cast
template <class T>
const T& any_cast(const T&);
namespace detail {
template <class U>
......
......@@ -15,11 +15,19 @@ struct check_context
std::string name() const { return "check_context"; }
shape compute_shape(const std::vector<shape>&) const { return {}; }
argument compute(context& ctx, const shape&, const std::vector<argument>&) const
{
this->check(ctx);
return {};
}
void finalize(context& ctx, const shape&, const std::vector<shape>&) const
{
this->check(ctx);
}
void check(context& ctx) const
{
T* x = any_cast<T>(&ctx);
if(x == nullptr)
MIGRAPHX_THROW(std::string("Unexpected context type: ") + ctx.type_id().name());
return {};
}
};
......
......@@ -119,6 +119,13 @@ struct concat_optimization
return (*this).private_detail_te_get_handle().get_concat(op);
}
friend bool is_shared(const concat_optimization& private_detail_x,
const concat_optimization& private_detail_y)
{
return private_detail_x.private_detail_te_handle_mem_var ==
private_detail_y.private_detail_te_handle_mem_var;
}
private:
struct private_detail_te_handle_base_type
{
......@@ -235,6 +242,7 @@ inline const ValueType& any_cast(const concat_optimization& x)
}
#endif
} // namespace MIGRAPHX_INLINE_NS
} // namespace migraphx
......
......@@ -95,7 +95,13 @@ struct context
void finish() const
{
assert((*this).private_detail_te_handle_mem_var);
return (*this).private_detail_te_get_handle().finish();
(*this).private_detail_te_get_handle().finish();
}
friend bool is_shared(const context& private_detail_x, const context& private_detail_y)
{
return private_detail_x.private_detail_te_handle_mem_var ==
private_detail_y.private_detail_te_handle_mem_var;
}
private:
......@@ -136,7 +142,7 @@ struct context
const std::type_info& type() const override { return typeid(private_detail_te_value); }
void finish() const override { return private_detail_te_value.finish(); }
void finish() const override { private_detail_te_value.finish(); }
PrivateDetailTypeErasedT private_detail_te_value;
};
......
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