From 2631077cdf6ea8eeeccf4f927f041670602b5220 Mon Sep 17 00:00:00 2001 From: liaogang Date: Fri, 28 Jul 2017 10:57:55 +0800 Subject: [PATCH 1/2] Check Insufficient Alloc in tensor --- paddle/framework/tensor.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/paddle/framework/tensor.h b/paddle/framework/tensor.h index d3f56b31cd..2edc981cdd 100644 --- a/paddle/framework/tensor.h +++ b/paddle/framework/tensor.h @@ -129,13 +129,16 @@ class Tensor { virtual platform::Place place() const = 0; }; - template + template struct PlaceholderImpl : public Placeholder { - PlaceholderImpl(PlaceType place, size_t size) - : ptr_(static_cast(memory::Alloc(place, size)), - memory::PODDeleter(place)), - place_(place), - size_(size) {} + PlaceholderImpl(Place place, size_t size) + : place_(place), + size_(size), + ptr_(static_cast(memory::Alloc(place, size)), + memory::PODDeleter(place)) { + PADDLE_ENFORCE(ptr_ != nullptr, "Insufficient %s memory to allocation.", + is_cpu_place(place_) ? "CPU" : "GPU"); + } virtual size_t size() const { return size_; } virtual platform::Place place() const { return place_; } @@ -143,7 +146,7 @@ class Tensor { virtual std::type_index type() const { return std::type_index(typeid(T)); } /*! the pointer of memory block. */ - std::unique_ptr> ptr_; + std::unique_ptr> ptr_; /*! the place of memory block. */ platform::Place place_; From 9e523ef64928df0184c3a8fd9435185ade4dac57 Mon Sep 17 00:00:00 2001 From: liaogang Date: Fri, 28 Jul 2017 11:41:07 +0800 Subject: [PATCH 2/2] FIX: order matter in Linux ! --- paddle/framework/tensor.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/framework/tensor.h b/paddle/framework/tensor.h index 2edc981cdd..039ab08374 100644 --- a/paddle/framework/tensor.h +++ b/paddle/framework/tensor.h @@ -132,10 +132,10 @@ class Tensor { template struct PlaceholderImpl : public Placeholder { PlaceholderImpl(Place place, size_t size) - : place_(place), - size_(size), - ptr_(static_cast(memory::Alloc(place, size)), - memory::PODDeleter(place)) { + : ptr_(static_cast(memory::Alloc(place, size)), + memory::PODDeleter(place)), + place_(place), + size_(size) { PADDLE_ENFORCE(ptr_ != nullptr, "Insufficient %s memory to allocation.", is_cpu_place(place_) ? "CPU" : "GPU"); }