diff --git a/CMakeLists.txt b/CMakeLists.txt index 900bea3..37b9ed4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -219,6 +219,12 @@ if(WITH_OMPI OR WITH_MPICH) find_package(MPI REQUIRED) endif() +set(INFINICCL_MPI_DEVICE_AWARE_QUERY_SUPPORTED OFF) +if(WITH_OMPI OR WITH_MPICH) + infiniccl_configure_mpi_device_aware( + INFINICCL_MPI_DEVICE_AWARE_QUERY_SUPPORTED) +endif() + if(WITH_NCCL) infiniccl_configure_nccl(NCCL_INC NCCL_LIB NCCL_COMPILE_DEFINITIONS) include_directories(${NCCL_INC}) diff --git a/cmake/backends/MPI.cmake b/cmake/backends/MPI.cmake index db6c365..5eaaf8e 100644 --- a/cmake/backends/MPI.cmake +++ b/cmake/backends/MPI.cmake @@ -27,3 +27,150 @@ function(infiniccl_detect_mpi output) set(${output} "${_implementation}" PARENT_SCOPE) endfunction() + +function(infiniccl_configure_mpi_device_aware output) + set(_supported 0) + set(_probe_includes "") + set(_probe_libraries "") + set(_probe_compile_flags "") + set(_probe_link_flags "") + set(_probe_library_files "") + + if(WITH_OMPI) + set(_probe_includes "${MPI_CXX_INCLUDE_DIRS}") + if(TARGET MPI::MPI_CXX) + set(_probe_libraries MPI::MPI_CXX) + get_target_property(_mpi_imported_locations MPI::MPI_CXX + IMPORTED_LOCATION) + if(_mpi_imported_locations) + list(APPEND _probe_library_files ${_mpi_imported_locations}) + endif() + else() + set(_probe_libraries "${MPI_CXX_LIBRARIES}") + set(_probe_library_files "${_probe_libraries}") + set(_probe_compile_flags "${MPI_CXX_COMPILE_FLAGS}") + set(_probe_link_flags "${MPI_CXX_LINK_FLAGS}") + endif() + endif() + + set(_fingerprint + "gen=1|implementation=${WITH_OMPI}|includes=${_probe_includes}|libraries=${_probe_libraries}|compile_flags=${_probe_compile_flags}|link_flags=${_probe_link_flags}") + foreach(_library IN LISTS _probe_library_files) + if(EXISTS "${_library}") + set(_library_mtime "") + file(TIMESTAMP "${_library}" _library_mtime "%s") + string(APPEND _fingerprint "|mtime:${_library}=${_library_mtime}") + endif() + endforeach() + string(MD5 _fingerprint_md5 "${_fingerprint}") + + set(_reuse FALSE) + set(_cached_supported "") + set(_stamp + "${CMAKE_BINARY_DIR}/src/backends/mpi/ompi/device_support_config.stamp") + if(EXISTS "${_stamp}") + file(READ "${_stamp}" _stamp_text) + string(REPLACE "\n" ";" _stamp_lines "${_stamp_text}") + list(GET _stamp_lines 0 _stamp_md5) + list(LENGTH _stamp_lines _stamp_line_count) + if(_stamp_line_count GREATER 1 + AND "${_stamp_md5}" STREQUAL "${_fingerprint_md5}") + list(GET _stamp_lines 1 _cached_supported) + set(_reuse TRUE) + endif() + endif() + + if(NOT _reuse) + if(WITH_OMPI) + include(CheckCXXSourceCompiles) + include(CMakePushCheckState) + cmake_push_check_state(RESET) + + set(CMAKE_REQUIRED_INCLUDES ${_probe_includes}) + + set(CMAKE_REQUIRED_LIBRARIES ${_probe_libraries}) + if(_probe_compile_flags) + set(CMAKE_REQUIRED_FLAGS ${_probe_compile_flags}) + endif() + if(_probe_link_flags) + separate_arguments(_MPI_DEVICE_AWARE_LINK_OPTIONS NATIVE_COMMAND + "${_probe_link_flags}") + set(CMAKE_REQUIRED_LINK_OPTIONS + ${_MPI_DEVICE_AWARE_LINK_OPTIONS}) + endif() + + unset(_INFINICCL_MPI_HAS_OMPI_CUDA_QUERY CACHE) + unset(_INFINICCL_MPI_HAS_OMPI_CUDA_QUERY) + check_cxx_source_compiles(" + #include + #include + int main() { + return MPIX_Query_cuda_support(); + } + " _INFINICCL_MPI_HAS_OMPI_CUDA_QUERY) + cmake_pop_check_state() + + if(_INFINICCL_MPI_HAS_OMPI_CUDA_QUERY) + set(_supported 1) + endif() + endif() + + file(WRITE "${_stamp}" "${_fingerprint_md5}\n${_supported}") + else() + set(_supported "${_cached_supported}") + endif() + + set(_output + "${CMAKE_BINARY_DIR}/src/backends/mpi/ompi/device_support_config.h") + set(_extension_includes "") + set(_query_body "return false;") + if(_supported) + set(_extension_includes + "#include \n#include \n") + set(_query_body "return MPIX_Query_cuda_support() != 0;") + endif() + + string(CONCAT _content + "#ifndef INFINI_CCL_BACKENDS_MPI_OMPI_DEVICE_SUPPORT_CONFIG_H_\n" + "#define INFINI_CCL_BACKENDS_MPI_OMPI_DEVICE_SUPPORT_CONFIG_H_\n" + "\n" + "// Generated by `infiniccl_configure_mpi_device_aware()` at\n" + "// configure time from a compile-link probe against the selected MPI.\n" + "// Do not edit.\n" + "\n" + "${_extension_includes}" + "\n" + "namespace infini::ccl::mpi_config {\n" + "\n" + "inline constexpr bool kHasOmpiCudaQuery = ${_supported};\n" + "\n" + "inline bool QueryOmpiCudaSupport() {\n" + " ${_query_body}\n" + "}\n" + "\n" + "} // namespace infini::ccl::mpi_config\n" + "\n" + "#endif // INFINI_CCL_BACKENDS_MPI_OMPI_DEVICE_SUPPORT_CONFIG_H_\n") + + set(_header_changed TRUE) + if(EXISTS "${_output}") + file(READ "${_output}" _existing_content) + if(_existing_content STREQUAL "${_content}") + set(_header_changed FALSE) + endif() + endif() + if(_header_changed) + file(WRITE "${_output}" "${_content}") + message(STATUS + "MPI device-aware query: wrote ${_output}") + else() + message(STATUS + "MPI device-aware query: ${_output} unchanged") + endif() + + if(_supported) + set(${output} ON PARENT_SCOPE) + else() + set(${output} OFF PARENT_SCOPE) + endif() +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index affb03f..b2f962a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -280,6 +280,7 @@ if(WITH_OMPI) if(TARGET MPI::MPI_CXX) target_link_libraries(infiniccl PRIVATE MPI::MPI_CXX) endif() + endif() if(WITH_MPICH) diff --git a/src/backends/mpi/ompi/buffer_plan.h b/src/backends/mpi/ompi/buffer_plan.h new file mode 100644 index 0000000..5b826f9 --- /dev/null +++ b/src/backends/mpi/ompi/buffer_plan.h @@ -0,0 +1,166 @@ +#ifndef INFINI_CCL_BACKENDS_MPI_OMPI_BUFFER_PLAN_H_ +#define INFINI_CCL_BACKENDS_MPI_OMPI_BUFFER_PLAN_H_ + +#include +#include + +#include "runtime.h" + +namespace infini::ccl { + +namespace detail { + +using HostBuffer = std::unique_ptr; + +inline HostBuffer AllocateHostBuffer(std::size_t bytes) { + return HostBuffer(std::malloc(bytes), &std::free); +} + +template +bool IsDeviceBuffer(const void *ptr) { + return ptr != nullptr && GetMemorySpace(ptr) == MemorySpace::kDevice; +} + +} // namespace detail + +template +class MpiBufferPlan { + public: + using Rt = Runtime; + + enum class Mode { + kPair, + kAlias, + }; + + ReturnStatus Prepare(const void *send_buff, void *recv_buff, + std::size_t send_bytes, std::size_t recv_bytes, + bool allow_direct, void *stream, Mode mode) { + const bool send_active = send_bytes != 0; + const bool recv_active = recv_bytes != 0; + if (!send_active && !recv_active) { + return ReturnStatus::kSuccess; + } + + user_recv_buff_ = recv_buff; + recv_bytes_ = recv_bytes; + + const bool send_device = + send_active && detail::IsDeviceBuffer(send_buff); + const bool recv_device = + recv_active && detail::IsDeviceBuffer(recv_buff); + recv_is_device_ = recv_device; + + if (mode == Mode::kPair) { + return PreparePair(send_buff, recv_buff, send_bytes, recv_bytes, + allow_direct, stream, send_active, recv_active, + send_device, recv_device); + } + + return PrepareAlias(recv_buff, recv_bytes, allow_direct, stream, + send_active, recv_device); + } + + ReturnStatus Commit() { + if (!host_recv_buff_) { + return ReturnStatus::kSuccess; + } + + CHECK_STATUS(Rt, Rt::Memcpy(user_recv_buff_, host_recv_buff_.get(), + recv_bytes_, Rt::MemcpyHostToDevice)); + return ReturnStatus::kSuccess; + } + + const void *send_buff() const { return mpi_send_buff_; } + + void *recv_buff() const { return mpi_recv_buff_; } + + bool direct() const { return direct_; } + + private: + ReturnStatus PreparePair(const void *send_buff, void *recv_buff, + std::size_t send_bytes, std::size_t recv_bytes, + bool allow_direct, void *stream, bool send_active, + bool recv_active, bool send_device, + bool recv_device) { + direct_ = allow_direct && (!send_active || send_device) && + (!recv_active || recv_device); + if (direct_) { + if (send_device) { + CHECK_STATUS(Rt, Rt::StreamSynchronize( + static_cast(stream))); + } + + mpi_send_buff_ = send_buff; + mpi_recv_buff_ = recv_buff; + return ReturnStatus::kSuccess; + } + + if (send_device) { + CHECK_STATUS( + Rt, Rt::StreamSynchronize(static_cast(stream))); + host_send_buff_ = detail::AllocateHostBuffer(send_bytes); + if (!host_send_buff_) { + return ReturnStatus::kSystemError; + } + + CHECK_STATUS(Rt, Rt::Memcpy(host_send_buff_.get(), send_buff, send_bytes, + Rt::MemcpyDeviceToHost)); + mpi_send_buff_ = host_send_buff_.get(); + } else { + mpi_send_buff_ = send_buff; + } + + if (recv_device) { + host_recv_buff_ = detail::AllocateHostBuffer(recv_bytes); + if (!host_recv_buff_) { + return ReturnStatus::kSystemError; + } + mpi_recv_buff_ = host_recv_buff_.get(); + } else { + mpi_recv_buff_ = recv_buff; + } + + return ReturnStatus::kSuccess; + } + + ReturnStatus PrepareAlias(void *recv_buff, std::size_t recv_bytes, + bool allow_direct, void *stream, bool send_active, + bool recv_device) { + direct_ = allow_direct && recv_device && !send_active; + if (direct_) { + CHECK_STATUS( + Rt, Rt::StreamSynchronize(static_cast(stream))); + mpi_recv_buff_ = recv_buff; + return ReturnStatus::kSuccess; + } + + if (recv_device) { + CHECK_STATUS( + Rt, Rt::StreamSynchronize(static_cast(stream))); + host_recv_buff_ = detail::AllocateHostBuffer(recv_bytes); + if (!host_recv_buff_) { + return ReturnStatus::kSystemError; + } + + mpi_recv_buff_ = host_recv_buff_.get(); + } else { + mpi_recv_buff_ = recv_buff; + } + + return ReturnStatus::kSuccess; + } + + void *user_recv_buff_ = nullptr; + const void *mpi_send_buff_ = nullptr; + void *mpi_recv_buff_ = nullptr; + detail::HostBuffer host_send_buff_{nullptr, &std::free}; + detail::HostBuffer host_recv_buff_{nullptr, &std::free}; + std::size_t recv_bytes_ = 0; + bool recv_is_device_ = false; + bool direct_ = false; +}; + +} // namespace infini::ccl + +#endif // INFINI_CCL_BACKENDS_MPI_OMPI_BUFFER_PLAN_H_ diff --git a/src/backends/mpi/ompi/comm_instance.h b/src/backends/mpi/ompi/comm_instance.h index d0f3a9a..5193b4b 100644 --- a/src/backends/mpi/ompi/comm_instance.h +++ b/src/backends/mpi/ompi/comm_instance.h @@ -5,12 +5,15 @@ #include "checks.h" #include "communicator.h" +#include "device_support.h" namespace infini::ccl { struct OmpiInstance : public BackendCommInstance { MPI_Comm handle = MPI_COMM_NULL; + MpiDeviceSupport device_support = MpiDeviceSupport::kHostStaged; + OmpiInstance() { type = BackendType::kOmpi; } ~OmpiInstance() override { Destroy(); } diff --git a/src/backends/mpi/ompi/device_support.h b/src/backends/mpi/ompi/device_support.h new file mode 100644 index 0000000..11b8bd7 --- /dev/null +++ b/src/backends/mpi/ompi/device_support.h @@ -0,0 +1,84 @@ +#ifndef INFINI_CCL_BACKENDS_MPI_OMPI_DEVICE_SUPPORT_H_ +#define INFINI_CCL_BACKENDS_MPI_OMPI_DEVICE_SUPPORT_H_ + +#include +#include +#include + +#include "backends/mpi/ompi/device_support_config.h" +#include "device.h" + +namespace infini::ccl { + +enum class MpiDeviceSupport : std::uint8_t { + kHostStaged = 0, + kDeviceAware = 1, +}; + +enum class MpiDeviceAwareMode : std::uint8_t { + kAuto, + kOn, + kOff, +}; + +template +struct MpiDeviceTraits { + static constexpr bool kDeviceAwareCapable = false; + + static bool Query() { return false; } +}; + +template <> +struct MpiDeviceTraits { + static constexpr bool kDeviceAwareCapable = mpi_config::kHasOmpiCudaQuery; + + static bool Query() { return mpi_config::QueryOmpiCudaSupport(); } +}; + +template <> +struct MpiDeviceTraits { + // Add the vendor query here after MetaX MPI exposes a stable interface. + static constexpr bool kDeviceAwareCapable = false; + + static bool Query() { return false; } +}; + +inline MpiDeviceAwareMode MpiDeviceAwareModeFromEnv() { + const char *mode = std::getenv("INFINICCL_MPI_DEVICE_AWARE"); + if (mode == nullptr || std::strcmp(mode, "auto") == 0) { + return MpiDeviceAwareMode::kAuto; + } + if (std::strcmp(mode, "1") == 0) { + return MpiDeviceAwareMode::kOn; + } + if (std::strcmp(mode, "0") == 0) { + return MpiDeviceAwareMode::kOff; + } + return MpiDeviceAwareMode::kAuto; +} + +template +MpiDeviceSupport ResolveMpiDeviceSupport() { + const MpiDeviceAwareMode mode = MpiDeviceAwareModeFromEnv(); + if (mode == MpiDeviceAwareMode::kOff) { + return MpiDeviceSupport::kHostStaged; + } + if (mode == MpiDeviceAwareMode::kOn) { + return MpiDeviceSupport::kDeviceAware; + } + + if constexpr (!MpiDeviceTraits::kDeviceAwareCapable) { + return MpiDeviceSupport::kHostStaged; + } else { + return MpiDeviceTraits::Query() ? MpiDeviceSupport::kDeviceAware + : MpiDeviceSupport::kHostStaged; + } +} + +inline bool MpiDeviceAwareUsable(MpiDeviceSupport support) { + return support == MpiDeviceSupport::kDeviceAware; +} + +} // namespace infini::ccl + +#endif // INFINI_CCL_BACKENDS_MPI_OMPI_DEVICE_SUPPORT_H_ diff --git a/src/backends/mpi/ompi/impl/comm_init_all.h b/src/backends/mpi/ompi/impl/comm_init_all.h index 4812f9c..2cf8f8d 100644 --- a/src/backends/mpi/ompi/impl/comm_init_all.h +++ b/src/backends/mpi/ompi/impl/comm_init_all.h @@ -1,8 +1,11 @@ #ifndef INFINI_CCL_BACKENDS_MPI_OMPI_IMPL_COMM_INIT_ALL_H_ #define INFINI_CCL_BACKENDS_MPI_OMPI_IMPL_COMM_INIT_ALL_H_ +#include + #include "backends/mpi/ompi/checks.h" #include "backends/mpi/ompi/comm_instance.h" +#include "backends/mpi/ompi/device_support.h" #include "base/comm_init_all.h" #include "communicator.h" #include "logging.h" @@ -14,8 +17,7 @@ class CommInitAllImpl { public: static ReturnStatus Apply(Communicator *comm, int n_dev, const int *dev_list) { - constexpr Device::Type kDev = - ListGetBest(ActiveDevices{}); + constexpr Device::Type kDev = device_type; using Rt = Runtime; if (comm && comm->inter_comm()) { @@ -32,7 +34,6 @@ class CommInitAllImpl { comm->set_world_info(rank, size); comm->set_local_size(n_dev); - comm->set_inter_comm(std::move(inst)); int local_rank = 0; char *local_rank_str = getenv("OMPI_COMM_WORLD_LOCAL_RANK"); @@ -49,6 +50,17 @@ class CommInitAllImpl { CHECK_STATUS(Rt, Rt::SetDevice(comm->device_id())); + inst->device_support = ResolveMpiDeviceSupport(); + std::ostringstream message; + message << "Rank " << rank << " device " << Device::StringFromType(kDev) + << ": MPI device-aware transport: " + << (inst->device_support == MpiDeviceSupport::kDeviceAware + ? "enabled (device-direct)." + : "disabled (host-staged)."); + LOG(message.str().c_str(), Logger::LogLevel::kInfo); + + comm->set_inter_comm(std::move(inst)); + return ReturnStatus::kSuccess; } }; diff --git a/src/backends/mpi/ompi/impl/recv.h b/src/backends/mpi/ompi/impl/recv.h index b1422a5..58fadf6 100644 --- a/src/backends/mpi/ompi/impl/recv.h +++ b/src/backends/mpi/ompi/impl/recv.h @@ -1,9 +1,9 @@ #ifndef INFINI_CCL_BACKENDS_MPI_OMPI_IMPL_RECV_H_ #define INFINI_CCL_BACKENDS_MPI_OMPI_IMPL_RECV_H_ -#include #include +#include "backends/mpi/ompi/buffer_plan.h" #include "backends/mpi/ompi/checks.h" #include "backends/mpi/ompi/comm_instance.h" #include "base/recv.h" @@ -18,9 +18,7 @@ class RecvImpl { public: static ReturnStatus Apply(void *recv_buff, size_t count, DataType data_type, int peer, Communicator *comm, void *stream) { - constexpr Device::Type kDev = - ListGetBest(ActiveDevices{}); - using Rt = Runtime; + constexpr Device::Type kDev = device_type; auto *inst = static_cast(comm->inter_comm()); if (!inst || inst->handle == MPI_COMM_NULL) { @@ -34,14 +32,17 @@ class RecvImpl { return ReturnStatus::kInvalidArgument; } - size_t total_bytes = count * type_size; - void *host_buf = std::malloc(total_bytes); - if (!host_buf) { - LOG("Failed to allocate host buffer for `Recv` staging."); - return ReturnStatus::kSystemError; + const size_t total_bytes = count * type_size; + MpiBufferPlan plan; + ReturnStatus status = + plan.Prepare(nullptr, recv_buff, 0, total_bytes, + MpiDeviceAwareUsable(inst->device_support), stream, + MpiBufferPlan::Mode::kPair); + if (status != ReturnStatus::kSuccess) { + return status; } - auto *bytes = static_cast(host_buf); + auto *bytes = static_cast(plan.recv_buff()); size_t offset = 0; constexpr size_t kMaxMpiCount = static_cast(std::numeric_limits::max()); @@ -51,17 +52,14 @@ class RecvImpl { if (chunk > kMaxMpiCount) { chunk = kMaxMpiCount; } + INFINI_CHECK_MPI(MPI_Recv(bytes + offset, static_cast(chunk), MPI_BYTE, peer, kTag, inst->handle, MPI_STATUS_IGNORE)); offset += chunk; } - CHECK_STATUS(Rt, Rt::Memcpy(recv_buff, host_buf, total_bytes, - Rt::MemcpyHostToDevice)); - - std::free(host_buf); - return ReturnStatus::kSuccess; + return plan.Commit(); } }; diff --git a/src/backends/mpi/ompi/impl/send.h b/src/backends/mpi/ompi/impl/send.h index 16ea91d..315e25f 100644 --- a/src/backends/mpi/ompi/impl/send.h +++ b/src/backends/mpi/ompi/impl/send.h @@ -1,9 +1,9 @@ #ifndef INFINI_CCL_BACKENDS_MPI_OMPI_IMPL_SEND_H_ #define INFINI_CCL_BACKENDS_MPI_OMPI_IMPL_SEND_H_ -#include #include +#include "backends/mpi/ompi/buffer_plan.h" #include "backends/mpi/ompi/checks.h" #include "backends/mpi/ompi/comm_instance.h" #include "base/send.h" @@ -19,9 +19,7 @@ class SendImpl { static ReturnStatus Apply(const void *send_buff, size_t count, DataType data_type, int peer, Communicator *comm, void *stream) { - constexpr Device::Type kDev = - ListGetBest(ActiveDevices{}); - using Rt = Runtime; + constexpr Device::Type kDev = device_type; auto *inst = static_cast(comm->inter_comm()); if (!inst || inst->handle == MPI_COMM_NULL) { @@ -35,18 +33,17 @@ class SendImpl { return ReturnStatus::kInvalidArgument; } - size_t total_bytes = count * type_size; - void *host_buf = std::malloc(total_bytes); - if (!host_buf) { - LOG("Failed to allocate host buffer for `Send` staging."); - return ReturnStatus::kSystemError; + const size_t total_bytes = count * type_size; + MpiBufferPlan plan; + ReturnStatus status = + plan.Prepare(send_buff, nullptr, total_bytes, 0, + MpiDeviceAwareUsable(inst->device_support), stream, + MpiBufferPlan::Mode::kPair); + if (status != ReturnStatus::kSuccess) { + return status; } - CHECK_STATUS(Rt, Rt::Memcpy(host_buf, send_buff, total_bytes, - Rt::MemcpyDeviceToHost)); - CHECK_STATUS(Rt, Rt::StreamSynchronize(static_cast(stream))); - - auto *bytes = static_cast(host_buf); + const auto *bytes = static_cast(plan.send_buff()); size_t offset = 0; constexpr size_t kMaxMpiCount = static_cast(std::numeric_limits::max()); @@ -56,12 +53,12 @@ class SendImpl { if (chunk > kMaxMpiCount) { chunk = kMaxMpiCount; } + INFINI_CHECK_MPI(MPI_Send(bytes + offset, static_cast(chunk), MPI_BYTE, peer, kTag, inst->handle)); offset += chunk; } - std::free(host_buf); return ReturnStatus::kSuccess; } }; diff --git a/src/devices/metax/device_.h b/src/devices/metax/device_.h index 8f5e9a6..cffce64 100644 --- a/src/devices/metax/device_.h +++ b/src/devices/metax/device_.h @@ -5,7 +5,6 @@ #include // clang-format on -#include "checks.h" #include "device.h" namespace infini::ccl { @@ -20,7 +19,11 @@ MemorySpace GetMemorySpace(const void* ptr) { } mcPointerAttribute_t attr; - INFINI_CHECK_MACA(mcPointerGetAttributes(&attr, ptr)); + mcError_t status = mcPointerGetAttributes(&attr, ptr); + if (status != mcSuccess) { + mcGetLastError(); + return MemorySpace::kHost; + } if (attr.type == mcMemoryTypeDevice || attr.type == mcMemoryTypeManaged || attr.type == mcMemoryTypeArray) { diff --git a/src/devices/nvidia/device_.h b/src/devices/nvidia/device_.h index 87c6f90..e7d65b8 100644 --- a/src/devices/nvidia/device_.h +++ b/src/devices/nvidia/device_.h @@ -4,7 +4,6 @@ #include #include "device.h" -#include "devices/cuda/checks.h" namespace infini::ccl { @@ -18,7 +17,11 @@ MemorySpace GetMemorySpace(const void* ptr) { } cudaPointerAttributes attr; - INFINI_CHECK_CUDA(cudaPointerGetAttributes(&attr, ptr)); + cudaError_t status = cudaPointerGetAttributes(&attr, ptr); + if (status != cudaSuccess) { + cudaGetLastError(); + return MemorySpace::kHost; + } if (attr.type == cudaMemoryTypeDevice || attr.type == cudaMemoryTypeManaged) { return MemorySpace::kDevice;