From fcd968346bbec96df15695a9be30f9afc9a032da Mon Sep 17 00:00:00 2001 From: Ahsan Saghir Date: Wed, 10 Apr 2024 16:14:39 +0000 Subject: [PATCH 1/3] Append so_version for loading shared libraries (changes from PR#2948 commit 7374d52a76 in develop) --- src/register_target.cpp | 20 +++++++++++++++++++- src/version.h.in | 6 +++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/register_target.cpp b/src/register_target.cpp index a20485d73c6..1c7712fb772 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { @@ -58,10 +59,27 @@ target make_target(const std::string& name) { #ifdef _WIN32 std::string target_name = "migraphx_" + name + ".dll"; + store_target_lib(dynamic_loader(target_name)); #else std::string target_name = "libmigraphx_" + name + ".so"; + std::string so_version = "." + std::to_string(MIGRAPHX_SO_MAJOR_VERSION) + ".0"; + + // Try to load library with so version appended to the name. + // If library with so version name is not found, + // try loading the library without the so version name appended. + // For example, if "libmigraphx_ref.so.2010000.0" is not found, + // try loading "libmigraphx_ref.so". + try + { + // Default to loading shared libraries with so version appended. + store_target_lib(dynamic_loader(target_name + so_version)); + } + catch(...) + { + // Load the library without the so version in the name. + store_target_lib(dynamic_loader(target_name)); + } #endif - store_target_lib(dynamic_loader(target_name)); } const auto it = target_map().find(name); if(it == target_map().end()) diff --git a/src/version.h.in b/src/version.h.in index ec678821fb3..70ddc38ef77 100644 --- a/src/version.h.in +++ b/src/version.h.in @@ -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 @@ -26,4 +26,8 @@ #define MIGRAPHX_VERSION_MINOR @PROJECT_VERSION_MINOR@ #define MIGRAPHX_VERSION_PATCH @PROJECT_VERSION_PATCH@ #define MIGRAPHX_VERSION_TWEAK "@PROJECT_VERSION_TWEAK@" +#define MIGRAPHX_SO_MAJOR_VERSION \ + @PROJECT_VERSION_MAJOR@ * 1000 * 1000 + \ + @PROJECT_VERSION_MINOR@ * 1000 + \ + @PROJECT_VERSION_PATCH@ // clang-format on From add2667c2dc7ec2f46595c8b9fe730636cfee366 Mon Sep 17 00:00:00 2001 From: Ahsan Saghir Date: Wed, 10 Apr 2024 18:21:12 +0000 Subject: [PATCH 2/3] Licensing fix --- 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 1c7712fb772..2bcd260a7f6 100644 --- a/src/register_target.cpp +++ b/src/register_target.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 From ab39bfc365e908806fbd7a0fadc2c3a0189cf407 Mon Sep 17 00:00:00 2001 From: Ahsan Saghir Date: Tue, 16 Apr 2024 14:03:37 +0000 Subject: [PATCH 3/3] Use so_major_version --- src/register_target.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/register_target.cpp b/src/register_target.cpp index 2bcd260a7f6..da0338f7780 100644 --- a/src/register_target.cpp +++ b/src/register_target.cpp @@ -61,22 +61,23 @@ target make_target(const std::string& name) std::string target_name = "migraphx_" + name + ".dll"; store_target_lib(dynamic_loader(target_name)); #else - std::string target_name = "libmigraphx_" + name + ".so"; - std::string so_version = "." + std::to_string(MIGRAPHX_SO_MAJOR_VERSION) + ".0"; + std::string target_name = "libmigraphx_" + name + ".so"; + std::string so_major_version = "." + std::to_string(MIGRAPHX_SO_MAJOR_VERSION); - // Try to load library with so version appended to the name. - // If library with so version name is not found, - // try loading the library without the so version name appended. - // For example, if "libmigraphx_ref.so.2010000.0" is not found, + // Try to load library with so_major_version appended to the name. + // If library with so_major_version name is not found, + // try loading the library without the so_major_version name appended. + // For example, if "libmigraphx_ref.so.2010000" is not found, // try loading "libmigraphx_ref.so". try { - // Default to loading shared libraries with so version appended. - store_target_lib(dynamic_loader(target_name + so_version)); + // Default to loading shared libraries with + // so_major_version appended. + store_target_lib(dynamic_loader(target_name + so_major_version)); } catch(...) { - // Load the library without the so version in the name. + // Load the library without the so_major_version in the name. store_target_lib(dynamic_loader(target_name)); } #endif