!19517 fix device bug of the input empty

Merge pull request !19517 from limingqi107/r1.3
This commit is contained in:
i-robot 2021-07-07 18:11:38 +00:00 committed by Gitee
commit 5770ee2921
2 changed files with 24 additions and 12 deletions

View File

@ -36,6 +36,11 @@ bool CPUDeviceAddress::DumpMemToFile(const std::string &filepath, const std::str
} }
bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector &, size_t size, TypeId type, void *host_ptr) const { bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector &, size_t size, TypeId type, void *host_ptr) const {
// The input or output may be empty.
if ((size == 0) || (size_ == 0)) {
MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_;
return true;
}
if (ptr_ == nullptr) { if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The pointer ptr_ is null!"; MS_LOG(ERROR) << "The pointer ptr_ is null!";
return false; return false;
@ -46,7 +51,7 @@ bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector &, size_t size, TypeId
} }
if (type == type_id_) { if (type == type_id_) {
if ((size == 0) || (size_ == 0) || (size > size_)) { if (size > size_) {
MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_; MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_;
return true; return true;
} }
@ -73,6 +78,11 @@ bool CPUDeviceAddress::SyncDeviceToHost(const ShapeVector &, size_t size, TypeId
bool CPUDeviceAddress::SyncHostToDevice(const ShapeVector & /* shape */, size_t size, TypeId type, const void *host_ptr, bool CPUDeviceAddress::SyncHostToDevice(const ShapeVector & /* shape */, size_t size, TypeId type, const void *host_ptr,
const std::string &format) const { const std::string &format) const {
// The input or output may be empty.
if ((size == 0) || (size_ == 0)) {
MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_;
return true;
}
if (ptr_ == nullptr) { if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The pointer ptr_ is null!"; MS_LOG(ERROR) << "The pointer ptr_ is null!";
return false; return false;
@ -83,7 +93,7 @@ bool CPUDeviceAddress::SyncHostToDevice(const ShapeVector & /* shape */, size_t
} }
if (type == type_id_) { if (type == type_id_) {
if ((size == 0) || (size_ == 0) || (size > size_)) { if (size > size_) {
MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_; MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_;
return true; return true;
} }

View File

@ -35,16 +35,17 @@ namespace mindspore {
namespace device { namespace device {
namespace gpu { namespace gpu {
bool GPUDeviceAddress::SyncDeviceToHost(size_t size, void *host_ptr) const { bool GPUDeviceAddress::SyncDeviceToHost(size_t size, void *host_ptr) const {
MS_EXCEPTION_IF_NULL(host_ptr); // The input or output may be empty.
if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The device address is null!";
return false;
}
bool need_sync = (size != 0) && (size_ != 0) && (size <= size_); bool need_sync = (size != 0) && (size_ != 0) && (size <= size_);
if (!need_sync) { if (!need_sync) {
MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_; MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_;
return true; return true;
} }
MS_EXCEPTION_IF_NULL(host_ptr);
if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The device address is null!";
return false;
}
auto &stream = GPUDeviceManager::GetInstance().default_stream(); auto &stream = GPUDeviceManager::GetInstance().default_stream();
MS_EXCEPTION_IF_NULL(stream); MS_EXCEPTION_IF_NULL(stream);
@ -64,16 +65,17 @@ bool GPUDeviceAddress::SyncDeviceToHost(size_t size, void *host_ptr) const {
} }
bool GPUDeviceAddress::SyncHostToDevice(size_t size, const void *host_ptr) const { bool GPUDeviceAddress::SyncHostToDevice(size_t size, const void *host_ptr) const {
MS_EXCEPTION_IF_NULL(host_ptr); // The input or output may be empty.
if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The device address is null!";
return false;
}
bool need_sync = (size != 0) && (size_ != 0) && (size <= size_); bool need_sync = (size != 0) && (size_ != 0) && (size <= size_);
if (!need_sync) { if (!need_sync) {
MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_; MS_LOG(INFO) << "No need sync, host size: " << size << ", device size: " << size_;
return true; return true;
} }
MS_EXCEPTION_IF_NULL(host_ptr);
if (ptr_ == nullptr) {
MS_LOG(ERROR) << "The device address is null!";
return false;
}
if (size != size_) { if (size != size_) {
// nccl kernel input and output device address is aligned, may lead to host size is not equal to device size // nccl kernel input and output device address is aligned, may lead to host size is not equal to device size