From e6d91c03a2453e0776c84eb3ffbf699e92b5628a Mon Sep 17 00:00:00 2001 From: AdityaAtulTewari Date: Wed, 26 Jun 2024 07:56:35 +0000 Subject: [PATCH] fixed missing load behavior --- pando-rt/src/global_ptr.cpp | 128 ++++++------------------------------ 1 file changed, 19 insertions(+), 109 deletions(-) diff --git a/pando-rt/src/global_ptr.cpp b/pando-rt/src/global_ptr.cpp index 189f4f5c..e514e984 100644 --- a/pando-rt/src/global_ptr.cpp +++ b/pando-rt/src/global_ptr.cpp @@ -149,18 +149,6 @@ void load(GlobalAddress srcGlobalAddr, std::size_t n, void* dstNativePtr) { #elif defined(PANDO_RT_USE_BACKEND_DRVX) - using BlockType = std::uint64_t; - const auto blockSize = sizeof(BlockType); - const auto numBlocks = n / blockSize; - const auto remainderBytes = n % blockSize; - - auto blockDst = static_cast(dstNativePtr); - auto blockSrc = srcGlobalAddr; - - const auto bytesRead = numBlocks * blockSize; - auto byteDst = static_cast(dstNativePtr) + bytesRead; - auto byteSrc = srcGlobalAddr + bytesRead; - #if defined(PANDO_RT_BYPASS) if (getBypassFlag()) { void *srcNativePtr = nullptr; @@ -169,59 +157,32 @@ void load(GlobalAddress srcGlobalAddr, std::size_t n, void* dstNativePtr) { DrvAPI::DrvAPIAddressToNative(srcGlobalAddr, &srcNativePtr, &blah); std::memcpy(dstNativePtr, srcNativePtr, n); DrvAPI::nop(1u); - } + } else { #else - for (std::size_t i = 0; i < numBlocks; i++) { - const auto bytesOffset = i * blockSize; - *(blockDst + i) = DrvAPI::read(blockSrc + bytesOffset); - } + { +#endif // PANDO_RT_BYPASS + using BlockType = std::uint64_t; + const auto blockSize = sizeof(BlockType); + const auto numBlocks = n / blockSize; + const auto remainderBytes = n % blockSize; - for (std::size_t i = 0; i < remainderBytes; i++) { - *(byteDst + i) = DrvAPI::read(byteSrc + i); - } -#endif + const auto blockDst = static_cast(dstNativePtr); + const auto blockSrc = srcGlobalAddr; + const auto bytesRead = numBlocks * blockSize; -// Adding an extra layer for message payload granularity -// Currently does not work for types more than 64 bits -// Kept for future usage -/* - using ChunkType = std::uint64_t; - using BlockType = std::uint16_t; - const auto chunkSize = sizeof(ChunkType); - const auto blockSize = sizeof(BlockType); - const auto numChunks = n / chunkSize; - const auto remainderBlocks = n % chunkSize; - const auto numBlocks = remainderBlocks / blockSize; - const auto remainderBytes = remainderBlocks % blockSize; - - if (numChunks > 0) { - auto chunkDst = static_cast(dstNativePtr); - auto chunkSrc = reinterpret_cast(srcGlobalAddr); - for (std::size_t i = 0; i < numChunks; i++) { - const auto offset = i * chunkSize; - *(chunkDst + i) = DrvAPI::read(chunkSrc + offset); - } - } + const auto byteDst = static_cast(dstNativePtr) + bytesRead; + const auto byteSrc = srcGlobalAddr + bytesRead; - const auto blocksRead = numChunks * chunkSize; - if (numBlocks > 0) { - auto blockDst = static_cast(dstNativePtr) + blocksRead; - auto blockSrc = reinterpret_cast(srcGlobalAddr) + blocksRead; for (std::size_t i = 0; i < numBlocks; i++) { - const auto offset = i * blockSize; - *(blockDst + i) = DrvAPI::read(blockSrc + offset); + const auto bytesOffset = i * blockSize; + *(blockDst + i) = DrvAPI::read(blockSrc + bytesOffset); } - } - const auto bytesRead = blocksRead + numBlocks * blockSize; - if (remainderBytes > 0) { - auto byteDst = static_cast(dstNativePtr) + bytesRead; - auto byteSrc = reinterpret_cast(srcGlobalAddr) + bytesRead; for (std::size_t i = 0; i < remainderBytes; i++) { *(byteDst + i) = DrvAPI::read(byteSrc + i); } } -*/ + #endif // PANDO_RT_USE_BACKEND_PREP } @@ -303,6 +264,9 @@ void store(GlobalAddress dstGlobalAddr, std::size_t n, const void* srcNativePtr) DrvAPI::nop(1u); } } else { +#else + { +#endif // PANDO_RT_BYPASS for (std::size_t i = 0; i < numBlocks; i++) { auto blockData = *(blockSrc + i); const auto offset = i * blockSize; @@ -314,63 +278,8 @@ void store(GlobalAddress dstGlobalAddr, std::size_t n, const void* srcNativePtr) DrvAPI::write(byteDst + i, byteData); } } -#else - for (std::size_t i = 0; i < numBlocks; i++) { - auto blockData = *(blockSrc + i); - const auto offset = i * blockSize; - DrvAPI::write(blockDst + offset, blockData); - } - for (std::size_t i = 0; i < remainderBytes; i++) { - auto byteData = *(byteSrc + i); - DrvAPI::write(byteDst + i, byteData); - } -#endif - -// Adding an extra layer for message payload granularity -// Currently does not work for types more than 64 bits -// Kept for future usage -/* - using ChunkType = std::uint64_t; - using BlockType = std::uint16_t; - const auto chunkSize = sizeof(ChunkType); - const auto blockSize = sizeof(BlockType); - const auto numChunks = n / chunkSize; - const auto remainderBlocks = n % chunkSize; - const auto numBlocks = remainderBlocks / blockSize; - const auto remainderBytes = remainderBlocks % blockSize; - - if (numChunks > 0) { - auto chunkSrc = static_cast(srcNativePtr); - auto chunkDst = reinterpret_cast(dstGlobalAddr); - for (std::size_t i = 0; i < numChunks; i++) { - auto chunkData = *(chunkSrc + i); - const auto offset = i * chunkSize; - DrvAPI::write(chunkDst + offset, chunkData); - } - } - const auto blocksWritten = numChunks * chunkSize; - if (numBlocks > 0) { - auto blockSrc = static_cast(srcNativePtr) + blocksWritten; - auto blockDst = reinterpret_cast(dstGlobalAddr) + blocksWritten; - for (std::size_t i = 0; i < numBlocks; i++) { - auto blockData = *(blockSrc + i); - const auto offset = i * blockSize; - DrvAPI::write(blockDst + offset, blockData); - } - } - - const auto bytesWritten = blocksWritten + numBlocks * blockSize; - if (remainderBytes > 0) { - auto byteSrc = static_cast(srcNativePtr) + bytesWritten; - auto byteDst = reinterpret_cast(dstGlobalAddr) + bytesWritten; - for (std::size_t i = 0; i < remainderBytes; i++) { - auto byteData = *(byteSrc + i); - DrvAPI::write(byteDst + i, byteData); - } - } -*/ #endif // PANDO_RT_USE_BACKEND_PREP } @@ -431,6 +340,7 @@ void dmaTransfer(GlobalAddress srcGlobalAddr, std::size_t n, GlobalAddress dstGl } #elif defined(PANDO_RT_USE_BACKEND_DRVX) std::byte* temp = new std::byte[n]; + if(temp == nullptr) PANDO_ABORT("CATASTROPHIC DATA MOVEMENT FAILURE"); load(srcGlobalAddr, n, temp); store(dstGlobalAddr, n, temp); delete[] temp;