From e61cd66b76fa9719e531dbdef3a88c83904072e4 Mon Sep 17 00:00:00 2001 From: Collin Tod Date: Wed, 15 Jan 2025 21:33:02 +0000 Subject: [PATCH] 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 --- runtime/lib/ttnn/runtime.cpp | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/runtime/lib/ttnn/runtime.cpp b/runtime/lib/ttnn/runtime.cpp index c0465f329..22cc537c1 100644 --- a/runtime/lib/ttnn/runtime.cpp +++ b/runtime/lib/ttnn/runtime.cpp @@ -510,23 +510,12 @@ Tensor getOpOutputTensor(OpContext opContextHandle, return createNullTensor(); } - ::ttnn::Tensor hostTensor = ::ttnn::from_device(*outPtr); - ::ttnn::Tensor outCopy = - ::ttnn::to_layout(hostTensor, ::ttnn::ROW_MAJOR_LAYOUT, std::nullopt, - std::nullopt, static_cast<::ttnn::IDevice *>(nullptr)); - - void *src = ::tt::tt_metal::get_raw_host_data_ptr(outCopy); - std::uint32_t outCopySize = outCopy.volume() * outCopy.element_size(); - std::shared_ptr data = ::tt::runtime::utils::malloc_shared(outCopySize); - std::memcpy(data.get(), src, outCopySize); - - auto tensor = std::make_shared<::ttnn::Tensor>( - ttnn::createStorage(data.get(), outCopy.volume(), - ::tt::target::DataType::Float32), - outCopy.shape().value, ::ttnn::DataType::FLOAT32, - ::ttnn::Layout::ROW_MAJOR); + std::shared_ptr<::ttnn::Tensor> hostTensor = + std::make_shared<::ttnn::Tensor>(::ttnn::to_layout( + ::ttnn::from_device(*outPtr), ::ttnn::Layout::ROW_MAJOR, std::nullopt, + std::nullopt, static_cast<::ttnn::IDevice *>(nullptr))); - return Tensor(std::static_pointer_cast(tensor), nullptr, + return Tensor(std::static_pointer_cast(hostTensor), nullptr, DeviceRuntime::TTNN); }