From bdef7adb0317f060fcb3053df4499addc05c6ac2 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Wed, 4 Oct 2023 00:19:32 +0200 Subject: [PATCH 1/3] a few c++ fixes to allow compilation on Windows --- src/api/api.cpp | 1 + src/api/include/migraphx/migraphx.h | 1 + src/api/include/migraphx/migraphx.hpp | 2 +- src/driver/main.cpp | 1 + src/include/migraphx/auto_register.hpp | 7 +++---- src/include/migraphx/config.hpp | 4 ++++ src/include/migraphx/filesystem.hpp | 11 +++++++++++ src/include/migraphx/float_equal.hpp | 3 --- src/include/migraphx/generate.hpp | 4 ++-- src/include/migraphx/matcher.hpp | 7 +++++++ src/include/migraphx/op/nonmaxsuppression.hpp | 1 + src/include/migraphx/op/roialign.hpp | 1 + src/include/migraphx/optional.hpp | 11 +++++++++++ src/include/migraphx/run_loop.hpp | 1 + src/include/migraphx/source_location.hpp | 1 + src/include/migraphx/type_name.hpp | 2 +- src/onnx/onnx_parser.cpp | 2 +- src/targets/cpu/include/migraphx/cpu/pointwise.hpp | 1 + src/targets/gpu/hiprtc/main.cpp | 1 + test/include/test.hpp | 2 +- test/multi_target/multitarget_test.cpp | 1 - test/promote_literals_test.cpp | 1 + tools/api/api.cpp | 1 + tools/api/migraphx.h | 1 + 24 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/api/api.cpp b/src/api/api.cpp index 7a1bbabf1f5..dbb7256a8db 100644 --- a/src/api/api.cpp +++ b/src/api/api.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include namespace migraphx { diff --git a/src/api/include/migraphx/migraphx.h b/src/api/include/migraphx/migraphx.h index bb26ec2a3d9..6ab451a1509 100644 --- a/src/api/include/migraphx/migraphx.h +++ b/src/api/include/migraphx/migraphx.h @@ -26,6 +26,7 @@ #include #include +#include #include diff --git a/src/api/include/migraphx/migraphx.hpp b/src/api/include/migraphx/migraphx.hpp index 7e37defcb1e..a588e47445a 100644 --- a/src/api/include/migraphx/migraphx.hpp +++ b/src/api/include/migraphx/migraphx.hpp @@ -66,7 +66,7 @@ template std::string compute_type_name() { std::string name; -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) name = typeid(PrivateMigraphTypeNameProbe).name(); name = name.substr(7); #else diff --git a/src/driver/main.cpp b/src/driver/main.cpp index 4a920d66618..4ecd8c392c1 100644 --- a/src/driver/main.cpp +++ b/src/driver/main.cpp @@ -39,6 +39,7 @@ #include #include +#include #include #include #include diff --git a/src/include/migraphx/auto_register.hpp b/src/include/migraphx/auto_register.hpp index 9011627c66e..d519a9da4b4 100644 --- a/src/include/migraphx/auto_register.hpp +++ b/src/include/migraphx/auto_register.hpp @@ -62,10 +62,9 @@ const int auto_register::static_register = auto_register_action 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 diff --git a/src/include/migraphx/config.hpp b/src/include/migraphx/config.hpp index 7b045a4a16d..e5f12be0800 100644 --- a/src/include/migraphx/config.hpp +++ b/src/include/migraphx/config.hpp @@ -26,6 +26,10 @@ #include +#if defined(_MSC_VER) && !defined(__clang__) +#include +#endif + #if !defined(MIGRAPHX_USE_CLANG_TIDY) && !defined(DOXYGEN) #ifdef BUILD_DEV diff --git a/src/include/migraphx/filesystem.hpp b/src/include/migraphx/filesystem.hpp index 5b5950d0511..1eab67a2008 100644 --- a/src/include/migraphx/filesystem.hpp +++ b/src/include/migraphx/filesystem.hpp @@ -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() && __cplusplus >= 201703L #define MIGRAPHX_HAS_FILESYSTEM 1 diff --git a/src/include/migraphx/float_equal.hpp b/src/include/migraphx/float_equal.hpp index da1fc0c2c64..75fd69c37e1 100644 --- a/src/include/migraphx/float_equal.hpp +++ b/src/include/migraphx/float_equal.hpp @@ -27,9 +27,6 @@ #include #include #include -#ifdef _MSC_VER -#include -#endif #include #include diff --git a/src/include/migraphx/generate.hpp b/src/include/migraphx/generate.hpp index d6e58b96ec0..a2158ca8108 100644 --- a/src/include/migraphx/generate.hpp +++ b/src/include/migraphx/generate.hpp @@ -48,7 +48,7 @@ constexpr T normalize(unsigned long z) template {} and not is_floating_point{})> 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 {})> constexpr T normalize(unsigned long z) { - const auto max = 1UL << (sizeof(T) * 5); + const auto max = 1ULL << (sizeof(T) * 5); return z % max; } diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index 2d0f26a5d6b..dbb38b837a7 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -307,6 +308,12 @@ struct matcher_result { } + instruction_container& operator=(const std::unordered_map& x) + { + ins_map = x; + return *this; + } + instruction_ref operator[](const std::string& name) const { auto it = ins_map.find(name); diff --git a/src/include/migraphx/op/nonmaxsuppression.hpp b/src/include/migraphx/op/nonmaxsuppression.hpp index 872120f8551..1feb2482ffa 100644 --- a/src/include/migraphx/op/nonmaxsuppression.hpp +++ b/src/include/migraphx/op/nonmaxsuppression.hpp @@ -24,6 +24,7 @@ #ifndef MIGRAPHX_GUARD_OPERATORS_NONMAXSUPPRESSION_HPP #define MIGRAPHX_GUARD_OPERATORS_NONMAXSUPPRESSION_HPP +#include #include #include #include diff --git a/src/include/migraphx/op/roialign.hpp b/src/include/migraphx/op/roialign.hpp index 1dcb13ee4a5..d66e8f0feeb 100644 --- a/src/include/migraphx/op/roialign.hpp +++ b/src/include/migraphx/op/roialign.hpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include diff --git a/src/include/migraphx/optional.hpp b/src/include/migraphx/optional.hpp index bac25e26725..f53ca37029c 100644 --- a/src/include/migraphx/optional.hpp +++ b/src/include/migraphx/optional.hpp @@ -29,6 +29,17 @@ #if defined(CPPCHECK) #define MIGRAPHX_HAS_OPTIONAL 1 #define MIGRAPHX_HAS_OPTIONAL_TS 1 +#elif defined(_WIN32) +#if _MSC_VER >= 1920 +#define MIGRAPHX_HAS_OPTIONAL 1 +#define MIGRAPHX_HAS_OPTIONAL_TS 0 +#elif _MSC_VER >= 1900 +#define MIGRAPHX_HAS_OPTIONAL 0 +#define MIGRAPHX_HAS_OPTIONAL_TS 1 +#else +#define MIGRAPHX_HAS_OPTIONAL 0 +#define MIGRAPHX_HAS_OPTIONAL_TS 0 +#endif #elif defined(__has_include) #if __has_include() && __cplusplus >= 201703L #define MIGRAPHX_HAS_OPTIONAL 1 diff --git a/src/include/migraphx/run_loop.hpp b/src/include/migraphx/run_loop.hpp index ac4e3ffd596..bcb78a41056 100644 --- a/src/include/migraphx/run_loop.hpp +++ b/src/include/migraphx/run_loop.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include namespace migraphx { diff --git a/src/include/migraphx/source_location.hpp b/src/include/migraphx/source_location.hpp index facf9c4fac6..971bc3278a4 100644 --- a/src/include/migraphx/source_location.hpp +++ b/src/include/migraphx/source_location.hpp @@ -24,6 +24,7 @@ #ifndef MIGRAPHX_GUARD_MIGRAPHX_SOURCE_LOCATION_HPP #define MIGRAPHX_GUARD_MIGRAPHX_SOURCE_LOCATION_HPP +#include #include #if defined(CPPCHECK) diff --git a/src/include/migraphx/type_name.hpp b/src/include/migraphx/type_name.hpp index 3e039db3669..492ffdbeb6c 100644 --- a/src/include/migraphx/type_name.hpp +++ b/src/include/migraphx/type_name.hpp @@ -34,7 +34,7 @@ template std::string compute_type_name() { std::string name; -#ifdef _MSC_VER +#if defined(_MSC_VER) && !defined(__clang__) name = typeid(PrivateMigraphTypeNameProbe).name(); name = name.substr(7); #else diff --git a/src/onnx/onnx_parser.cpp b/src/onnx/onnx_parser.cpp index 0a28fcf926f..0b99267c182 100644 --- a/src/onnx/onnx_parser.cpp +++ b/src/onnx/onnx_parser.cpp @@ -244,7 +244,7 @@ void onnx_parser::parse_from(std::istream& is, std::string name) this->filename = std::move(name); auto parent_path = fs::path(this->filename).parent_path(); if(not parent_path.empty()) - this->path = parent_path; + this->path = parent_path.string(); onnx::ModelProto model; if(model.ParseFromIstream(&is)) diff --git a/src/targets/cpu/include/migraphx/cpu/pointwise.hpp b/src/targets/cpu/include/migraphx/cpu/pointwise.hpp index c3e764bcb0a..9e2dfafedf1 100644 --- a/src/targets/cpu/include/migraphx/cpu/pointwise.hpp +++ b/src/targets/cpu/include/migraphx/cpu/pointwise.hpp @@ -24,6 +24,7 @@ #ifndef MIGRAPHX_GUARD_AMDMIGRAPHX_CPU_POINTWISE_HPP #define MIGRAPHX_GUARD_AMDMIGRAPHX_CPU_POINTWISE_HPP +#include #include #include #include diff --git a/src/targets/gpu/hiprtc/main.cpp b/src/targets/gpu/hiprtc/main.cpp index ef7138945a8..209a8da38df 100644 --- a/src/targets/gpu/hiprtc/main.cpp +++ b/src/targets/gpu/hiprtc/main.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/test/include/test.hpp b/test/include/test.hpp index 1228f888e0b..cc2416cd407 100644 --- a/test/include/test.hpp +++ b/test/include/test.hpp @@ -333,7 +333,7 @@ enum class color bg_blue = 44, bg_default = 49 }; -inline std::ostream& operator<<(std::ostream& os, const color& c) +inline std::ostream& operator<<(std::ostream& os, [[maybe_unused]] const color& c) { #ifndef _WIN32 static const bool use_color = isatty(STDOUT_FILENO) != 0; diff --git a/test/multi_target/multitarget_test.cpp b/test/multi_target/multitarget_test.cpp index 6b25405ac87..c375612d760 100644 --- a/test/multi_target/multitarget_test.cpp +++ b/test/multi_target/multitarget_test.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include #include diff --git a/test/promote_literals_test.cpp b/test/promote_literals_test.cpp index 5d28dee962c..638217f73cf 100644 --- a/test/promote_literals_test.cpp +++ b/test/promote_literals_test.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/tools/api/api.cpp b/tools/api/api.cpp index c9a8bf16623..096bced44fc 100644 --- a/tools/api/api.cpp +++ b/tools/api/api.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include namespace migraphx { diff --git a/tools/api/migraphx.h b/tools/api/migraphx.h index 34ce75b7a65..8179cfffd52 100644 --- a/tools/api/migraphx.h +++ b/tools/api/migraphx.h @@ -26,6 +26,7 @@ #include #include +#include #include From ba2a9a232e64dd6119a796c84cc5975d51629149 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Wed, 4 Oct 2023 15:19:52 +0200 Subject: [PATCH 2/3] incorporate code changes from the review feedback --- src/include/migraphx/matcher.hpp | 6 ------ test/verify/run_verify.cpp | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index dbb38b837a7..5237dc9c5c6 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -308,12 +308,6 @@ struct matcher_result { } - instruction_container& operator=(const std::unordered_map& x) - { - ins_map = x; - return *this; - } - instruction_ref operator[](const std::string& name) const { auto it = ins_map.find(name); diff --git a/test/verify/run_verify.cpp b/test/verify/run_verify.cpp index 66a7f197639..2e56c900d0f 100644 --- a/test/verify/run_verify.cpp +++ b/test/verify/run_verify.cpp @@ -44,8 +44,8 @@ MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_DUMP_TEST) // An improved async, that doesn't block template -std::future::type> detach_async(Function&& f, - bool parallel = true) +std::future> detach_async(Function&& f, + bool parallel = true) { if(parallel) { From e599b939a0a2ca689bc1e6b389e773ced805764e Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Sun, 8 Oct 2023 01:22:25 +0200 Subject: [PATCH 3/3] incorporate review feedback --- src/driver/main.cpp | 1 - src/include/migraphx/config.hpp | 3 --- src/include/migraphx/instruction_ref.hpp | 4 ++++ test/include/test.hpp | 4 +++- test/promote_literals_test.cpp | 1 - test/verify/run_verify.cpp | 3 +-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/driver/main.cpp b/src/driver/main.cpp index 4ecd8c392c1..4a920d66618 100644 --- a/src/driver/main.cpp +++ b/src/driver/main.cpp @@ -39,7 +39,6 @@ #include #include -#include #include #include #include diff --git a/src/include/migraphx/config.hpp b/src/include/migraphx/config.hpp index e5f12be0800..9a170e387e1 100644 --- a/src/include/migraphx/config.hpp +++ b/src/include/migraphx/config.hpp @@ -25,10 +25,7 @@ #define MIGRAPHX_GUARD_CONFIG_HPP #include - -#if defined(_MSC_VER) && !defined(__clang__) #include -#endif #if !defined(MIGRAPHX_USE_CLANG_TIDY) && !defined(DOXYGEN) diff --git a/src/include/migraphx/instruction_ref.hpp b/src/include/migraphx/instruction_ref.hpp index 9970dce96e1..67bace9b7d2 100644 --- a/src/include/migraphx/instruction_ref.hpp +++ b/src/include/migraphx/instruction_ref.hpp @@ -65,4 +65,8 @@ struct equal_to // NOLINT } // namespace std +#ifdef _MSC_VER +#include +#endif + #endif diff --git a/test/include/test.hpp b/test/include/test.hpp index cc2416cd407..b3d33e6af6c 100644 --- a/test/include/test.hpp +++ b/test/include/test.hpp @@ -333,12 +333,14 @@ enum class color bg_blue = 44, bg_default = 49 }; -inline std::ostream& operator<<(std::ostream& os, [[maybe_unused]] const color& c) +inline std::ostream& operator<<(std::ostream& os, const color& c) { #ifndef _WIN32 static const bool use_color = isatty(STDOUT_FILENO) != 0; if(use_color) return os << "\033[" << static_cast(c) << "m"; +#else + (void)c; #endif return os; } diff --git a/test/promote_literals_test.cpp b/test/promote_literals_test.cpp index 638217f73cf..5d28dee962c 100644 --- a/test/promote_literals_test.cpp +++ b/test/promote_literals_test.cpp @@ -26,7 +26,6 @@ #include #include #include -#include #include #include #include diff --git a/test/verify/run_verify.cpp b/test/verify/run_verify.cpp index 2e56c900d0f..c91a4aba73e 100644 --- a/test/verify/run_verify.cpp +++ b/test/verify/run_verify.cpp @@ -44,8 +44,7 @@ MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_DUMP_TEST) // An improved async, that doesn't block template -std::future> detach_async(Function&& f, - bool parallel = true) +std::future> detach_async(Function&& f, bool parallel = true) { if(parallel) {