diff --git a/CMakeLists.txt b/CMakeLists.txt index f444089d0209112a31fa486ea7da8003692bac36..c5603cd838d4ca4e0b6fbbbfae31f7a430ff8398 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,7 @@ option(BUILD_CONSUMER_TOOLS "Build consumer tools" OFF) option(BUILD_EXAMPLES "Build examples" OFF) option(ENABLE_LIBFABRIC "Enables LibFabric support for RDMA transfers" OFF) +option(ENABLE_LIBFABRIC_LOCALHOST "Emulates LibFabric stack over TCP. Only for localhost and testing purposes." OFF) set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules/) @@ -75,6 +76,10 @@ IF(ENABLE_LIBFABRIC) message(STATUS "LIB_FABRIC: Path: ${LIBFABRIC_LIBRARY} Include: ${LIBFABRIC_INCLUDE_DIR}") add_definitions(-DLIBFABRIC_ENABLED) SET(ASAPO_COMMON_FABRIC_LIBRARIES ${ASAPO_COMMON_FABRIC_LIBRARIES} fabric) + IF(ENABLE_LIBFABRIC_LOCALHOST) + message(STATUS "LIB_FABRIC: Enabled emulated RDMA when localhost is used. Should only be used for tests.") + add_definitions(-DLIBFARBIC_ALLOW_LOCALHOST) + ENDIF() ENDIF() SET_PROPERTY(GLOBAL PROPERTY ASAPO_COMMON_FABRIC_LIBRARIES ${ASAPO_COMMON_FABRIC_LIBRARIES}) @@ -123,4 +128,4 @@ endif() include(prepare_version) -add_subdirectory(docs) \ No newline at end of file +add_subdirectory(docs) diff --git a/common/cpp/src/asapo_fabric/common/fabric_context_impl.cpp b/common/cpp/src/asapo_fabric/common/fabric_context_impl.cpp index 19477ac5cccbee53369e2c5f6ba76e95a0149aea..2614c32bf25327ae237c323dfdaa66e5aed407bc 100644 --- a/common/cpp/src/asapo_fabric/common/fabric_context_impl.cpp +++ b/common/cpp/src/asapo_fabric/common/fabric_context_impl.cpp @@ -66,8 +66,15 @@ void FabricContextImpl::InitCommon(const std::string& networkIpHint, uint16_t se uint64_t additionalFlags = isServer ? FI_SOURCE : 0; fi_info* hints = fi_allocinfo(); - if (networkIpHint == "127.0.0.1") { + +#ifdef LIBFARBIC_ALLOW_LOCALHOST + constexpr bool allowLocalhost = true; +#else + constexpr bool allowLocalhost = false; +#endif + if (networkIpHint == "127.0.0.1" && allowLocalhost) { // sockets mode + printf("WARN: Using sockets to emulate RDMA, this should only used for tests.\n"); hints->fabric_attr->prov_name = strdup("sockets"); hotfix_using_sockets_ = true; } else { diff --git a/tests/automatic/CMakeLists.txt b/tests/automatic/CMakeLists.txt index 9df59ca928b4dcae80fdf225a5f317419b3dbdc0..9c8a631946507776eb40d323e41f4630e089d99d 100644 --- a/tests/automatic/CMakeLists.txt +++ b/tests/automatic/CMakeLists.txt @@ -39,5 +39,9 @@ endif() add_subdirectory(bug_fixes) if (ENABLE_LIBFABRIC) - add_subdirectory(asapo_fabric) + if (ENABLE_LIBFABRIC_LOCALHOST) + add_subdirectory(asapo_fabric) + else () + message(WARNING "Disabled automated LibFabric test because 'ENABLE_LIBFABRIC_LOCALHOST' is not enabled.") + endif() endif() diff --git a/tests/manual/asapo_fabric/fabric_client.cpp b/tests/manual/asapo_fabric/fabric_client.cpp index ea48c16d57b495f2be0ac430f91077cda3d57016..68b416d723a3782c68e5fab92ae2df332d24214e 100644 --- a/tests/manual/asapo_fabric/fabric_client.cpp +++ b/tests/manual/asapo_fabric/fabric_client.cpp @@ -10,7 +10,9 @@ int main(int argc, char* argv[]) { if (argc < 3 || argc > 5) { std::cout << "Usage: " << argv[0] << " <serverAddress> <serverPort> [kiByte=1024*400/*400MiByte*/ /*MUST BE SYNC WITH SERVER*/] [count=10]" << std::endl + #ifdef LIBFARBIC_ALLOW_LOCALHOST << "If the address is localhost or 127.0.0.1 the verbs connection will be emulated" << std::endl + #endif ; return 1; } diff --git a/tests/manual/asapo_fabric/fabric_server.cpp b/tests/manual/asapo_fabric/fabric_server.cpp index ebfb258eebc6daa593134abdf3aa9a30bda909e1..53376b7b3119613898ee52c6a8aa0dd1fa6b39e2 100644 --- a/tests/manual/asapo_fabric/fabric_server.cpp +++ b/tests/manual/asapo_fabric/fabric_server.cpp @@ -40,7 +40,9 @@ int main(int argc, char* argv[]) { if (argc < 3 || argc > 4) { std::cout << "Usage: " << argv[0] << " <listenAddress> <listenPort> [kiByte=1024*400/*400MiByte*/ /*MUST BE SYNC WITH CLIENT*/]" << std::endl + #ifdef LIBFARBIC_ALLOW_LOCALHOST << "If the address is localhost or 127.0.0.1 the verbs connection will be emulated" << std::endl + #endif ; return 1; }