Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uvm backend #1174

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions aten/src/ATen/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ void Context::setUserEnabledMkldnn(bool e) {
enabled_mkldnn = e;
}

bool Context::userEnabledUVM() const {
return enabled_uvm;
}

void Context::setUserEnabledUVM(bool e) {
enabled_uvm = e;
}

bool Context::userEnabledMove() const {
return enabled_move;
}

void Context::setUserEnabledMove(bool e) {
enabled_move = e;
}

bool Context::deterministicCuDNN() const {
return deterministic_cudnn;
}
Expand Down
11 changes: 10 additions & 1 deletion aten/src/ATen/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class TORCH_API Context {
static bool isPinnedPtr(void* data) {
return detail::getCUDAHooks().isPinnedPtr(data);
}
static bool isManagedPtr(void* data) {
return detail::getCUDAHooks().isManagedPtr(data);
}
static bool hasOpenMP();
static bool hasMKL();
static bool hasLAPACK();
Expand Down Expand Up @@ -119,6 +122,10 @@ class TORCH_API Context {
void setUserEnabledCuDNN(bool e);
bool userEnabledMkldnn() const;
void setUserEnabledMkldnn(bool e);
bool userEnabledUVM() const;
void setUserEnabledUVM(bool e);
bool userEnabledMove() const;
void setUserEnabledMove(bool e);
bool benchmarkCuDNN() const;
void setBenchmarkCuDNN(bool);
int benchmarkLimitCuDNN() const;
Expand Down Expand Up @@ -288,7 +295,9 @@ class TORCH_API Context {
bool allow_fp16_reduction_cublas = true;
bool enabled_mkldnn = true;
at::LinalgBackend linalg_preferred_backend = at::LinalgBackend::Default;
#ifdef C10_MOBILE
bool enabled_uvm = false;
bool enabled_move = false;
#ifdef C10_MOBILE
bool release_original_weights = true;
#else
bool release_original_weights = false;
Expand Down
14 changes: 11 additions & 3 deletions aten/src/ATen/EmptyTensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
#include <ATen/detail/CUDAHooksInterface.h>
#include <c10/core/CPUAllocator.h>
#include <c10/util/safe_numerics.h>
#include <ATen/Context.h>

#include <limits>

namespace at {
namespace detail {
namespace {
c10::Allocator* GetCPUAllocatorMaybePinned(bool pin_memory) {
if (pin_memory) {
return at::detail::getCUDAHooks().getPinnedMemoryAllocator();
if (at::globalContext().userEnabledUVM()) {
// When UVM is enabled, we only use a single allocator
// for all allocations.
return detail::getCUDAHooks().getCUDADeviceAllocator();
}
else {
if (pin_memory) {
return at::detail::getCUDAHooks().getPinnedMemoryAllocator();
}
return c10::GetCPUAllocator();
}
return c10::GetCPUAllocator();
}

constexpr uint64_t storage_max() {
Expand Down
4 changes: 4 additions & 0 deletions aten/src/ATen/core/TensorBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ class TORCH_API TensorBase {
return impl_->is_cpu();
}

inline void _set_new_device(Device dst_device) const {
impl_->_set_new_device(dst_device);
}

/// Returns if a `Tensor` has CUDA backend.
bool is_cuda() const {
// NB: this is not a native function to avoid dispatching overhead.
Expand Down
Loading