Skip to content

Commit

Permalink
fix compile issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Binyang2014 committed Nov 1, 2024
1 parent 49e66f5 commit d7b8519
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
7 changes: 7 additions & 0 deletions include/mscclpp/gpu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ constexpr auto CU_MEM_ACCESS_FLAGS_PROT_READWRITE = hipMemAccessFlagsProtReadWri
#define CUDA_NVLS_SUPPORTED 0
#endif // !defined(__HIP_PLATFORM_AMD__)

// Fabric
#if !defined(__HIP_PLATFORM_AMD__)
#define CUDA_FABRIC_SUPPORTED ((CUDART_VERSION >= 12040))
#else // !defined(__HIP_PLATFORM_AMD__)
#define CUDA_FABRIC_SUPPORTED 0
#endif // !defined(__HIP_PLATFORM_AMD__)

// GPU sync threads
#if defined(__HIP_PLATFORM_AMD__)
#define __syncshm() asm volatile("s_waitcnt lgkmcnt(0) \n s_barrier");
Expand Down
6 changes: 4 additions & 2 deletions include/mscclpp/gpu_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ T* cudaPhysicalCalloc(size_t nbytes, size_t gran) {
prop.location.type = CU_MEM_LOCATION_TYPE_DEVICE;
#if defined(__HIP_PLATFORM_AMD__)
prop.requestedHandleType = CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR;
#else
#elif (CUDA_FABRIC_SUPPORTED)
prop.requestedHandleTypes =
(CUmemAllocationHandleType)(CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR | CU_MEM_HANDLE_TYPE_FABRIC);
#else
prop.requestedHandleTypes = CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR;
#endif
prop.location.id = currentDevice;

Expand Down Expand Up @@ -260,7 +262,7 @@ static inline size_t getMulticastGranularity(size_t size, CUmulticastGranularity
#if defined(__HIP_PLATFORM_AMD__)
// TODO: revisit when HIP fixes this typo in the field name
prop.handleTypes = CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR;
#elif (CUDA_NVLS_SUPPORTED)
#elif (CUDA_FABRIC_SUPPORTED)
prop.handleTypes = (CUmemAllocationHandleType)(CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR | CU_MEM_HANDLE_TYPE_FABRIC);
#else
prop.handleTypes = CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR;
Expand Down
14 changes: 10 additions & 4 deletions src/registered_memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ bool isCuMemMapAllocated(void* ptr) {
return true;
}

#if (CUDA_FABRIC_SUPPORTED)
// Get the recommended granularity for cuMemAddressReserve
size_t getRecommendedGranularity() {
size_t gran = 0;
Expand All @@ -34,16 +35,13 @@ size_t getRecommendedGranularity() {
CUmemAllocationProp prop = {};
prop.type = CU_MEM_ALLOCATION_TYPE_PINNED;
prop.location.type = CU_MEM_LOCATION_TYPE_DEVICE;
#if defined(__HIP_PLATFORM_AMD__)
prop.requestedHandleType = CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR;
#else
prop.requestedHandleTypes =
(CUmemAllocationHandleType)(CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR | CU_MEM_HANDLE_TYPE_FABRIC);
#endif
prop.location.id = currentDevice;
MSCCLPP_CUTHROW(cuMemGetAllocationGranularity(&gran, &prop, CU_MEM_ALLOC_GRANULARITY_RECOMMENDED));
return gran;
}
#endif
} // namespace

namespace mscclpp {
Expand All @@ -67,6 +65,7 @@ RegisteredMemory::Impl::Impl(void* data, size_t size, TransportFlags transports,
this->isCuMemMapAlloc = true;
}
if (this->isCuMemMapAlloc) {
#if (CUDA_FABRIC_SUPPORTED)
if (isFabricSupported()) {
CUmemGenericAllocationHandle handle;
MSCCLPP_CUTHROW(cuMemRetainAllocationHandle(&handle, baseDataPtr));
Expand All @@ -76,6 +75,9 @@ RegisteredMemory::Impl::Impl(void* data, size_t size, TransportFlags transports,
} else {
throw Error("Fabric is not supported", ErrorCode::InvalidUsage);
}
#else
throw Error("Only support cuMemMap with CUDA 12.4 or later", ErrorCode::InvalidUsage);
#endif
} else {
cudaIpcMemHandle_t handle;
MSCCLPP_CUDATHROW(cudaIpcGetMemHandle(&handle, baseDataPtr));
Expand Down Expand Up @@ -218,6 +220,7 @@ RegisteredMemory::Impl::Impl(const std::vector<char>& serialization) {
auto entry = getTransportInfo(Transport::CudaIpc);
void* base;
if (this->isCuMemMapAlloc) {
#if (CUDA_FABRIC_SUPPORTED)
if (isFabricSupported()) {
CUmemGenericAllocationHandle handle;
MSCCLPP_CUTHROW(cuMemImportFromShareableHandle(&handle, entry.shareableHandle, CU_MEM_HANDLE_TYPE_FABRIC));
Expand All @@ -229,6 +232,9 @@ RegisteredMemory::Impl::Impl(const std::vector<char>& serialization) {
} else {
throw Error("Fabric is not supported", ErrorCode::InvalidUsage);
}
#else
throw Error("Only support cuMemMap with CUDA 12.4 or later", ErrorCode::InvalidUsage);
#endif
} else {
MSCCLPP_CUDATHROW(cudaIpcOpenMemHandle(&base, entry.cudaIpcBaseHandle, cudaIpcMemLazyEnablePeerAccess));
this->data = static_cast<char*>(base) + entry.cudaIpcOffsetFromBase;
Expand Down
12 changes: 6 additions & 6 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ std::string getHostName(int maxlen, const char delim) {
}

bool isNvlsSupported() {
static bool result = false;
static bool isChecked = false;
#if (CUDART_VERSION >= 12040)
[[maybe_unused]] static bool result = false;
[[maybe_unused]] static bool isChecked = false;
#if (CUDA_FABRIC_SUPPORTED)
if (!isChecked) {
int isMulticastSupported;
int isFabricSupported;
Expand All @@ -86,9 +86,9 @@ bool isNvlsSupported() {
}

bool isFabricSupported() {
static bool result = false;
static bool isChecked = false;
#if (CUDART_VERSION >= 12040)
[[maybe_unused]] static bool result = false;
[[maybe_unused]] static bool isChecked = false;
#if (CUDA_FABRIC_SUPPORTED)
if (!isChecked) {
int isFabricSupported;
CUdevice dev;
Expand Down

0 comments on commit d7b8519

Please sign in to comment.