diff --git a/src/include/migraphx/register_target.hpp b/src/include/migraphx/register_target.hpp index ddfff1cf2ac..1d274433e91 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 @@ -28,6 +28,7 @@ #include #include #include +#include #include namespace migraphx { @@ -44,7 +45,7 @@ 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 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 88eb38340a7..c14e4091c22 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 migraphx_all_targets) + 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..e6146088a05 --- /dev/null +++ b/test/register_target.cpp @@ -0,0 +1,45 @@ +/* + * 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 + +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