Skip to content

Commit 0b18496

Browse files
committed
Fix tensor post processing
This change fixes an issue with processing output tensors after they are pulled off the device when checking golden-ness. The resulting tensor had the first 32 bytes overwritten with seemingly uninitialized memory, resulting in nondeterministic failures during similarity checks. Now, the unadulterated tensor is returned. Fixes #1795
1 parent f30a198 commit 0b18496

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

runtime/lib/ttnn/runtime.cpp

+5-16
Original file line numberDiff line numberDiff line change
@@ -467,23 +467,12 @@ Tensor getOpOutputTensor(OpContext opContextHandle,
467467
return createNullTensor();
468468
}
469469

470-
::ttnn::Tensor hostTensor = ::ttnn::from_device(*outPtr);
471-
::ttnn::Tensor outCopy =
472-
::ttnn::to_layout(hostTensor, ::ttnn::ROW_MAJOR_LAYOUT, std::nullopt,
473-
std::nullopt, static_cast<::ttnn::IDevice *>(nullptr));
474-
475-
void *src = ::tt::tt_metal::get_raw_host_data_ptr(outCopy);
476-
std::uint32_t outCopySize = outCopy.volume() * outCopy.element_size();
477-
std::shared_ptr<void> data = ::tt::runtime::utils::malloc_shared(outCopySize);
478-
std::memcpy(data.get(), src, outCopySize);
479-
480-
auto tensor = std::make_shared<::ttnn::Tensor>(
481-
ttnn::createStorage<BorrowedStorage>(data.get(), outCopy.volume(),
482-
::tt::target::DataType::Float32),
483-
outCopy.shape().value, ::ttnn::DataType::FLOAT32,
484-
::ttnn::Layout::ROW_MAJOR);
470+
std::shared_ptr<::ttnn::Tensor> hostTensor =
471+
std::make_shared<::ttnn::Tensor>(::ttnn::to_layout(
472+
::ttnn::from_device(*outPtr), ::ttnn::Layout::ROW_MAJOR, std::nullopt,
473+
std::nullopt, static_cast<::ttnn::IDevice *>(nullptr)));
485474

486-
return Tensor(std::static_pointer_cast<void>(tensor), nullptr,
475+
return Tensor(std::static_pointer_cast<void>(hostTensor), nullptr,
487476
DeviceRuntime::TTNN);
488477
}
489478

0 commit comments

Comments
 (0)