|
|
@ -12,13 +12,14 @@
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "paddle/fluid/memory/allocation/naive_best_fit_allocator.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
#include "glog/logging.h"
|
|
|
|
#include "glog/logging.h"
|
|
|
|
#include "paddle/fluid/memory/allocation/naive_best_fit_allocator.h"
|
|
|
|
|
|
|
|
#include "paddle/fluid/memory/detail/buddy_allocator.h"
|
|
|
|
#include "paddle/fluid/memory/detail/buddy_allocator.h"
|
|
|
|
#include "paddle/fluid/memory/detail/system_allocator.h"
|
|
|
|
#include "paddle/fluid/memory/detail/system_allocator.h"
|
|
|
|
#include "paddle/fluid/platform/gpu_info.h"
|
|
|
|
#include "paddle/fluid/platform/gpu_info.h"
|
|
|
@ -125,7 +126,11 @@ class GPUBuddyAllocatorList {
|
|
|
|
BuddyAllocator *Get(int gpu_id) {
|
|
|
|
BuddyAllocator *Get(int gpu_id) {
|
|
|
|
auto pos = std::distance(
|
|
|
|
auto pos = std::distance(
|
|
|
|
devices_.begin(), std::find(devices_.begin(), devices_.end(), gpu_id));
|
|
|
|
devices_.begin(), std::find(devices_.begin(), devices_.end(), gpu_id));
|
|
|
|
PADDLE_ENFORCE_LT(pos, devices_.size());
|
|
|
|
PADDLE_ENFORCE_LT(pos, devices_.size(),
|
|
|
|
|
|
|
|
platform::errors::OutOfRange(
|
|
|
|
|
|
|
|
"The index exceeds the size of devices, the size of "
|
|
|
|
|
|
|
|
"devices is %d, the index is %d",
|
|
|
|
|
|
|
|
devices_.size(), pos));
|
|
|
|
|
|
|
|
|
|
|
|
std::call_once(*init_flags_[pos], [this, pos] {
|
|
|
|
std::call_once(*init_flags_[pos], [this, pos] {
|
|
|
|
platform::SetDeviceId(devices_[pos]);
|
|
|
|
platform::SetDeviceId(devices_[pos]);
|
|
|
@ -166,7 +171,8 @@ size_t Used<platform::CUDAPlace>(const platform::CUDAPlace &place) {
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
return GetGPUBuddyAllocator(place.device)->Used();
|
|
|
|
return GetGPUBuddyAllocator(place.device)->Used();
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("'CUDAPlace' is not supported in CPU only device.");
|
|
|
|
PADDLE_THROW(platform::errors::PermissionDenied(
|
|
|
|
|
|
|
|
"'CUDAPlace' is not supported in CPU only device."));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -195,7 +201,8 @@ void *Alloc<platform::CUDAPlace>(const platform::CUDAPlace &place,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
return ptr;
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("'CUDAPlace' is not supported in CPU only device.");
|
|
|
|
PADDLE_THROW(platform::errors::PermissionDenied(
|
|
|
|
|
|
|
|
"'CUDAPlace' is not supported in CPU only device."));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -205,7 +212,8 @@ void Free<platform::CUDAPlace>(const platform::CUDAPlace &place, void *p,
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
GetGPUBuddyAllocator(place.device)->Free(p);
|
|
|
|
GetGPUBuddyAllocator(place.device)->Free(p);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("'CUDAPlace' is not supported in CPU only device.");
|
|
|
|
PADDLE_THROW(platform::errors::PermissionDenied(
|
|
|
|
|
|
|
|
"'CUDAPlace' is not supported in CPU only device."));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -230,7 +238,8 @@ size_t Used<platform::CUDAPinnedPlace>(const platform::CUDAPinnedPlace &place) {
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
return GetCUDAPinnedBuddyAllocator()->Used();
|
|
|
|
return GetCUDAPinnedBuddyAllocator()->Used();
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("'CUDAPinnedPlace' is not supported in CPU only device.");
|
|
|
|
PADDLE_THROW(platform::errors::PermissionDenied(
|
|
|
|
|
|
|
|
"'CUDAPinnedPlace' is not supported in CPU only device."));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -250,7 +259,8 @@ void *Alloc<platform::CUDAPinnedPlace>(const platform::CUDAPinnedPlace &place,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
return ptr;
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("'CUDAPinnedPlace' is not supported in CPU only device.");
|
|
|
|
PADDLE_THROW(platform::errors::PermissionDenied(
|
|
|
|
|
|
|
|
"'CUDAPinnedPlace' is not supported in CPU only device."));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -260,7 +270,8 @@ void Free<platform::CUDAPinnedPlace>(const platform::CUDAPinnedPlace &place,
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
GetCUDAPinnedBuddyAllocator()->Free(p);
|
|
|
|
GetCUDAPinnedBuddyAllocator()->Free(p);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("'CUDAPinnedPlace' is not supported in CPU only device.");
|
|
|
|
PADDLE_THROW(platform::errors::PermissionDenied(
|
|
|
|
|
|
|
|
"'CUDAPinnedPlace' is not supported in CPU only device."));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -298,7 +309,8 @@ size_t Usage::operator()(const platform::CUDAPlace &gpu) const {
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
return Used(gpu);
|
|
|
|
return Used(gpu);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("'CUDAPlace' is not supported in CPU only device.");
|
|
|
|
PADDLE_THROW(platform::errors::PermissionDenied(
|
|
|
|
|
|
|
|
"'CUDAPlace' is not supported in CPU only device."));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -306,7 +318,8 @@ size_t Usage::operator()(const platform::CUDAPinnedPlace &cuda_pinned) const {
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
#ifdef PADDLE_WITH_CUDA
|
|
|
|
return Used(cuda_pinned);
|
|
|
|
return Used(cuda_pinned);
|
|
|
|
#else
|
|
|
|
#else
|
|
|
|
PADDLE_THROW("'CUDAPinnedPlace' is not supported in CPU only device.");
|
|
|
|
PADDLE_THROW(platform::errors::PermissionDenied(
|
|
|
|
|
|
|
|
"'CUDAPinnedPlace' is not supported in CPU only device."));
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // namespace legacy
|
|
|
|
} // namespace legacy
|
|
|
|