Skip to content

Commit

Permalink
Define guard macros to prevent windows.h from conflicting with winsoc…
Browse files Browse the repository at this point in the history
…k2.h (dmlc#10923)

* Define guard macros to prevent windows.h from conflicting with winsock2.h

* On Windows, CUDA virtual memory is not available
  • Loading branch information
hcho3 authored Oct 24, 2024
1 parent 5903c78 commit 9c4f190
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,9 @@ if(USE_CUDA)

find_package(CUDAToolkit REQUIRED)
find_package(CCCL CONFIG)
if(NOT CCCL_FOUND)
if(CCCL_FOUND)
message(STATUS "Standalone CCCL found.")
else()
message(STATUS "Standalone CCCL not found. Attempting to use CCCL from CUDA Toolkit...")
find_package(CCCL CONFIG
HINTS ${CUDAToolkit_LIBRARY_DIR}/cmake)
Expand All @@ -238,6 +240,10 @@ if(USE_CUDA)
target_link_libraries(CCCL::CCCL INTERFACE libcudacxx::libcudacxx CUB::CUB Thrust)
endif()
endif()
# Define guard macros to prevent windows.h from conflicting with winsock2.h
if(WIN32)
target_compile_definitions(CCCL::CCCL INTERFACE NOMINMAX WIN32_LEAN_AND_MEAN _WINSOCKAPI_)
endif()
endif()

if(FORCE_COLORED_OUTPUT AND (CMAKE_GENERATOR STREQUAL "Ninja") AND
Expand Down
3 changes: 2 additions & 1 deletion include/xgboost/collective/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ inline auto ThrowAtError(StringView fn_name, std::int32_t errsv = LastError()) {
using SocketT = SOCKET;
#else
using SocketT = int;
#define INVALID_SOCKET -1
#endif // defined(_WIN32)

#if !defined(xgboost_CHECK_SYS_CALL)
Expand Down Expand Up @@ -276,7 +277,7 @@ class TCPSocket {
SockDomain domain_{SockDomain::kV4};
#endif

constexpr static HandleT InvalidSocket() { return -1; }
constexpr static HandleT InvalidSocket() { return INVALID_SOCKET; }

explicit TCPSocket(HandleT newfd) : handle_{newfd} {}

Expand Down
6 changes: 6 additions & 0 deletions include/xgboost/windefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@
#endif // !defined(NOMINMAX)

// A macro used inside `windows.h` to avoid conflicts with `winsock2.h`
#if !defined(WIN32_LEAN_AND_MEAN)
#define WIN32_LEAN_AND_MEAN
#endif // !defined(WIN32_LEAN_AND_MEAN)
// Stop windows.h from including winsock.h
#if !defined(_WINSOCKAPI_)
#define _WINSOCKAPI_
#endif // !defined(_WINSOCKAPI_)

#if !defined(xgboost_IS_MINGW)

Expand Down
5 changes: 5 additions & 0 deletions tests/cpp/common/test_device_vector.cu
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../../../src/common/device_helpers.cuh" // for CachingThrustPolicy, PinnedMemory
#include "../../../src/common/device_vector.cuh"
#include "xgboost/global_config.h" // for GlobalConfigThreadLocalStore
#include "xgboost/windefs.h" // for xgboost_IS_WIN

namespace dh {
TEST(DeviceUVector, Basic) {
Expand Down Expand Up @@ -109,10 +110,14 @@ TEST(TestVirtualMem, Version) {
xgboost::curt::DrVersion(&major, &minor);
LOG(INFO) << "Latest supported CUDA version by the driver:" << major << "." << minor;
PinnedMemory pinned;
#if defined(xgboost_IS_WIN)
ASSERT_FALSE(pinned.IsVm());
#else // defined(xgboost_IS_WIN)
if (major >= 12 && minor >= 5) {
ASSERT_TRUE(pinned.IsVm());
} else {
ASSERT_FALSE(pinned.IsVm());
}
#endif // defined(xgboost_IS_WIN)
}
} // namespace dh

0 comments on commit 9c4f190

Please sign in to comment.