From 34bf4882623dd7d1afa0cf96275aac6b51581e07 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Tue, 27 Feb 2024 08:53:11 +0100 Subject: [PATCH 01/22] fix target registering on Windows --- src/include/migraphx/register_target.hpp | 25 ++++----------- src/register_target.cpp | 39 +++++++++++------------- src/targets/cpu/target.cpp | 2 +- src/targets/fpga/CMakeLists.txt | 2 ++ src/targets/fpga/target.cpp | 2 +- src/targets/gpu/target.cpp | 2 +- src/targets/ref/target.cpp | 2 +- test/CMakeLists.txt | 1 + test/fpga/get_target_assignments.cpp | 4 +-- test/targets.cpp | 28 +++++++++-------- test/verify/auto_print.cpp | 23 ++++++++++++-- test/verify/auto_print.hpp | 4 +++ test/verify/run_verify.cpp | 2 +- 13 files changed, 72 insertions(+), 64 deletions(-) diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index ddfff1cf2ac..2649660074f 100644 --- a/src/include/migraphx/register_target.hpp +++ b/src/include/migraphx/register_target.hpp @@ -28,23 +28,22 @@ #include #include #include +#include #include namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { -MIGRAPHX_EXPORT void register_target_init(); MIGRAPHX_EXPORT void register_target(const target& t); -MIGRAPHX_EXPORT void unregister_target(const std::string& name); -MIGRAPHX_EXPORT target make_target(const std::string& name); -MIGRAPHX_EXPORT std::vector get_targets(); +MIGRAPHX_EXPORT void unregister_target(std::string_view name); +MIGRAPHX_EXPORT target make_target(std::string_view name); namespace detail { struct target_handler { target t; std::string target_name; - target_handler(const target& t_r) : t(t_r), target_name(t.name()) {} + explicit target_handler(target t_r) : t(std::move(t_r)), target_name(t.name()) {} ~target_handler() { unregister_target(target_name); } }; } // namespace detail @@ -52,24 +51,12 @@ struct target_handler template void register_target() { - register_target_init(); static auto t_h = detail::target_handler(T{}); register_target(t_h.t); } -struct register_target_action -{ - template - static void apply() - { - register_target(); - } -}; - -template -using auto_register_target = auto_register; - -#define MIGRAPHX_REGISTER_TARGET(...) MIGRAPHX_AUTO_REGISTER(register_target_action, __VA_ARGS__) +#define MIGRAPHX_REGISTER_TARGET(_EXPORT_MACRO, ...) \ + _EXPORT_MACRO extern "C" void register_target() { migraphx::register_target<__VA_ARGS__>(); } } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx diff --git a/src/register_target.cpp b/src/register_target.cpp index d5fe071002c..0d92bd8a87c 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -31,10 +31,18 @@ namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { -void store_target_lib(const dynamic_loader& lib) +void store_target_lib(const fs::path& target_name, const dynamic_loader& lib) { static std::vector target_loader; - target_loader.emplace_back(lib); + try + { + lib.get_function("register_target")(); + target_loader.push_back(lib); + } + catch(const std::runtime_error&) + { + std::cerr << "Not a target library: " << target_name << std::endl; + } } std::unordered_map& target_map() @@ -43,24 +51,22 @@ std::unordered_map& target_map() return m; } -void register_target_init() { (void)target_map(); } - -void unregister_target(const std::string& name) +void unregister_target(std::string_view name) { - assert(target_map().count(name)); - target_map().erase(name); + assert(target_map().count(name.data())); + target_map().erase(name.data()); } void register_target(const target& t) { target_map()[t.name()] = t; } -target make_target(const std::string& name) +target make_target(std::string_view name) { - if(not contains(target_map(), name)) + if(not contains(target_map(), name.data())) { auto target_name = make_shared_object_filename("migraphx_" + name); - store_target_lib(dynamic_loader(target_name)); + store_target_lib(target_name, dynamic_loader(target_name)); } - const auto it = target_map().find(name); + const auto it = target_map().find(name.data()); if(it == target_map().end()) { MIGRAPHX_THROW("Requested target '" + name + "' is not loaded or not supported"); @@ -68,16 +74,5 @@ target make_target(const std::string& name) return it->second; } -std::vector get_targets() -{ - std::vector result; - std::transform(target_map().begin(), - target_map().end(), - std::back_inserter(result), - [&](auto&& p) { return p.first; }); - std::sort(result.begin(), result.end()); - return result; -} - } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx diff --git a/src/targets/cpu/target.cpp b/src/targets/cpu/target.cpp index 73a8378928a..3ef4fd27fee 100644 --- a/src/targets/cpu/target.cpp +++ b/src/targets/cpu/target.cpp @@ -114,7 +114,7 @@ std::vector target::get_passes(migraphx::context& gctx, const compile_opti argument target::allocate(const shape& s) const { return fill_argument(s, 0); } -MIGRAPHX_REGISTER_TARGET(target); +MIGRAPHX_REGISTER_TARGET(MIGRAPHX_CPU_EXPORT, target); } // namespace cpu } // namespace MIGRAPHX_INLINE_NS diff --git a/src/targets/fpga/CMakeLists.txt b/src/targets/fpga/CMakeLists.txt index 39df3be6400..2eec1534d5a 100644 --- a/src/targets/fpga/CMakeLists.txt +++ b/src/targets/fpga/CMakeLists.txt @@ -29,6 +29,8 @@ add_library(migraphx_fpga vitis_ai_adapter.cpp ) +migraphx_generate_export_header(migraphx_fpga) + set_target_properties(migraphx_fpga PROPERTIES EXPORT_NAME fpga) rocm_set_soversion(migraphx_fpga ${MIGRAPHX_SO_VERSION}) diff --git a/src/targets/fpga/target.cpp b/src/targets/fpga/target.cpp index 570779fff2e..a5905a5dd79 100644 --- a/src/targets/fpga/target.cpp +++ b/src/targets/fpga/target.cpp @@ -76,7 +76,7 @@ supported_segments target::find_supported(const_module_ref mod, support_metric m return {instrs}; } -MIGRAPHX_REGISTER_TARGET(target); +MIGRAPHX_REGISTER_TARGET(MIGRAPHX_FPGA_EXPORT, target); } // namespace fpga } // namespace MIGRAPHX_INLINE_NS diff --git a/src/targets/gpu/target.cpp b/src/targets/gpu/target.cpp index cc0a136892d..145a68b316b 100644 --- a/src/targets/gpu/target.cpp +++ b/src/targets/gpu/target.cpp @@ -213,7 +213,7 @@ argument target::copy_from(const argument& arg) const { return gpu::from_gpu(arg argument target::allocate(const shape& s) const { return gpu::allocate_gpu(s); } -MIGRAPHX_REGISTER_TARGET(target); +MIGRAPHX_REGISTER_TARGET(MIGRAPHX_GPU_EXPORT, target); } // namespace gpu } // namespace MIGRAPHX_INLINE_NS diff --git a/src/targets/ref/target.cpp b/src/targets/ref/target.cpp index 13c15e541e3..a61894413d5 100644 --- a/src/targets/ref/target.cpp +++ b/src/targets/ref/target.cpp @@ -59,7 +59,7 @@ std::vector target::get_passes(migraphx::context&, const compile_options&) argument target::allocate(const shape& s) const { return fill_argument(s, 0); } -MIGRAPHX_REGISTER_TARGET(target); +MIGRAPHX_REGISTER_TARGET(MIGRAPHX_REF_EXPORT, target); } // namespace ref } // namespace MIGRAPHX_INLINE_NS diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b6ecc2e35d3..41ca09d9036 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -39,6 +39,7 @@ foreach(TEST ${TESTS}) get_filename_component(BASE_NAME ${TEST} NAME_WE) rocm_add_test_executable(test_${BASE_NAME} ${TEST}) rocm_clang_tidy_check(test_${BASE_NAME}) + target_link_libraries(test_${BASE_NAME} migraphx_all_targets) endforeach() if(MIGRAPHX_ENABLE_GPU) diff --git a/test/fpga/get_target_assignments.cpp b/test/fpga/get_target_assignments.cpp index b7fa7b7b47a..3e90d83bc5e 100644 --- a/test/fpga/get_target_assignments.cpp +++ b/test/fpga/get_target_assignments.cpp @@ -44,9 +44,7 @@ migraphx::program create_program() TEST_CASE(is_supported) { - auto p = create_program(); - auto targets = migraphx::get_targets(); - EXPECT(not targets.empty()); + auto p = create_program(); auto t = migraphx::make_target("fpga"); const auto assignments = p.get_target_assignments({t}); diff --git a/test/targets.cpp b/test/targets.cpp index 97e2d8d5f2f..6bb9eeae533 100644 --- a/test/targets.cpp +++ b/test/targets.cpp @@ -25,25 +25,29 @@ #include #include "test.hpp" -TEST_CASE(make_target) +bool verify_target(std::string_view name) { - for(const auto& name : migraphx::get_targets()) - { - auto t = migraphx::make_target(name); - CHECK(t.name() == name); - } + auto t = migraphx::make_target(name); + return t.name() == name; } -TEST_CASE(make_invalid_target) +TEST_CASE(make_target) { - EXPECT(test::throws([&] { migraphx::make_target("mi100"); })); + CHECK(verify_target("ref")); +#ifdef HAVE_CPU + CHECK(verify_target("cpu")); +#endif +#ifdef HAVE_GPU + CHECK(verify_target("gpu")); +#endif +#ifdef HAVE_FPGA + CHECK(verify_target("fpga")); +#endif } -TEST_CASE(targets) +TEST_CASE(make_invalid_target) { - auto ref_target = migraphx::make_target("ref"); - auto ts = migraphx::get_targets(); - EXPECT(ts.size() >= 1); + EXPECT(test::throws([&] { migraphx::make_target("mi100"); })); } int main(int argc, const char* argv[]) { test::run(argc, argv); } diff --git a/test/verify/auto_print.cpp b/test/verify/auto_print.cpp index 903fefd9230..9d6f74466d3 100644 --- a/test/verify/auto_print.cpp +++ b/test/verify/auto_print.cpp @@ -36,7 +36,7 @@ using handler_map = std::map>; static handler_map create_handlers() { handler_map m; - for(const auto& name : migraphx::get_targets()) + for(const auto& name : get_targets()) m[name] = [] {}; return m; } @@ -64,7 +64,7 @@ void auto_print::set_terminate_handler(const std::string& name) std::cout << " what(): " << e.what() << std::endl; } std::cout << std::endl; - for(const auto& tname : migraphx::get_targets()) + for(const auto& tname : get_targets()) get_handler(tname)(); }); } @@ -83,8 +83,25 @@ auto_print::~auto_print() if(in_exception()) { std::cout << std::endl; - for(const auto& tname : migraphx::get_targets()) + for(const auto& tname : get_targets()) get_handler(tname)(); } get_handler(name) = [] {}; } + +std::vector get_targets() +{ + static const std::vector targets = { + "ref", +#ifdef HAVE_CPU + "cpu", +#endif +#ifdef HAVE_GPU + "gpu", +#endif +#ifdef HAVE_FPGA + "fpga", +#endif + }; + return targets; +} diff --git a/test/verify/auto_print.hpp b/test/verify/auto_print.hpp index f680479fae8..1ffe3eb4c8b 100644 --- a/test/verify/auto_print.hpp +++ b/test/verify/auto_print.hpp @@ -26,6 +26,10 @@ #include #include +#include +#include + +std::vector get_targets(); struct auto_print { diff --git a/test/verify/run_verify.cpp b/test/verify/run_verify.cpp index e7fdd535fcc..171f8dd831c 100644 --- a/test/verify/run_verify.cpp +++ b/test/verify/run_verify.cpp @@ -184,7 +184,7 @@ void run_verify::verify(const program_info& pi) const migraphx::save(p, name + ".mxr"); verify_load_save(p); std::vector target_names; - for(const auto& tname : migraphx::get_targets()) + for(const auto& tname : get_targets()) { // TODO(varunsh): once verify tests can run, remove fpga if(tname == "ref" or tname == "fpga") From fc29bd65d9dccda8fd072b863d208db6ae719493 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 7 Mar 2024 16:31:04 +0100 Subject: [PATCH 02/22] upgrade the year in licenses --- src/include/migraphx/register_target.hpp | 2 +- src/targets/fpga/target.cpp | 2 +- test/fpga/get_target_assignments.cpp | 2 +- test/targets.cpp | 2 +- test/verify/auto_print.cpp | 2 +- test/verify/auto_print.hpp | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index 2649660074f..a4f31c15f18 100644 --- a/src/include/migraphx/register_target.hpp +++ b/src/include/migraphx/register_target.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/targets/fpga/target.cpp b/src/targets/fpga/target.cpp index a5905a5dd79..e543a0bb97d 100644 --- a/src/targets/fpga/target.cpp +++ b/src/targets/fpga/target.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/test/fpga/get_target_assignments.cpp b/test/fpga/get_target_assignments.cpp index 3e90d83bc5e..4b8901cffa3 100644 --- a/test/fpga/get_target_assignments.cpp +++ b/test/fpga/get_target_assignments.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 diff --git a/test/targets.cpp b/test/targets.cpp index 6bb9eeae533..32b79e31e4f 100644 --- a/test/targets.cpp +++ b/test/targets.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 diff --git a/test/verify/auto_print.cpp b/test/verify/auto_print.cpp index 9d6f74466d3..f832e48a518 100644 --- a/test/verify/auto_print.cpp +++ b/test/verify/auto_print.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/test/verify/auto_print.hpp b/test/verify/auto_print.hpp index 1ffe3eb4c8b..fcaeb36b5ff 100644 --- a/test/verify/auto_print.hpp +++ b/test/verify/auto_print.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 From cd4654167c7059d4ae3498d51427a3ce0498ccf2 Mon Sep 17 00:00:00 2001 From: "artur.wojcik@amd.com" Date: Thu, 7 Mar 2024 19:30:36 +0100 Subject: [PATCH 03/22] fix compilation of the fpga target --- dev-requirements.txt | 4 ++-- requirements.txt | 6 +++--- src/targets/fpga/target.cpp | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index cf520e3cb59..3145d14aaf7 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -21,10 +21,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. ##################################################################################### -ROCmSoftwarePlatform/rocm-recipes +ROCm/rocm-recipes facebook/zstd@v1.4.5 -X subdir -DCMAKE_DIR=build/cmake ccache@v4.1 -DENABLE_TESTING=OFF pcre,pfultz2/pcre@8.45 -H sha256:d6f7182602a775a7d500a0cedca6449af0400c6493951513046d17615ed0bf11 danmar/cppcheck@bb2711c22a0be09efe7f1a8da3030876471026c8 -DHAVE_RULES=1 # 2.11 -RadeonOpenCompute/rocm-cmake@5a34e72d9f113eb5d028e740c2def1f944619595 --build +ROCm/rocm-cmake@5a34e72d9f113eb5d028e740c2def1f944619595 --build -f requirements.txt diff --git a/requirements.txt b/requirements.txt index a5f6ebc0662..c2fb85df825 100755 --- a/requirements.txt +++ b/requirements.txt @@ -23,9 +23,9 @@ ##################################################################################### google/protobuf@v3.19.0 -DCMAKE_POSITION_INDEPENDENT_CODE=On -X subdir -Dprotobuf_BUILD_TESTS=Off nlohmann/json@v3.8.0 -ROCmSoftwarePlatform/half@rocm-5.6.0 +ROCm/half@rocm-5.6.0 pybind/pybind11@d159a563383d10c821ba7b2a71905d1207db6de4 --build msgpack/msgpack-c@cpp-3.3.0 -DMSGPACK_BUILD_TESTS=Off sqlite3@3.43.2 -DCMAKE_POSITION_INDEPENDENT_CODE=On -ROCmSoftwarePlatform/composable_kernel@57cdd70b7cb14e5e3b60cd9a5f96ba8dc343763e -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On -ROCmSoftwarePlatform/rocMLIR@da3df73b13c69d6b1d5ffec9c8281c261a0df257 -DBUILD_FAT_LIBROCKCOMPILER=On +ROCm/composable_kernel@57cdd70b7cb14e5e3b60cd9a5f96ba8dc343763e -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On +ROCm/rocMLIR@da3df73b13c69d6b1d5ffec9c8281c261a0df257 -DBUILD_FAT_LIBROCKCOMPILER=On diff --git a/src/targets/fpga/target.cpp b/src/targets/fpga/target.cpp index e543a0bb97d..0f7eeaa38fb 100644 --- a/src/targets/fpga/target.cpp +++ b/src/targets/fpga/target.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include From 60860e97064f52ff7c78dfd103fb222a814a065c Mon Sep 17 00:00:00 2001 From: "artur.wojcik@amd.com" Date: Thu, 7 Mar 2024 19:31:52 +0100 Subject: [PATCH 04/22] update the year in CMakeLists.txt files --- src/targets/fpga/CMakeLists.txt | 2 +- test/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/targets/fpga/CMakeLists.txt b/src/targets/fpga/CMakeLists.txt index 2eec1534d5a..b4414067ad9 100644 --- a/src/targets/fpga/CMakeLists.txt +++ b/src/targets/fpga/CMakeLists.txt @@ -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/test/CMakeLists.txt b/test/CMakeLists.txt index 41ca09d9036..dbbd7af0e73 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 From 7de05db2326e763017b58cf7ac0b8253428d0a6e Mon Sep 17 00:00:00 2001 From: "artur.wojcik@amd.com" Date: Thu, 7 Mar 2024 19:41:42 +0100 Subject: [PATCH 05/22] fix cppcheck reports --- src/register_target.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/register_target.cpp b/src/register_target.cpp index 0d92bd8a87c..cae18281401 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -31,13 +31,19 @@ namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { +namespace { +std::vector target_loaders() +{ + static std::vector target_loaders; + return target_loaders; +} + void store_target_lib(const fs::path& target_name, const dynamic_loader& lib) { - static std::vector target_loader; try { lib.get_function("register_target")(); - target_loader.push_back(lib); + target_loaders().push_back(lib); } catch(const std::runtime_error&) { @@ -50,6 +56,7 @@ std::unordered_map& target_map() static std::unordered_map m; // NOLINT return m; } +} // namespace void unregister_target(std::string_view name) { From bbe1d3d6efda328e03654b1fe7c2751cceb5260b Mon Sep 17 00:00:00 2001 From: "artur.wojcik@amd.com" Date: Thu, 7 Mar 2024 19:55:10 +0100 Subject: [PATCH 06/22] undo *requirements.txt --- dev-requirements.txt | 4 ++-- requirements.txt | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/dev-requirements.txt b/dev-requirements.txt index 3145d14aaf7..cf520e3cb59 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -21,10 +21,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN # THE SOFTWARE. ##################################################################################### -ROCm/rocm-recipes +ROCmSoftwarePlatform/rocm-recipes facebook/zstd@v1.4.5 -X subdir -DCMAKE_DIR=build/cmake ccache@v4.1 -DENABLE_TESTING=OFF pcre,pfultz2/pcre@8.45 -H sha256:d6f7182602a775a7d500a0cedca6449af0400c6493951513046d17615ed0bf11 danmar/cppcheck@bb2711c22a0be09efe7f1a8da3030876471026c8 -DHAVE_RULES=1 # 2.11 -ROCm/rocm-cmake@5a34e72d9f113eb5d028e740c2def1f944619595 --build +RadeonOpenCompute/rocm-cmake@5a34e72d9f113eb5d028e740c2def1f944619595 --build -f requirements.txt diff --git a/requirements.txt b/requirements.txt index c2fb85df825..a5f6ebc0662 100755 --- a/requirements.txt +++ b/requirements.txt @@ -23,9 +23,9 @@ ##################################################################################### google/protobuf@v3.19.0 -DCMAKE_POSITION_INDEPENDENT_CODE=On -X subdir -Dprotobuf_BUILD_TESTS=Off nlohmann/json@v3.8.0 -ROCm/half@rocm-5.6.0 +ROCmSoftwarePlatform/half@rocm-5.6.0 pybind/pybind11@d159a563383d10c821ba7b2a71905d1207db6de4 --build msgpack/msgpack-c@cpp-3.3.0 -DMSGPACK_BUILD_TESTS=Off sqlite3@3.43.2 -DCMAKE_POSITION_INDEPENDENT_CODE=On -ROCm/composable_kernel@57cdd70b7cb14e5e3b60cd9a5f96ba8dc343763e -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On -ROCm/rocMLIR@da3df73b13c69d6b1d5ffec9c8281c261a0df257 -DBUILD_FAT_LIBROCKCOMPILER=On +ROCmSoftwarePlatform/composable_kernel@57cdd70b7cb14e5e3b60cd9a5f96ba8dc343763e -DCK_BUILD_JIT_LIB=On -DCMAKE_POSITION_INDEPENDENT_CODE=On +ROCmSoftwarePlatform/rocMLIR@da3df73b13c69d6b1d5ffec9c8281c261a0df257 -DBUILD_FAT_LIBROCKCOMPILER=On From 1e1f4fb6548ad7784d4e2402723b5b8b0bab8adc Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 7 Mar 2024 21:56:23 +0100 Subject: [PATCH 07/22] minimize the number of changes required --- src/include/migraphx/register_target.hpp | 16 ++++++++--- src/register_target.cpp | 35 +++++++----------------- src/targets/cpu/target.cpp | 2 +- src/targets/fpga/CMakeLists.txt | 4 +-- src/targets/fpga/target.cpp | 5 ++-- src/targets/gpu/target.cpp | 2 +- src/targets/ref/target.cpp | 2 +- test/CMakeLists.txt | 3 +- test/targets.cpp | 2 +- 9 files changed, 30 insertions(+), 41 deletions(-) diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index a4f31c15f18..ed04d83bfdd 100644 --- a/src/include/migraphx/register_target.hpp +++ b/src/include/migraphx/register_target.hpp @@ -35,8 +35,8 @@ namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { MIGRAPHX_EXPORT void register_target(const target& t); -MIGRAPHX_EXPORT void unregister_target(std::string_view name); -MIGRAPHX_EXPORT target make_target(std::string_view name); +MIGRAPHX_EXPORT void unregister_target(const std::string& name); +MIGRAPHX_EXPORT target make_target(const std::string& name); namespace detail { struct target_handler @@ -55,8 +55,16 @@ void register_target() register_target(t_h.t); } -#define MIGRAPHX_REGISTER_TARGET(_EXPORT_MACRO, ...) \ - _EXPORT_MACRO extern "C" void register_target() { migraphx::register_target<__VA_ARGS__>(); } +struct register_target_action +{ + template + static void apply() + { + register_target(); + } +}; + +#define MIGRAPHX_REGISTER_TARGET(...) MIGRAPHX_AUTO_REGISTER(register_target_action, __VA_ARGS__) } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx diff --git a/src/register_target.cpp b/src/register_target.cpp index cae18281401..6313c4cbc05 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -31,24 +31,10 @@ namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { -namespace { -std::vector target_loaders() +void store_target_lib(const dynamic_loader& lib) { - static std::vector target_loaders; - return target_loaders; -} - -void store_target_lib(const fs::path& target_name, const dynamic_loader& lib) -{ - try - { - lib.get_function("register_target")(); - target_loaders().push_back(lib); - } - catch(const std::runtime_error&) - { - std::cerr << "Not a target library: " << target_name << std::endl; - } + static std::vector target_loader; + target_loader.emplace_back(lib); } std::unordered_map& target_map() @@ -56,24 +42,23 @@ std::unordered_map& target_map() static std::unordered_map m; // NOLINT return m; } -} // namespace -void unregister_target(std::string_view name) +void unregister_target(const std::string& name) { - assert(target_map().count(name.data())); - target_map().erase(name.data()); + assert(target_map().count(name)); + target_map().erase(name); } void register_target(const target& t) { target_map()[t.name()] = t; } -target make_target(std::string_view name) +target make_target(const std::string& name) { - if(not contains(target_map(), name.data())) + if(not contains(target_map(), name)) { auto target_name = make_shared_object_filename("migraphx_" + name); - store_target_lib(target_name, dynamic_loader(target_name)); + store_target_lib(dynamic_loader(target_name)); } - const auto it = target_map().find(name.data()); + const auto it = target_map().find(name); if(it == target_map().end()) { MIGRAPHX_THROW("Requested target '" + name + "' is not loaded or not supported"); diff --git a/src/targets/cpu/target.cpp b/src/targets/cpu/target.cpp index 3ef4fd27fee..73a8378928a 100644 --- a/src/targets/cpu/target.cpp +++ b/src/targets/cpu/target.cpp @@ -114,7 +114,7 @@ std::vector target::get_passes(migraphx::context& gctx, const compile_opti argument target::allocate(const shape& s) const { return fill_argument(s, 0); } -MIGRAPHX_REGISTER_TARGET(MIGRAPHX_CPU_EXPORT, target); +MIGRAPHX_REGISTER_TARGET(target); } // namespace cpu } // namespace MIGRAPHX_INLINE_NS diff --git a/src/targets/fpga/CMakeLists.txt b/src/targets/fpga/CMakeLists.txt index b4414067ad9..39df3be6400 100644 --- a/src/targets/fpga/CMakeLists.txt +++ b/src/targets/fpga/CMakeLists.txt @@ -1,7 +1,7 @@ ##################################################################################### # The MIT License (MIT) # -# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2015-2022 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 @@ -29,8 +29,6 @@ add_library(migraphx_fpga vitis_ai_adapter.cpp ) -migraphx_generate_export_header(migraphx_fpga) - set_target_properties(migraphx_fpga PROPERTIES EXPORT_NAME fpga) rocm_set_soversion(migraphx_fpga ${MIGRAPHX_SO_VERSION}) diff --git a/src/targets/fpga/target.cpp b/src/targets/fpga/target.cpp index 0f7eeaa38fb..570779fff2e 100644 --- a/src/targets/fpga/target.cpp +++ b/src/targets/fpga/target.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2022 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 @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -77,7 +76,7 @@ supported_segments target::find_supported(const_module_ref mod, support_metric m return {instrs}; } -MIGRAPHX_REGISTER_TARGET(MIGRAPHX_FPGA_EXPORT, target); +MIGRAPHX_REGISTER_TARGET(target); } // namespace fpga } // namespace MIGRAPHX_INLINE_NS diff --git a/src/targets/gpu/target.cpp b/src/targets/gpu/target.cpp index 145a68b316b..cc0a136892d 100644 --- a/src/targets/gpu/target.cpp +++ b/src/targets/gpu/target.cpp @@ -213,7 +213,7 @@ argument target::copy_from(const argument& arg) const { return gpu::from_gpu(arg argument target::allocate(const shape& s) const { return gpu::allocate_gpu(s); } -MIGRAPHX_REGISTER_TARGET(MIGRAPHX_GPU_EXPORT, target); +MIGRAPHX_REGISTER_TARGET(target); } // namespace gpu } // namespace MIGRAPHX_INLINE_NS diff --git a/src/targets/ref/target.cpp b/src/targets/ref/target.cpp index a61894413d5..13c15e541e3 100644 --- a/src/targets/ref/target.cpp +++ b/src/targets/ref/target.cpp @@ -59,7 +59,7 @@ std::vector target::get_passes(migraphx::context&, const compile_options&) argument target::allocate(const shape& s) const { return fill_argument(s, 0); } -MIGRAPHX_REGISTER_TARGET(MIGRAPHX_REF_EXPORT, target); +MIGRAPHX_REGISTER_TARGET(target); } // namespace ref } // namespace MIGRAPHX_INLINE_NS diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dbbd7af0e73..b6ecc2e35d3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ # #################################################################################### # The MIT License (MIT) # -# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2015-2023 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 @@ -39,7 +39,6 @@ foreach(TEST ${TESTS}) get_filename_component(BASE_NAME ${TEST} NAME_WE) rocm_add_test_executable(test_${BASE_NAME} ${TEST}) rocm_clang_tidy_check(test_${BASE_NAME}) - target_link_libraries(test_${BASE_NAME} migraphx_all_targets) endforeach() if(MIGRAPHX_ENABLE_GPU) diff --git a/test/targets.cpp b/test/targets.cpp index 32b79e31e4f..ab9340e3236 100644 --- a/test/targets.cpp +++ b/test/targets.cpp @@ -25,7 +25,7 @@ #include #include "test.hpp" -bool verify_target(std::string_view name) +bool verify_target(const std::string& name) { auto t = migraphx::make_target(name); return t.name() == name; From 07cc3749eaef21b62a9e4ab1c297f3fb5a6190e9 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 7 Mar 2024 23:38:45 +0100 Subject: [PATCH 08/22] add missing migraphx_all_targets to tests --- test/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b6ecc2e35d3..41ca09d9036 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -39,6 +39,7 @@ foreach(TEST ${TESTS}) get_filename_component(BASE_NAME ${TEST} NAME_WE) rocm_add_test_executable(test_${BASE_NAME} ${TEST}) rocm_clang_tidy_check(test_${BASE_NAME}) + target_link_libraries(test_${BASE_NAME} migraphx_all_targets) endforeach() if(MIGRAPHX_ENABLE_GPU) From 4624e436ae98b2b080323f49dcba2c3d1ec681e4 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Fri, 8 Mar 2024 00:02:51 +0100 Subject: [PATCH 09/22] update the year in the license --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 41ca09d9036..dbbd7af0e73 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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 From 45ede6fa6ec11c289e71bf3e5008b6b7b72de9f0 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Wed, 8 May 2024 20:23:40 +0200 Subject: [PATCH 10/22] incorporate review feedback --- src/include/migraphx/register_target.hpp | 1 + src/register_target.cpp | 31 ++++++++++++++++++++++++ test/CMakeLists.txt | 3 +-- test/fpga/get_target_assignments.cpp | 6 +++-- test/targets.cpp | 31 +++++++++++------------- test/verify/auto_print.cpp | 25 +++---------------- test/verify/auto_print.hpp | 6 +---- test/verify/run_verify.cpp | 2 +- 8 files changed, 57 insertions(+), 48 deletions(-) diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index ed04d83bfdd..ab71d5967d7 100644 --- a/src/include/migraphx/register_target.hpp +++ b/src/include/migraphx/register_target.hpp @@ -37,6 +37,7 @@ inline namespace MIGRAPHX_INLINE_NS { MIGRAPHX_EXPORT void register_target(const target& t); MIGRAPHX_EXPORT void unregister_target(const std::string& name); MIGRAPHX_EXPORT target make_target(const std::string& name); +MIGRAPHX_EXPORT std::vector get_targets(); namespace detail { struct target_handler diff --git a/src/register_target.cpp b/src/register_target.cpp index 3e1b79c6857..e8c31a93eee 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -32,6 +32,26 @@ namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { +namespace { +struct auto_load_targets +{ + auto_load_targets() + { + make_target("ref"); +#ifdef HAVE_CPU + make_target("cpu"); +#endif +#ifdef HAVE_GPU + make_target("gpu"); +#endif +#ifdef HAVE_FPGA + make_target("fpga"); +#endif + } +}; +[[maybe_unused]] static auto load_targets = auto_load_targets{}; +} + void store_target_lib(const dynamic_loader& lib) { static std::vector target_loader; @@ -84,5 +104,16 @@ target make_target(const std::string& name) return it->second; } +std::vector get_targets() +{ + std::vector result; + std::transform(target_map().begin(), + target_map().end(), + std::back_inserter(result), + [&](auto&& p) { return p.first; }); + std::sort(result.begin(), result.end()); + return result; +} + } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index dbbd7af0e73..b6ecc2e35d3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,7 @@ # #################################################################################### # The MIT License (MIT) # -# Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. +# Copyright (c) 2015-2023 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 @@ -39,7 +39,6 @@ foreach(TEST ${TESTS}) get_filename_component(BASE_NAME ${TEST} NAME_WE) rocm_add_test_executable(test_${BASE_NAME} ${TEST}) rocm_clang_tidy_check(test_${BASE_NAME}) - target_link_libraries(test_${BASE_NAME} migraphx_all_targets) endforeach() if(MIGRAPHX_ENABLE_GPU) diff --git a/test/fpga/get_target_assignments.cpp b/test/fpga/get_target_assignments.cpp index 4b8901cffa3..c3976a40502 100644 --- a/test/fpga/get_target_assignments.cpp +++ b/test/fpga/get_target_assignments.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2023 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 @@ -44,7 +44,9 @@ migraphx::program create_program() TEST_CASE(is_supported) { - auto p = create_program(); + auto p = create_program(); + auto targets = migraphx::get_targets(); + EXCEPT(not targets.empty()); auto t = migraphx::make_target("fpga"); const auto assignments = p.get_target_assignments({t}); diff --git a/test/targets.cpp b/test/targets.cpp index ab9340e3236..ca8ed8dd79e 100644 --- a/test/targets.cpp +++ b/test/targets.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2023 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 @@ -25,24 +25,13 @@ #include #include "test.hpp" -bool verify_target(const std::string& name) -{ - auto t = migraphx::make_target(name); - return t.name() == name; -} - TEST_CASE(make_target) { - CHECK(verify_target("ref")); -#ifdef HAVE_CPU - CHECK(verify_target("cpu")); -#endif -#ifdef HAVE_GPU - CHECK(verify_target("gpu")); -#endif -#ifdef HAVE_FPGA - CHECK(verify_target("fpga")); -#endif + for(const auto& name : migraphx::get_targets()) + { + auto t = migraphx::make_target(name); + CHECK(t.name() == name); + } } TEST_CASE(make_invalid_target) @@ -50,4 +39,12 @@ TEST_CASE(make_invalid_target) EXPECT(test::throws([&] { migraphx::make_target("mi100"); })); } +TEST_CASE(targets) +{ + auto ref_target = migraphx::make_target("ref"); + + auto ts = migraphx::get_targets(); + EXPECT(ts.size() >= 1); +} + int main(int argc, const char* argv[]) { test::run(argc, argv); } diff --git a/test/verify/auto_print.cpp b/test/verify/auto_print.cpp index f832e48a518..903fefd9230 100644 --- a/test/verify/auto_print.cpp +++ b/test/verify/auto_print.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2022 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 @@ -36,7 +36,7 @@ using handler_map = std::map>; static handler_map create_handlers() { handler_map m; - for(const auto& name : get_targets()) + for(const auto& name : migraphx::get_targets()) m[name] = [] {}; return m; } @@ -64,7 +64,7 @@ void auto_print::set_terminate_handler(const std::string& name) std::cout << " what(): " << e.what() << std::endl; } std::cout << std::endl; - for(const auto& tname : get_targets()) + for(const auto& tname : migraphx::get_targets()) get_handler(tname)(); }); } @@ -83,25 +83,8 @@ auto_print::~auto_print() if(in_exception()) { std::cout << std::endl; - for(const auto& tname : get_targets()) + for(const auto& tname : migraphx::get_targets()) get_handler(tname)(); } get_handler(name) = [] {}; } - -std::vector get_targets() -{ - static const std::vector targets = { - "ref", -#ifdef HAVE_CPU - "cpu", -#endif -#ifdef HAVE_GPU - "gpu", -#endif -#ifdef HAVE_FPGA - "fpga", -#endif - }; - return targets; -} diff --git a/test/verify/auto_print.hpp b/test/verify/auto_print.hpp index fcaeb36b5ff..f680479fae8 100644 --- a/test/verify/auto_print.hpp +++ b/test/verify/auto_print.hpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2022 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 @@ -26,10 +26,6 @@ #include #include -#include -#include - -std::vector get_targets(); struct auto_print { diff --git a/test/verify/run_verify.cpp b/test/verify/run_verify.cpp index 171f8dd831c..e7fdd535fcc 100644 --- a/test/verify/run_verify.cpp +++ b/test/verify/run_verify.cpp @@ -184,7 +184,7 @@ void run_verify::verify(const program_info& pi) const migraphx::save(p, name + ".mxr"); verify_load_save(p); std::vector target_names; - for(const auto& tname : get_targets()) + for(const auto& tname : migraphx::get_targets()) { // TODO(varunsh): once verify tests can run, remove fpga if(tname == "ref" or tname == "fpga") From caac2b0194708fda2c84c9f1baa507c7a313c90a Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Wed, 8 May 2024 20:24:51 +0200 Subject: [PATCH 11/22] fix typo --- test/fpga/get_target_assignments.cpp | 2 +- test/targets.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/test/fpga/get_target_assignments.cpp b/test/fpga/get_target_assignments.cpp index c3976a40502..b7fa7b7b47a 100644 --- a/test/fpga/get_target_assignments.cpp +++ b/test/fpga/get_target_assignments.cpp @@ -46,7 +46,7 @@ TEST_CASE(is_supported) { auto p = create_program(); auto targets = migraphx::get_targets(); - EXCEPT(not targets.empty()); + EXPECT(not targets.empty()); auto t = migraphx::make_target("fpga"); const auto assignments = p.get_target_assignments({t}); diff --git a/test/targets.cpp b/test/targets.cpp index ca8ed8dd79e..97e2d8d5f2f 100644 --- a/test/targets.cpp +++ b/test/targets.cpp @@ -42,7 +42,6 @@ TEST_CASE(make_invalid_target) TEST_CASE(targets) { auto ref_target = migraphx::make_target("ref"); - auto ts = migraphx::get_targets(); EXPECT(ts.size() >= 1); } From 0e73fdb2ad74a5bb942ce21c23ddfe15fb58dc72 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Wed, 8 May 2024 22:45:23 +0200 Subject: [PATCH 12/22] fix clang-format --- src/register_target.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/register_target.cpp b/src/register_target.cpp index e8c31a93eee..f769b4c093e 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -50,7 +50,7 @@ struct auto_load_targets } }; [[maybe_unused]] static auto load_targets = auto_load_targets{}; -} +} // namespace void store_target_lib(const dynamic_loader& lib) { From f0d79d3e249e1080d165b5f05cf54d617673c13b Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 9 May 2024 00:16:07 +0200 Subject: [PATCH 13/22] limit auto target registration to Windows only --- src/register_target.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/register_target.cpp b/src/register_target.cpp index f769b4c093e..0cc3535c21e 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -32,6 +32,7 @@ namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { +#ifdef _WIN32 namespace { struct auto_load_targets { @@ -51,6 +52,7 @@ struct auto_load_targets }; [[maybe_unused]] static auto load_targets = auto_load_targets{}; } // namespace +#endif void store_target_lib(const dynamic_loader& lib) { From 9d8bcf87bec1c79807a1e424966887c6d448345f Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Mon, 27 May 2024 21:27:37 +0200 Subject: [PATCH 14/22] incorporate review feedback --- src/register_target.cpp | 22 -------------------- test/CMakeLists.txt | 10 ++++++--- test/register_target.cpp | 45 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 25 deletions(-) create mode 100644 test/register_target.cpp diff --git a/src/register_target.cpp b/src/register_target.cpp index 0cc3535c21e..cd8c075da1a 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -32,28 +32,6 @@ namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { -#ifdef _WIN32 -namespace { -struct auto_load_targets -{ - auto_load_targets() - { - make_target("ref"); -#ifdef HAVE_CPU - make_target("cpu"); -#endif -#ifdef HAVE_GPU - make_target("gpu"); -#endif -#ifdef HAVE_FPGA - make_target("fpga"); -#endif - } -}; -[[maybe_unused]] static auto load_targets = auto_load_targets{}; -} // namespace -#endif - void store_target_lib(const dynamic_loader& lib) { static std::vector target_loader; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 88eb38340a7..694647143ce 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -33,7 +33,11 @@ if(MIGRAPHX_DISABLE_LARGE_BUFFER_TESTS) add_compile_definitions(MIGRAPHX_DISABLE_LARGE_BUFFER_TESTS) endif() +add_library(register_targets STATIC register_target.cpp) +target_link_libraries(register_targets PRIVATE migraphx) + file(GLOB TESTS CONFIGURE_DEPENDS *.cpp) +list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/register_target.cpp) foreach(TEST ${TESTS}) get_filename_component(BASE_NAME ${TEST} NAME_WE) @@ -56,7 +60,7 @@ if(MIGRAPHX_ENABLE_GPU) if(MIGRAPHX_USE_HIPRTC) target_compile_definitions(test_gpu_${BASE_NAME} PUBLIC -DMIGRAPHX_USE_HIPRTC) endif() - target_link_libraries(test_gpu_${BASE_NAME} migraphx_gpu migraphx_kernels) + target_link_libraries(test_gpu_${BASE_NAME} migraphx_gpu migraphx_kernels register_targets) endforeach() endif() @@ -102,7 +106,7 @@ if(MIGRAPHX_ENABLE_GPU AND MIGRAPHX_ENABLE_CPU AND MIGRAPHX_ENABLE_FPGA) set(TEST_NAME test_${BASE_NAME}) add_executable(${TEST_NAME} ${MULTI_TARGET_TEST}) rocm_clang_tidy_check(${TEST_NAME}) - target_link_libraries(${TEST_NAME} migraphx migraphx_onnx migraphx_tf migraphx_all_targets) + target_link_libraries(${TEST_NAME} migraphx migraphx_onnx migraphx_tf migraphx_all_targets register_targets) target_include_directories(${TEST_NAME} PUBLIC include) add_test(NAME ${TEST_NAME} COMMAND $ WORKING_DIRECTORY ${TEST_MULTI_TARGET_DIR}) rocm_mark_as_test(${TEST_NAME}) @@ -140,7 +144,7 @@ function(test_headers PREFIX) string(MAKE_C_IDENTIFIER ${HEADER_REL} TEST_NAME) get_filename_component(BASE_NAME ${HEADER} NAME_WE) test_header(header_${TEST_NAME} ${PREFIX}/${BASE_NAME}.hpp) - target_link_libraries(header_${TEST_NAME} migraphx migraphx_onnx migraphx_tf migraphx_all_targets) + target_link_libraries(header_${TEST_NAME} migraphx migraphx_onnx migraphx_tf migraphx_all_targets register_targets) endforeach() endfunction() diff --git a/test/register_target.cpp b/test/register_target.cpp new file mode 100644 index 00000000000..95b368d7ba6 --- /dev/null +++ b/test/register_target.cpp @@ -0,0 +1,45 @@ +/* +* The MIT License (MIT) +* +* Copyright (c) 2015-2022 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 +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include + +namespace { +struct auto_load_targets +{ + auto_load_targets() + { + migraphx::make_target("ref"); +#ifdef HAVE_CPU + migraphx::make_target("cpu"); +#endif +#ifdef HAVE_GPU + migraphx::make_target("gpu"); +#endif +#ifdef HAVE_FPGA + migraphx::make_target("fpga"); +#endif + } +}; +[[maybe_unused]] static auto load_targets = auto_load_targets{}; +} // namespace From db78e91e53b42b62af878b17cc6003e006adecbc Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Mon, 27 May 2024 21:35:42 +0200 Subject: [PATCH 15/22] incorporate review feedback --- test/register_target.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/register_target.cpp b/test/register_target.cpp index 95b368d7ba6..394d7c2d167 100644 --- a/test/register_target.cpp +++ b/test/register_target.cpp @@ -41,5 +41,5 @@ struct auto_load_targets #endif } }; -[[maybe_unused]] static auto load_targets = auto_load_targets{}; +[[maybe_unused]] static auto load_targets{auto_load_targets{}}; } // namespace From 5a235c1d444803bed58f3862e8839567fe85fbb2 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Mon, 27 May 2024 21:36:32 +0200 Subject: [PATCH 16/22] fix license check --- test/register_target.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/register_target.cpp b/test/register_target.cpp index 394d7c2d167..94ce90c1b42 100644 --- a/test/register_target.cpp +++ b/test/register_target.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 From 6ec5a5ed7216fc90c0e42cdb7628b60367ea9837 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Mon, 27 May 2024 21:53:18 +0200 Subject: [PATCH 17/22] fix clang-format --- test/register_target.cpp | 44 ++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/register_target.cpp b/test/register_target.cpp index 94ce90c1b42..e6146088a05 100644 --- a/test/register_target.cpp +++ b/test/register_target.cpp @@ -1,26 +1,26 @@ /* -* The MIT License (MIT) -* -* 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 -* in the Software without restriction, including without limitation the rights -* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -* copies of the Software, and to permit persons to whom the Software is -* furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in -* all copies or substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -* THE SOFTWARE. -*/ + * The MIT License (MIT) + * + * 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 + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ #include From 31459c7d47d99bb18aa9ee5311d9fee7aa6bccac Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Mon, 27 May 2024 21:55:30 +0200 Subject: [PATCH 18/22] incorporate review feedback --- src/include/migraphx/register_target.hpp | 3 +++ src/register_target.cpp | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index ab71d5967d7..ef621e4e041 100644 --- a/src/include/migraphx/register_target.hpp +++ b/src/include/migraphx/register_target.hpp @@ -65,6 +65,9 @@ struct register_target_action } }; +template +using auto_register_target = auto_register; + #define MIGRAPHX_REGISTER_TARGET(...) MIGRAPHX_AUTO_REGISTER(register_target_action, __VA_ARGS__) } // namespace MIGRAPHX_INLINE_NS diff --git a/src/register_target.cpp b/src/register_target.cpp index cd8c075da1a..241b080c0e6 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -44,6 +44,8 @@ std::unordered_map& target_map() return m; } +void register_target_init() { (void)target_map(); } + void unregister_target(const std::string& name) { assert(target_map().count(name)); From a3ccae51c98b57742a0b7a14282c0895f5962587 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 7 Mar 2024 20:13:55 +0100 Subject: [PATCH 19/22] fix target library registration on Windows --- src/include/migraphx/register_target.hpp | 4 ---- src/register_target.cpp | 13 ---------- test/CMakeLists.txt | 1 + test/fpga/get_target_assignments.cpp | 6 ++--- test/targets.cpp | 30 ++++++++++++++---------- test/verify/auto_print.cpp | 25 ++++++++++++++++---- test/verify/auto_print.hpp | 6 ++++- test/verify/run_verify.cpp | 2 +- 8 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index ef621e4e041..ed04d83bfdd 100644 --- a/src/include/migraphx/register_target.hpp +++ b/src/include/migraphx/register_target.hpp @@ -37,7 +37,6 @@ inline namespace MIGRAPHX_INLINE_NS { MIGRAPHX_EXPORT void register_target(const target& t); MIGRAPHX_EXPORT void unregister_target(const std::string& name); MIGRAPHX_EXPORT target make_target(const std::string& name); -MIGRAPHX_EXPORT std::vector get_targets(); namespace detail { struct target_handler @@ -65,9 +64,6 @@ struct register_target_action } }; -template -using auto_register_target = auto_register; - #define MIGRAPHX_REGISTER_TARGET(...) MIGRAPHX_AUTO_REGISTER(register_target_action, __VA_ARGS__) } // namespace MIGRAPHX_INLINE_NS diff --git a/src/register_target.cpp b/src/register_target.cpp index 241b080c0e6..3e1b79c6857 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -44,8 +44,6 @@ std::unordered_map& target_map() return m; } -void register_target_init() { (void)target_map(); } - void unregister_target(const std::string& name) { assert(target_map().count(name)); @@ -86,16 +84,5 @@ target make_target(const std::string& name) return it->second; } -std::vector get_targets() -{ - std::vector result; - std::transform(target_map().begin(), - target_map().end(), - std::back_inserter(result), - [&](auto&& p) { return p.first; }); - std::sort(result.begin(), result.end()); - return result; -} - } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 694647143ce..04a18dc911b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,6 +43,7 @@ foreach(TEST ${TESTS}) get_filename_component(BASE_NAME ${TEST} NAME_WE) rocm_add_test_executable(test_${BASE_NAME} ${TEST}) rocm_clang_tidy_check(test_${BASE_NAME}) + target_link_libraries(test_${BASE_NAME} migraphx_all_targets) endforeach() if(MIGRAPHX_ENABLE_GPU) diff --git a/test/fpga/get_target_assignments.cpp b/test/fpga/get_target_assignments.cpp index b7fa7b7b47a..4b8901cffa3 100644 --- a/test/fpga/get_target_assignments.cpp +++ b/test/fpga/get_target_assignments.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 @@ -44,9 +44,7 @@ migraphx::program create_program() TEST_CASE(is_supported) { - auto p = create_program(); - auto targets = migraphx::get_targets(); - EXPECT(not targets.empty()); + auto p = create_program(); auto t = migraphx::make_target("fpga"); const auto assignments = p.get_target_assignments({t}); diff --git a/test/targets.cpp b/test/targets.cpp index 97e2d8d5f2f..ab9340e3236 100644 --- a/test/targets.cpp +++ b/test/targets.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 @@ -25,25 +25,29 @@ #include #include "test.hpp" -TEST_CASE(make_target) +bool verify_target(const std::string& name) { - for(const auto& name : migraphx::get_targets()) - { - auto t = migraphx::make_target(name); - CHECK(t.name() == name); - } + auto t = migraphx::make_target(name); + return t.name() == name; } -TEST_CASE(make_invalid_target) +TEST_CASE(make_target) { - EXPECT(test::throws([&] { migraphx::make_target("mi100"); })); + CHECK(verify_target("ref")); +#ifdef HAVE_CPU + CHECK(verify_target("cpu")); +#endif +#ifdef HAVE_GPU + CHECK(verify_target("gpu")); +#endif +#ifdef HAVE_FPGA + CHECK(verify_target("fpga")); +#endif } -TEST_CASE(targets) +TEST_CASE(make_invalid_target) { - auto ref_target = migraphx::make_target("ref"); - auto ts = migraphx::get_targets(); - EXPECT(ts.size() >= 1); + EXPECT(test::throws([&] { migraphx::make_target("mi100"); })); } int main(int argc, const char* argv[]) { test::run(argc, argv); } diff --git a/test/verify/auto_print.cpp b/test/verify/auto_print.cpp index 903fefd9230..f832e48a518 100644 --- a/test/verify/auto_print.cpp +++ b/test/verify/auto_print.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 @@ -36,7 +36,7 @@ using handler_map = std::map>; static handler_map create_handlers() { handler_map m; - for(const auto& name : migraphx::get_targets()) + for(const auto& name : get_targets()) m[name] = [] {}; return m; } @@ -64,7 +64,7 @@ void auto_print::set_terminate_handler(const std::string& name) std::cout << " what(): " << e.what() << std::endl; } std::cout << std::endl; - for(const auto& tname : migraphx::get_targets()) + for(const auto& tname : get_targets()) get_handler(tname)(); }); } @@ -83,8 +83,25 @@ auto_print::~auto_print() if(in_exception()) { std::cout << std::endl; - for(const auto& tname : migraphx::get_targets()) + for(const auto& tname : get_targets()) get_handler(tname)(); } get_handler(name) = [] {}; } + +std::vector get_targets() +{ + static const std::vector targets = { + "ref", +#ifdef HAVE_CPU + "cpu", +#endif +#ifdef HAVE_GPU + "gpu", +#endif +#ifdef HAVE_FPGA + "fpga", +#endif + }; + return targets; +} diff --git a/test/verify/auto_print.hpp b/test/verify/auto_print.hpp index f680479fae8..fcaeb36b5ff 100644 --- a/test/verify/auto_print.hpp +++ b/test/verify/auto_print.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 @@ -26,6 +26,10 @@ #include #include +#include +#include + +std::vector get_targets(); struct auto_print { diff --git a/test/verify/run_verify.cpp b/test/verify/run_verify.cpp index e7fdd535fcc..171f8dd831c 100644 --- a/test/verify/run_verify.cpp +++ b/test/verify/run_verify.cpp @@ -184,7 +184,7 @@ void run_verify::verify(const program_info& pi) const migraphx::save(p, name + ".mxr"); verify_load_save(p); std::vector target_names; - for(const auto& tname : migraphx::get_targets()) + for(const auto& tname : get_targets()) { // TODO(varunsh): once verify tests can run, remove fpga if(tname == "ref" or tname == "fpga") From 2004b73cecc9ea789773334276a38fe3f8bd3718 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 6 Jun 2024 15:39:43 +0200 Subject: [PATCH 20/22] add missing linking to migraphx_all_tragets --- test/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 04a18dc911b..d214807f26d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -34,7 +34,7 @@ if(MIGRAPHX_DISABLE_LARGE_BUFFER_TESTS) endif() add_library(register_targets STATIC register_target.cpp) -target_link_libraries(register_targets PRIVATE migraphx) +target_link_libraries(register_targets PRIVATE migraphx migraphx_all_targets) file(GLOB TESTS CONFIGURE_DEPENDS *.cpp) list(REMOVE_ITEM TESTS ${CMAKE_CURRENT_SOURCE_DIR}/register_target.cpp) From bcd8ad1f924ed608b56e9b43641935fbeb903ba7 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 6 Jun 2024 16:19:15 +0200 Subject: [PATCH 21/22] revert some more changes --- src/include/migraphx/register_target.hpp | 1 + src/register_target.cpp | 11 +++++++++ test/CMakeLists.txt | 1 - test/fpga/get_target_assignments.cpp | 6 +++-- test/targets.cpp | 30 ++++++++++-------------- test/verify/auto_print.cpp | 25 ++++---------------- test/verify/auto_print.hpp | 6 +---- test/verify/run_verify.cpp | 2 +- 8 files changed, 35 insertions(+), 47 deletions(-) diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index ed04d83bfdd..ab71d5967d7 100644 --- a/src/include/migraphx/register_target.hpp +++ b/src/include/migraphx/register_target.hpp @@ -37,6 +37,7 @@ inline namespace MIGRAPHX_INLINE_NS { MIGRAPHX_EXPORT void register_target(const target& t); MIGRAPHX_EXPORT void unregister_target(const std::string& name); MIGRAPHX_EXPORT target make_target(const std::string& name); +MIGRAPHX_EXPORT std::vector get_targets(); namespace detail { struct target_handler diff --git a/src/register_target.cpp b/src/register_target.cpp index 3e1b79c6857..cd8c075da1a 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -84,5 +84,16 @@ target make_target(const std::string& name) return it->second; } +std::vector get_targets() +{ + std::vector result; + std::transform(target_map().begin(), + target_map().end(), + std::back_inserter(result), + [&](auto&& p) { return p.first; }); + std::sort(result.begin(), result.end()); + return result; +} + } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d214807f26d..c14e4091c22 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -43,7 +43,6 @@ foreach(TEST ${TESTS}) get_filename_component(BASE_NAME ${TEST} NAME_WE) rocm_add_test_executable(test_${BASE_NAME} ${TEST}) rocm_clang_tidy_check(test_${BASE_NAME}) - target_link_libraries(test_${BASE_NAME} migraphx_all_targets) endforeach() if(MIGRAPHX_ENABLE_GPU) diff --git a/test/fpga/get_target_assignments.cpp b/test/fpga/get_target_assignments.cpp index 4b8901cffa3..b7fa7b7b47a 100644 --- a/test/fpga/get_target_assignments.cpp +++ b/test/fpga/get_target_assignments.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2023 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 @@ -44,7 +44,9 @@ migraphx::program create_program() TEST_CASE(is_supported) { - auto p = create_program(); + auto p = create_program(); + auto targets = migraphx::get_targets(); + EXPECT(not targets.empty()); auto t = migraphx::make_target("fpga"); const auto assignments = p.get_target_assignments({t}); diff --git a/test/targets.cpp b/test/targets.cpp index ab9340e3236..97e2d8d5f2f 100644 --- a/test/targets.cpp +++ b/test/targets.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2023 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 @@ -25,24 +25,13 @@ #include #include "test.hpp" -bool verify_target(const std::string& name) -{ - auto t = migraphx::make_target(name); - return t.name() == name; -} - TEST_CASE(make_target) { - CHECK(verify_target("ref")); -#ifdef HAVE_CPU - CHECK(verify_target("cpu")); -#endif -#ifdef HAVE_GPU - CHECK(verify_target("gpu")); -#endif -#ifdef HAVE_FPGA - CHECK(verify_target("fpga")); -#endif + for(const auto& name : migraphx::get_targets()) + { + auto t = migraphx::make_target(name); + CHECK(t.name() == name); + } } TEST_CASE(make_invalid_target) @@ -50,4 +39,11 @@ TEST_CASE(make_invalid_target) EXPECT(test::throws([&] { migraphx::make_target("mi100"); })); } +TEST_CASE(targets) +{ + auto ref_target = migraphx::make_target("ref"); + auto ts = migraphx::get_targets(); + EXPECT(ts.size() >= 1); +} + int main(int argc, const char* argv[]) { test::run(argc, argv); } diff --git a/test/verify/auto_print.cpp b/test/verify/auto_print.cpp index f832e48a518..903fefd9230 100644 --- a/test/verify/auto_print.cpp +++ b/test/verify/auto_print.cpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2022 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 @@ -36,7 +36,7 @@ using handler_map = std::map>; static handler_map create_handlers() { handler_map m; - for(const auto& name : get_targets()) + for(const auto& name : migraphx::get_targets()) m[name] = [] {}; return m; } @@ -64,7 +64,7 @@ void auto_print::set_terminate_handler(const std::string& name) std::cout << " what(): " << e.what() << std::endl; } std::cout << std::endl; - for(const auto& tname : get_targets()) + for(const auto& tname : migraphx::get_targets()) get_handler(tname)(); }); } @@ -83,25 +83,8 @@ auto_print::~auto_print() if(in_exception()) { std::cout << std::endl; - for(const auto& tname : get_targets()) + for(const auto& tname : migraphx::get_targets()) get_handler(tname)(); } get_handler(name) = [] {}; } - -std::vector get_targets() -{ - static const std::vector targets = { - "ref", -#ifdef HAVE_CPU - "cpu", -#endif -#ifdef HAVE_GPU - "gpu", -#endif -#ifdef HAVE_FPGA - "fpga", -#endif - }; - return targets; -} diff --git a/test/verify/auto_print.hpp b/test/verify/auto_print.hpp index fcaeb36b5ff..f680479fae8 100644 --- a/test/verify/auto_print.hpp +++ b/test/verify/auto_print.hpp @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2015-2024 Advanced Micro Devices, Inc. All rights reserved. + * Copyright (c) 2015-2022 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 @@ -26,10 +26,6 @@ #include #include -#include -#include - -std::vector get_targets(); struct auto_print { diff --git a/test/verify/run_verify.cpp b/test/verify/run_verify.cpp index 171f8dd831c..e7fdd535fcc 100644 --- a/test/verify/run_verify.cpp +++ b/test/verify/run_verify.cpp @@ -184,7 +184,7 @@ void run_verify::verify(const program_info& pi) const migraphx::save(p, name + ".mxr"); verify_load_save(p); std::vector target_names; - for(const auto& tname : get_targets()) + for(const auto& tname : migraphx::get_targets()) { // TODO(varunsh): once verify tests can run, remove fpga if(tname == "ref" or tname == "fpga") From 165d0ec9d5922c91993bc1717bebdaf9be9c0f78 Mon Sep 17 00:00:00 2001 From: Artur Wojcik Date: Thu, 6 Jun 2024 16:23:33 +0200 Subject: [PATCH 22/22] revert some more changes --- src/include/migraphx/register_target.hpp | 5 +++++ src/register_target.cpp | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index ab71d5967d7..1d274433e91 100644 --- a/src/include/migraphx/register_target.hpp +++ b/src/include/migraphx/register_target.hpp @@ -34,6 +34,7 @@ namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { +MIGRAPHX_EXPORT void register_target_init(); MIGRAPHX_EXPORT void register_target(const target& t); MIGRAPHX_EXPORT void unregister_target(const std::string& name); MIGRAPHX_EXPORT target make_target(const std::string& name); @@ -52,6 +53,7 @@ struct target_handler template void register_target() { + register_target_init(); static auto t_h = detail::target_handler(T{}); register_target(t_h.t); } @@ -65,6 +67,9 @@ struct register_target_action } }; +template +using auto_register_target = auto_register; + #define MIGRAPHX_REGISTER_TARGET(...) MIGRAPHX_AUTO_REGISTER(register_target_action, __VA_ARGS__) } // namespace MIGRAPHX_INLINE_NS diff --git a/src/register_target.cpp b/src/register_target.cpp index cd8c075da1a..241b080c0e6 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -44,6 +44,8 @@ std::unordered_map& target_map() return m; } +void register_target_init() { (void)target_map(); } + void unregister_target(const std::string& name) { assert(target_map().count(name));