!10601 [MS][LITE][GPU]fix bug: memory alloc over size

From: @chenzupeng
Reviewed-by: @ddwsky,@HilbertDavid
Signed-off-by: @ddwsky
This commit is contained in:
mindspore-ci-bot 2020-12-26 17:44:21 +08:00 committed by Gitee
commit 5488fe3fda
3 changed files with 6 additions and 4 deletions

View File

@ -137,7 +137,7 @@ void *OpenCLAllocator::Malloc(size_t size, const std::vector<size_t> &img_size,
uint32_t image_alignment = ocl_runtime_->GetImagePitchAlignment();
size = UP_ROUND(img_size[0], image_alignment) * img_size[1] * dtype_size;
}
if (size > MAX_MALLOC_SIZE) {
if (size > ocl_runtime_->GetMaxAllocSize()) {
MS_LOG(ERROR) << "MallocData out of max_size, size: " << size;
return nullptr;
}
@ -148,7 +148,7 @@ void *OpenCLAllocator::Malloc(size_t size, const std::vector<size_t> &img_size,
return host_ptr;
}
total_size_ += size;
const uint64_t max_size = ocl_runtime_->GetGlobalMemSize();
const uint64_t max_size = ocl_runtime_->GetGlobalMemSize() * 0.8;
if (total_size_ >= max_size) {
UnLock();
MS_LOG(ERROR) << "Mem pool out of max_size, total size: " << total_size_ << ", max size: " << max_size;

View File

@ -226,11 +226,11 @@ int OpenCLRuntime::Init() {
}
}
global_memery_size_ = device_->getInfo<CL_DEVICE_GLOBAL_MEM_SIZE>();
max_alloc_size_ = device_->getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>();
MS_LOG(INFO) << "Address space bits: " << device_->getInfo<CL_DEVICE_ADDRESS_BITS>();
MS_LOG(INFO) << "Global Mem Size: " << global_memery_size_;
MS_LOG(INFO) << "Global Mem Cache Size: " << global_memery_cachesize_;
MS_LOG(INFO) << "Max Alloc Size: " << device_->getInfo<CL_DEVICE_MAX_MEM_ALLOC_SIZE>();
MS_LOG(INFO) << "Max Alloc Size: " << max_alloc_size_;
MS_LOG(INFO) << "Compute Unit: " << compute_units_;
MS_LOG(INFO) << "Clock Frequency: " << max_freq_ << " MHz";

View File

@ -62,6 +62,7 @@ class OpenCLRuntime {
uint64_t GetMaxWorkGroupSize(const cl::Kernel &kernel);
uint32_t GetSubGroupSize(const cl::Kernel &kernel, const cl::NDRange &range = cl::NullRange);
uint64_t GetGlobalMemSize() { return global_memery_size_; }
uint64_t GetMaxAllocSize() { return max_alloc_size_; }
GpuInfo GetGpuInfo();
bool GetFp16Enable() const;
bool SetFp16Enable(bool enable);
@ -170,6 +171,7 @@ class OpenCLRuntime {
cl::Program binary_program_{0};
uint64_t global_memery_cachesize_{0};
uint64_t global_memery_size_{0};
uint64_t max_alloc_size_{0};
int max_work_group_size_{1};
uint32_t compute_units_{0};
uint32_t max_freq_{0};