[CPU] fix crash in resnet binary model (#9761)

This commit is contained in:
Tingqian Li 2022-02-22 20:23:20 +08:00 committed by GitHub
parent 6dc8b8b047
commit 51ef938385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -254,7 +254,17 @@ void MKLDNNInputNode::cloneBlobIfRequired() {
auto cloneBlob = [&, this] () {
MKLDNNMemory memory{ getEngine() };
memory.Create(memDesc, constOp->get_data_ptr());
// CVS-74980
// MKLDNN/oneDNN always allocate 1byte for element type with bitWidth < 8 (u4,u1...)
// but ngraph Constant uses actual bitWidth for data storage allocation
// in that case we make a copy to avoid overflow
if (constOp->get_byte_size() >= memDesc.getCurrentMemSize()) {
memory.Create(memDesc, constOp->get_data_ptr());
} else {
memory.Create(memDesc);
memcpy(memory.GetPtr(), constOp->get_data_ptr(), constOp->get_byte_size());
}
MKLDNNMemoryPtr ptr = MKLDNNMemoryPtr(new MKLDNNMemory(getEngine()));
ptr->Create(memDesc);