From f99999a010d60ddbc2b2e2ffd713bec8468b35e2 Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 3 Dec 2024 19:34:56 -0600 Subject: [PATCH 1/3] Use and keyword consistently --- .clang-tidy | 4 ++++ src/apply_alpha_beta.cpp | 2 +- src/driver/argument_parser.hpp | 2 +- src/driver/perf.cpp | 2 +- src/include/migraphx/op/nonmaxsuppression.hpp | 2 +- src/include/migraphx/raw_data.hpp | 4 ++-- src/include/migraphx/requires.hpp | 2 +- src/include/migraphx/tensor_view.hpp | 4 ++-- src/instruction.cpp | 4 ++-- src/program.cpp | 4 ++-- src/simplify_algebra.cpp | 2 +- src/targets/gpu/kernels/include/migraphx/kernels/dpp.hpp | 2 +- src/targets/gpu/kernels/include/migraphx/kernels/float8.hpp | 2 +- src/targets/gpu/kernels/include/migraphx/kernels/math.hpp | 2 +- src/targets/ref/lowering.cpp | 2 +- test/gpu/fuse_mlir.cpp | 2 +- test/simplify_algebra_test.cpp | 2 +- 17 files changed, 24 insertions(+), 20 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index f4262fd3c13..ef195c60ac9 100755 --- a/.clang-tidy +++ b/.clang-tidy @@ -117,3 +117,7 @@ CheckOptions: value: MIGRAPHX_ - key: readability-identifier-naming.ConstexprMethodIgnoredRegexp value: 'quiet_NaN|signaling_NaN' + - key: readability-operators-representation.BinaryOperators + value: 'and;or;not' + - key: readability-operators-representation.OverloadedOperators + value: 'and;or;not' diff --git a/src/apply_alpha_beta.cpp b/src/apply_alpha_beta.cpp index 7947ce29758..2b744455ab8 100644 --- a/src/apply_alpha_beta.cpp +++ b/src/apply_alpha_beta.cpp @@ -51,7 +51,7 @@ instruction_ref insert_apply_alpha_beta(module& m, auto op_res = m.insert_instruction(pos, op, a, b); if(args.size() == 3) { - if(not float_equal(beta.at(0), 0.0) && args[2]->get_shape().elements() > 0) + if(not float_equal(beta.at(0), 0.0) and args[2]->get_shape().elements() > 0) { auto out_lens = op_res->get_shape().lens(); auto c = args[2]; diff --git a/src/driver/argument_parser.hpp b/src/driver/argument_parser.hpp index b1b3f5a4f4c..4b26ff6d6e6 100644 --- a/src/driver/argument_parser.hpp +++ b/src/driver/argument_parser.hpp @@ -433,7 +433,7 @@ struct argument_parser argument* input_argument = self.find_argument([](const auto& arg) { return arg.flags.empty(); }); auto required_usages = get_argument_usages(get_required_arguments()); - if(required_usages.empty() && input_argument) + if(required_usages.empty() and input_argument) required_usages.push_back(input_argument->metavar); required_usages.insert(required_usages.begin(), ""); print_usage(required_usages); diff --git a/src/driver/perf.cpp b/src/driver/perf.cpp index d9e53b1705e..4b647532dd1 100644 --- a/src/driver/perf.cpp +++ b/src/driver/perf.cpp @@ -127,7 +127,7 @@ bool is_offload_copy_set(const program& p) for(const auto& j : return_args) { auto alias_ins = instruction::get_output_alias(j, true); - if((alias_ins->name() == "@param" && param_ins.erase(alias_ins) == 0) or + if((alias_ins->name() == "@param" and param_ins.erase(alias_ins) == 0) or (alias_ins->name() != "hip::copy_from_gpu")) return false; } diff --git a/src/include/migraphx/op/nonmaxsuppression.hpp b/src/include/migraphx/op/nonmaxsuppression.hpp index 59fd2d0d750..29fe087eb2a 100644 --- a/src/include/migraphx/op/nonmaxsuppression.hpp +++ b/src/include/migraphx/op/nonmaxsuppression.hpp @@ -335,7 +335,7 @@ struct nonmaxsuppression auto batch_boxes_start = boxes.begin() + batch_idx * num_boxes * 4; auto boxes_heap = filter_boxes_by_score(scores_start, num_boxes, score_threshold); int64_t selected_boxes_inside_class = 0; - while(not boxes_heap.empty() && + while(not boxes_heap.empty() and selected_boxes_inside_class < max_output_boxes_per_class) { // select next top scorer box and remove any boxes from boxes_heap that exceeds IOU diff --git a/src/include/migraphx/raw_data.hpp b/src/include/migraphx/raw_data.hpp index 19373bab6d4..0d4662b0add 100644 --- a/src/include/migraphx/raw_data.hpp +++ b/src/include/migraphx/raw_data.hpp @@ -275,7 +275,7 @@ auto visit_all(const std::vector& x) template {} && + MIGRAPHX_REQUIRES(std::is_base_of{} and std::is_base_of{})> bool operator==(const T& x, const U& y) { @@ -294,7 +294,7 @@ bool operator==(const T& x, const U& y) template {} && + MIGRAPHX_REQUIRES(std::is_base_of{} and std::is_base_of{})> bool operator!=(const T& x, const U& y) { diff --git a/src/include/migraphx/requires.hpp b/src/include/migraphx/requires.hpp index 2d8607129cd..38e991bb5c4 100644 --- a/src/include/migraphx/requires.hpp +++ b/src/include/migraphx/requires.hpp @@ -49,7 +49,7 @@ using bool_c = std::integral_constant; #else #define MIGRAPHX_REQUIRES(...) \ long MIGRAPHX_REQUIRES_VAR() = __LINE__, \ - typename std::enable_if<(MIGRAPHX_REQUIRES_VAR() == __LINE__ && \ + typename std::enable_if<(MIGRAPHX_REQUIRES_VAR() == __LINE__ and \ (migraphx::and_<__VA_ARGS__>{})), \ int>::type = 0 #define MIGRAPHX_CLASS_REQUIRES(...) typename std::enable_if<(migraphx::and_<__VA_ARGS__>{})>::type diff --git a/src/include/migraphx/tensor_view.hpp b/src/include/migraphx/tensor_view.hpp index 9c5ff978e83..71ade9b20cc 100644 --- a/src/include/migraphx/tensor_view.hpp +++ b/src/include/migraphx/tensor_view.hpp @@ -101,13 +101,13 @@ struct tensor_view T& operator[](std::size_t i) { - assert(not this->empty() && i < this->size()); + assert(not this->empty() and i < this->size()); return m_data[m_shape.index(i)]; } const T& operator[](std::size_t i) const { - assert(not this->empty() && i < this->size()); + assert(not this->empty() and i < this->size()); return m_data[m_shape.index(i)]; } diff --git a/src/instruction.cpp b/src/instruction.cpp index 235c551d709..f91129b8903 100644 --- a/src/instruction.cpp +++ b/src/instruction.cpp @@ -127,7 +127,7 @@ bool operator==(const instruction& i, instruction_ref ref) bool instruction::valid(instruction_ref start, bool check_order) const { - return valid() && std::all_of(arguments.begin(), arguments.end(), [&](instruction_ref i) { + return valid() and std::all_of(arguments.begin(), arguments.end(), [&](instruction_ref i) { auto self = std::find(i->outputs().begin(), i->outputs().end(), *this); bool ret = self != i->outputs().end(); if(check_order) @@ -162,7 +162,7 @@ bool instruction::valid() const } } - return (result == computed) && + return (result == computed) and std::all_of(output.begin(), output.end(), [&](instruction_ref i) { return std::find(i->inputs().begin(), i->inputs().end(), *this) != i->inputs().end(); }); diff --git a/src/program.cpp b/src/program.cpp index b39f3936371..a9e3ff6e4df 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -1204,12 +1204,12 @@ bool references_instruction(Map& m, const instruction& ins, const std::string& n void program::remove_module(const std::string& name) { // cppcheck-suppress assertWithSideEffect - assert(is_unused_module(impl->modules, generic_get_modules(this->get_main_module()), name) && + assert(is_unused_module(impl->modules, generic_get_modules(this->get_main_module()), name) and "Module used in program"); assert(std::none_of( impl->modules.at(name).begin(), impl->modules.at(name).end(), - [&](auto&& ins) { return references_instruction(impl->modules, ins, name); }) && + [&](auto&& ins) { return references_instruction(impl->modules, ins, name); }) and "Instruction referenced in another module"); // if an instruction has an input out side of the current module, need to remove diff --git a/src/simplify_algebra.cpp b/src/simplify_algebra.cpp index 4d3d59a0364..9753a21217c 100644 --- a/src/simplify_algebra.cpp +++ b/src/simplify_algebra.cpp @@ -1279,7 +1279,7 @@ struct find_splits { assert(not std::none_of(start->inputs().begin(), start->inputs().end(), [](auto i) { return i->name() == "slice"; - }) && "one argument must be a split"); + }) and "one argument must be a split"); split_idx = get_binary_op_split_idx(group, splits); assert(split_idx < 2); diff --git a/src/targets/gpu/kernels/include/migraphx/kernels/dpp.hpp b/src/targets/gpu/kernels/include/migraphx/kernels/dpp.hpp index 8cf950f2d24..c75ab3d6bda 100644 --- a/src/targets/gpu/kernels/include/migraphx/kernels/dpp.hpp +++ b/src/targets/gpu/kernels/include/migraphx/kernels/dpp.hpp @@ -30,7 +30,7 @@ namespace migraphx { -constexpr bool is_power_of_2(unsigned int x) { return x > 0 && (x & (x - 1)) == 0u; } +constexpr bool is_power_of_2(unsigned int x) { return x > 0 and (x & (x - 1)) == 0u; } #ifndef MIGRAPHX_HAS_DPP #define MIGRAPHX_HAS_DPP 1 diff --git a/src/targets/gpu/kernels/include/migraphx/kernels/float8.hpp b/src/targets/gpu/kernels/include/migraphx/kernels/float8.hpp index e94d3573fd6..5ebe534729f 100644 --- a/src/targets/gpu/kernels/include/migraphx/kernels/float8.hpp +++ b/src/targets/gpu/kernels/include/migraphx/kernels/float8.hpp @@ -296,7 +296,7 @@ struct float8 } else { - return (data == 0x00) || (data == 0x80); + return (data == 0x00) or (data == 0x80); } } diff --git a/src/targets/gpu/kernels/include/migraphx/kernels/math.hpp b/src/targets/gpu/kernels/include/migraphx/kernels/math.hpp index 611ac93a721..f14d9b1c8cd 100644 --- a/src/targets/gpu/kernels/include/migraphx/kernels/math.hpp +++ b/src/targets/gpu/kernels/include/migraphx/kernels/math.hpp @@ -105,7 +105,7 @@ constexpr T as_float(T x) template \ auto __device__ name(migraphx::vec x, Ts... xs) \ MIGRAPHX_RETURNS(migraphx::vec{fname(x, xs...)}); \ - template 2))> \ + template 2))> \ auto __device__ name(migraphx::vec x, Ts... xs) \ { \ return vec_packed_transform<2>(x, xs...)( \ diff --git a/src/targets/ref/lowering.cpp b/src/targets/ref/lowering.cpp index cbeed44bb9f..47db653763b 100644 --- a/src/targets/ref/lowering.cpp +++ b/src/targets/ref/lowering.cpp @@ -184,7 +184,7 @@ struct ref_im2col kernel_w)([&](std::size_t c, std::size_t koffset, std::size_t loffset) { auto idx = iinput + long(koffset) - kdiv2_h; auto jdx = jinput + long(loffset) - kdiv2_w; - col(ldx, p) = ((idx >= 0) && (idx < height) && (jdx >= 0) && (jdx < width)) + col(ldx, p) = ((idx >= 0) and (idx < height) and (jdx >= 0) and (jdx < width)) ? input(0, c, idx, jdx) : 0; p++; diff --git a/test/gpu/fuse_mlir.cpp b/test/gpu/fuse_mlir.cpp index 7532cc5f914..f48a0a2e952 100644 --- a/test/gpu/fuse_mlir.cpp +++ b/test/gpu/fuse_mlir.cpp @@ -60,7 +60,7 @@ migraphx::instruction_ref add_mlir(migraphx::program& p, std::vector arg_names, F f) { - assert(inputs.size() == arg_names.size() && "One interior parameter name given per input."); + assert(inputs.size() == arg_names.size() and "One interior parameter name given per input."); auto* mm = p.get_main_module(); auto* pm = p.create_module(name); pm->set_bypass(); diff --git a/test/simplify_algebra_test.cpp b/test/simplify_algebra_test.cpp index a0c5d51690b..b6ecdf0060c 100644 --- a/test/simplify_algebra_test.cpp +++ b/test/simplify_algebra_test.cpp @@ -146,7 +146,7 @@ TEST_CASE(simplify_zero_add_constant) } run_pass(m3); - EXPECT((m1 == m2) && (m2 == m3)); + EXPECT((m1 == m2) and (m2 == m3)); } TEST_CASE(simplify_add_broadcast1) From a5261762278ef88ef083db35f3ec8a257cb3b8fe Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 3 Dec 2024 19:36:59 -0600 Subject: [PATCH 2/3] Format --- src/include/migraphx/requires.hpp | 6 +++--- src/targets/gpu/kernels/include/migraphx/kernels/math.hpp | 2 +- src/targets/ref/lowering.cpp | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/include/migraphx/requires.hpp b/src/include/migraphx/requires.hpp index 38e991bb5c4..f1f365d405f 100644 --- a/src/include/migraphx/requires.hpp +++ b/src/include/migraphx/requires.hpp @@ -47,10 +47,10 @@ using bool_c = std::integral_constant; #define MIGRAPHX_REQUIRES(...) class = void #define MIGRAPHX_CLASS_REQUIRES(...) void #else -#define MIGRAPHX_REQUIRES(...) \ - long MIGRAPHX_REQUIRES_VAR() = __LINE__, \ +#define MIGRAPHX_REQUIRES(...) \ + long MIGRAPHX_REQUIRES_VAR() = __LINE__, \ typename std::enable_if<(MIGRAPHX_REQUIRES_VAR() == __LINE__ and \ - (migraphx::and_<__VA_ARGS__>{})), \ + (migraphx::and_<__VA_ARGS__>{})), \ int>::type = 0 #define MIGRAPHX_CLASS_REQUIRES(...) typename std::enable_if<(migraphx::and_<__VA_ARGS__>{})>::type #endif diff --git a/src/targets/gpu/kernels/include/migraphx/kernels/math.hpp b/src/targets/gpu/kernels/include/migraphx/kernels/math.hpp index f14d9b1c8cd..68172dbbd47 100644 --- a/src/targets/gpu/kernels/include/migraphx/kernels/math.hpp +++ b/src/targets/gpu/kernels/include/migraphx/kernels/math.hpp @@ -105,7 +105,7 @@ constexpr T as_float(T x) template \ auto __device__ name(migraphx::vec x, Ts... xs) \ MIGRAPHX_RETURNS(migraphx::vec{fname(x, xs...)}); \ - template 2))> \ + template 2))> \ auto __device__ name(migraphx::vec x, Ts... xs) \ { \ return vec_packed_transform<2>(x, xs...)( \ diff --git a/src/targets/ref/lowering.cpp b/src/targets/ref/lowering.cpp index 47db653763b..05655735eca 100644 --- a/src/targets/ref/lowering.cpp +++ b/src/targets/ref/lowering.cpp @@ -184,9 +184,10 @@ struct ref_im2col kernel_w)([&](std::size_t c, std::size_t koffset, std::size_t loffset) { auto idx = iinput + long(koffset) - kdiv2_h; auto jdx = jinput + long(loffset) - kdiv2_w; - col(ldx, p) = ((idx >= 0) and (idx < height) and (jdx >= 0) and (jdx < width)) - ? input(0, c, idx, jdx) - : 0; + col(ldx, p) = + ((idx >= 0) and (idx < height) and (jdx >= 0) and (jdx < width)) + ? input(0, c, idx, jdx) + : 0; p++; }); } From fb35b3c83bd84e0e05c69341b03ec697d588682f Mon Sep 17 00:00:00 2001 From: Paul Date: Tue, 3 Dec 2024 19:37:16 -0600 Subject: [PATCH 3/3] Update license --- src/apply_alpha_beta.cpp | 2 +- src/driver/argument_parser.hpp | 2 +- src/include/migraphx/op/nonmaxsuppression.hpp | 2 +- src/include/migraphx/requires.hpp | 2 +- src/targets/ref/lowering.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/apply_alpha_beta.cpp b/src/apply_alpha_beta.cpp index 2b744455ab8..628b4a74ec6 100644 --- a/src/apply_alpha_beta.cpp +++ b/src/apply_alpha_beta.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2024 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 diff --git a/src/driver/argument_parser.hpp b/src/driver/argument_parser.hpp index 4b26ff6d6e6..4ca6c9f8c01 100644 --- a/src/driver/argument_parser.hpp +++ b/src/driver/argument_parser.hpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2024 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 diff --git a/src/include/migraphx/op/nonmaxsuppression.hpp b/src/include/migraphx/op/nonmaxsuppression.hpp index 29fe087eb2a..9a8f62da2a6 100644 --- a/src/include/migraphx/op/nonmaxsuppression.hpp +++ b/src/include/migraphx/op/nonmaxsuppression.hpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2024 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 diff --git a/src/include/migraphx/requires.hpp b/src/include/migraphx/requires.hpp index f1f365d405f..bc9cdf241ee 100644 --- a/src/include/migraphx/requires.hpp +++ b/src/include/migraphx/requires.hpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2024 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 diff --git a/src/targets/ref/lowering.cpp b/src/targets/ref/lowering.cpp index 05655735eca..ec35971ad6c 100644 --- a/src/targets/ref/lowering.cpp +++ b/src/targets/ref/lowering.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2023 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2024 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