From d7b4390d15a2cdf48ce57598abfb1f838897c7ac Mon Sep 17 00:00:00 2001 From: Kenneth Moreland Date: Tue, 11 Jan 2022 07:15:41 -0700 Subject: [PATCH] Specify end position when filling values in Buffer This allows us to support `Fill` in `ArrayHandleView` and `ArrayHandleReverse`. --- vtkm/cont/ArrayHandle.h | 18 ++++++++++----- vtkm/cont/ArrayHandleBasic.h | 4 +++- vtkm/cont/ArrayHandleBitField.h | 16 +++++++++---- vtkm/cont/ArrayHandleCartesianProduct.h | 14 +++++++---- vtkm/cont/ArrayHandleCompositeVector.h | 11 ++++++--- vtkm/cont/ArrayHandleConcatenate.h | 16 +++++++++---- vtkm/cont/ArrayHandleDiscard.h | 1 + vtkm/cont/ArrayHandleExtractComponent.h | 1 + vtkm/cont/ArrayHandleGroupVec.h | 1 + vtkm/cont/ArrayHandleGroupVecVariable.h | 1 + vtkm/cont/ArrayHandleMultiplexer.h | 12 +++++++--- vtkm/cont/ArrayHandlePermutation.h | 6 ++++- vtkm/cont/ArrayHandleRecombineVec.h | 1 + vtkm/cont/ArrayHandleReverse.h | 11 +++------ vtkm/cont/ArrayHandleSOA.h | 4 +++- vtkm/cont/ArrayHandleStride.h | 6 ++++- vtkm/cont/ArrayHandleView.h | 13 +++++++++-- vtkm/cont/ArrayHandleZip.h | 5 ++-- vtkm/cont/BitField.cxx | 2 +- vtkm/cont/Storage.h | 4 +++- vtkm/cont/internal/Buffer.cxx | 16 ++++++++++--- vtkm/cont/internal/Buffer.h | 7 +++--- vtkm/cont/internal/testing/UnitTestBuffer.cxx | 23 +++++++++++++------ .../UnitTestArrayHandleConcatenate.cxx | 4 ++-- 24 files changed, 138 insertions(+), 59 deletions(-) diff --git a/vtkm/cont/ArrayHandle.h b/vtkm/cont/ArrayHandle.h index dd4e5dfa7..a1c6f4c47 100644 --- a/vtkm/cont/ArrayHandle.h +++ b/vtkm/cont/ArrayHandle.h @@ -558,7 +558,7 @@ public: if (startIndex < numberOfValues) { - this->Fill(fillValue, startIndex, token); + this->Fill(fillValue, startIndex, numberOfValues, token); } } @@ -580,20 +580,26 @@ public: /// @{ /// \brief Fills the array with a given value. /// - /// After calling this method, every entry in the array from `startIndex` to the - /// end of the array is set to `fillValue`. If `startIndex` is not specified, then - /// every entry is set to the fill value. + /// After calling this method, every entry in the array from `startIndex` to `endIndex`. + /// of the array is set to `fillValue`. If `startIndex` or `endIndex` is not specified, + /// then the fill happens from the begining or end, respectively. /// VTKM_CONT void Fill(const ValueType& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) const { - StorageType::Fill(this->GetBuffers(), fillValue, startIndex, token); + StorageType::Fill(this->GetBuffers(), fillValue, startIndex, endIndex, token); + } + VTKM_CONT void Fill(const ValueType& fillValue, vtkm::Id startIndex, vtkm::Id endIndex) const + { + vtkm::cont::Token token; + this->Fill(fillValue, startIndex, endIndex, token); } VTKM_CONT void Fill(const ValueType& fillValue, vtkm::Id startIndex = 0) const { vtkm::cont::Token token; - this->Fill(fillValue, startIndex, token); + this->Fill(fillValue, startIndex, this->GetNumberOfValues(), token); } /// @} diff --git a/vtkm/cont/ArrayHandleBasic.h b/vtkm/cont/ArrayHandleBasic.h index a7d31d838..d99f62a92 100644 --- a/vtkm/cont/ArrayHandleBasic.h +++ b/vtkm/cont/ArrayHandleBasic.h @@ -55,11 +55,13 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const T& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { constexpr vtkm::BufferSizeType fillValueSize = static_cast(sizeof(fillValue)); - buffers[0].Fill(&fillValue, fillValueSize, startIndex * fillValueSize, token); + buffers[0].Fill( + &fillValue, fillValueSize, startIndex * fillValueSize, endIndex * fillValueSize, token); } VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer* buffers, diff --git a/vtkm/cont/ArrayHandleBitField.h b/vtkm/cont/ArrayHandleBitField.h index 9d2a0c18d..657b34b74 100644 --- a/vtkm/cont/ArrayHandleBitField.h +++ b/vtkm/cont/ArrayHandleBitField.h @@ -113,19 +113,27 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, bool fillValue, vtkm::Id startBit, + vtkm::Id endBit, vtkm::cont::Token& token) { constexpr vtkm::BufferSizeType wordTypeSize = static_cast(sizeof(WordType)); - if ((startBit % (wordTypeSize * CHAR_BIT)) == 0) + constexpr vtkm::BufferSizeType wordNumBits = wordTypeSize * CHAR_BIT; + // Special case where filling to end of array. + vtkm::Id totalBitsInArray = GetNumberOfValues(buffers); + if (endBit >= totalBitsInArray) + { + endBit = ((totalBitsInArray + (wordNumBits - 1)) / wordNumBits) * wordNumBits; + } + if (((startBit % wordNumBits) == 0) && ((endBit % wordNumBits) == 0)) { WordType fillWord = (fillValue ? ~WordType{ 0 } : WordType{ 0 }); - buffers[0].Fill(&fillWord, wordTypeSize, startBit / CHAR_BIT, token); + buffers[0].Fill(&fillWord, wordTypeSize, startBit / CHAR_BIT, endBit / CHAR_BIT, token); } - else if ((startBit % CHAR_BIT) == 0) + else if (((startBit % CHAR_BIT) == 0) && ((endBit % CHAR_BIT) == 0)) { vtkm::UInt8 fillWord = (fillValue ? ~vtkm::UInt8{ 0 } : vtkm::UInt8{ 0 }); - buffers[0].Fill(&fillWord, 1, startBit / CHAR_BIT, token); + buffers[0].Fill(&fillWord, 1, startBit / CHAR_BIT, endBit / CHAR_BIT, token); } else { diff --git a/vtkm/cont/ArrayHandleCartesianProduct.h b/vtkm/cont/ArrayHandleCartesianProduct.h index 35d76b1ea..79b8aaf49 100644 --- a/vtkm/cont/ArrayHandleCartesianProduct.h +++ b/vtkm/cont/ArrayHandleCartesianProduct.h @@ -251,16 +251,20 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const vtkm::Vec& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { - if (startIndex != 0) + if ((startIndex != 0) || (endIndex != GetNumberOfValues(buffers))) { throw vtkm::cont::ErrorBadValue( - "Fill for ArrayHandleCartesianProduct must have startIndex == 0"); + "Fill for ArrayHandleCartesianProduct can only be used to fill entire array."); } - Storage1::Fill(Buffers1(buffers), fillValue[0], startIndex, token); - Storage2::Fill(Buffers2(buffers), fillValue[1], startIndex, token); - Storage3::Fill(Buffers3(buffers), fillValue[2], startIndex, token); + Storage1::Fill( + Buffers1(buffers), fillValue[0], 0, Storage1::GetNumberOfValues(Buffers1(buffers)), token); + Storage2::Fill( + Buffers2(buffers), fillValue[1], 0, Storage2::GetNumberOfValues(Buffers2(buffers)), token); + Storage3::Fill( + Buffers3(buffers), fillValue[2], 0, Storage3::GetNumberOfValues(Buffers3(buffers)), token); } VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer* buffers, diff --git a/vtkm/cont/ArrayHandleCompositeVector.h b/vtkm/cont/ArrayHandleCompositeVector.h index a47990765..c7e22667e 100644 --- a/vtkm/cont/ArrayHandleCompositeVector.h +++ b/vtkm/cont/ArrayHandleCompositeVector.h @@ -273,11 +273,15 @@ private: vtkm::cont::internal::Buffer* buffers, const ValueType& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { auto init_list = { ( - vtkm::tuple_element_t::Fill( - Buffers(buffers), fillValue[static_cast(Is)], startIndex, token), + vtkm::tuple_element_t::Fill(Buffers(buffers), + fillValue[static_cast(Is)], + startIndex, + endIndex, + token), false)... }; (void)init_list; } @@ -324,9 +328,10 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const ValueType& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { - FillImpl(IndexList{}, buffers, fillValue, startIndex, token); + FillImpl(IndexList{}, buffers, fillValue, startIndex, endIndex, token); } VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer* buffers, diff --git a/vtkm/cont/ArrayHandleConcatenate.h b/vtkm/cont/ArrayHandleConcatenate.h index 98034c2db..b29d7abaa 100644 --- a/vtkm/cont/ArrayHandleConcatenate.h +++ b/vtkm/cont/ArrayHandleConcatenate.h @@ -205,17 +205,23 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const T& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { vtkm::Id size1 = SourceStorage1::GetNumberOfValues(Buffers1(buffers)); - if (startIndex < size1) + if ((startIndex < size1) && (endIndex <= size1)) { - SourceStorage1::Fill(Buffers1(buffers), fillValue, startIndex, token); - SourceStorage2::Fill(Buffers2(buffers), fillValue, 0, token); + SourceStorage1::Fill(Buffers1(buffers), fillValue, startIndex, endIndex, token); } - else + else if (startIndex < size1) // && (endIndex > size1) { - SourceStorage2::Fill(Buffers2(buffers), fillValue, startIndex - size1, token); + SourceStorage1::Fill(Buffers1(buffers), fillValue, startIndex, size1, token); + SourceStorage2::Fill(Buffers2(buffers), fillValue, 0, endIndex - size1, token); + } + else // startIndex >= size1 + { + SourceStorage2::Fill( + Buffers2(buffers), fillValue, startIndex - size1, endIndex - size1, token); } } diff --git a/vtkm/cont/ArrayHandleDiscard.h b/vtkm/cont/ArrayHandleDiscard.h index a2d528e02..c3ce2bb45 100644 --- a/vtkm/cont/ArrayHandleDiscard.h +++ b/vtkm/cont/ArrayHandleDiscard.h @@ -122,6 +122,7 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, const ValueType&, vtkm::Id, + vtkm::Id, vtkm::cont::Token&) { // Fill is a NO-OP. diff --git a/vtkm/cont/ArrayHandleExtractComponent.h b/vtkm/cont/ArrayHandleExtractComponent.h index 78a683239..f91ef9612 100644 --- a/vtkm/cont/ArrayHandleExtractComponent.h +++ b/vtkm/cont/ArrayHandleExtractComponent.h @@ -132,6 +132,7 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, const ValueType&, vtkm::Id, + vtkm::Id, vtkm::cont::Token&) { throw vtkm::cont::ErrorBadType("Fill not supported for ArrayHandleExtractComponent."); diff --git a/vtkm/cont/ArrayHandleGroupVec.h b/vtkm/cont/ArrayHandleGroupVec.h index 3e02cccc5..c54be0f44 100644 --- a/vtkm/cont/ArrayHandleGroupVec.h +++ b/vtkm/cont/ArrayHandleGroupVec.h @@ -150,6 +150,7 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, const ValueType&, vtkm::Id, + vtkm::Id, vtkm::cont::Token&) { throw vtkm::cont::ErrorBadType("Fill not supported for ArrayHandleGroupVec."); diff --git a/vtkm/cont/ArrayHandleGroupVecVariable.h b/vtkm/cont/ArrayHandleGroupVecVariable.h index 5319ae25a..55fe437c7 100644 --- a/vtkm/cont/ArrayHandleGroupVecVariable.h +++ b/vtkm/cont/ArrayHandleGroupVecVariable.h @@ -161,6 +161,7 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, const vtkm::VecFromPortal&, vtkm::Id, + vtkm::Id, vtkm::cont::Token&) { throw vtkm::cont::ErrorBadType("Fill not supported for ArrayHandleGroupVecVariable."); diff --git a/vtkm/cont/ArrayHandleMultiplexer.h b/vtkm/cont/ArrayHandleMultiplexer.h index 1b4fe7cc4..0d70ff529 100644 --- a/vtkm/cont/ArrayHandleMultiplexer.h +++ b/vtkm/cont/ArrayHandleMultiplexer.h @@ -177,9 +177,10 @@ struct MultiplexerFillFunctor vtkm::cont::internal::Buffer* buffers, const ValueType& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) const { - StorageType::Fill(buffers, fillValue, startIndex, token); + StorageType::Fill(buffers, fillValue, startIndex, endIndex, token); } }; @@ -272,10 +273,15 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const ValueType& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { - Variant(buffers).CastAndCall( - detail::MultiplexerFillFunctor{}, ArrayBuffers(buffers), fillValue, startIndex, token); + Variant(buffers).CastAndCall(detail::MultiplexerFillFunctor{}, + ArrayBuffers(buffers), + fillValue, + startIndex, + endIndex, + token); } VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer* buffers, diff --git a/vtkm/cont/ArrayHandlePermutation.h b/vtkm/cont/ArrayHandlePermutation.h index 83731c57e..1ad536904 100644 --- a/vtkm/cont/ArrayHandlePermutation.h +++ b/vtkm/cont/ArrayHandlePermutation.h @@ -140,7 +140,11 @@ public: return IndexStorage::GetNumberOfValues(IndexBuffers(buffers)); } - VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, const T&, vtkm::Id, vtkm::cont::Token&) + VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, + const T&, + vtkm::Id, + vtkm::Id, + vtkm::cont::Token&) { throw vtkm::cont::ErrorBadType("Fill not supported for ArrayHandlePermutation."); } diff --git a/vtkm/cont/ArrayHandleRecombineVec.h b/vtkm/cont/ArrayHandleRecombineVec.h index a8f165d7e..380d78fc5 100644 --- a/vtkm/cont/ArrayHandleRecombineVec.h +++ b/vtkm/cont/ArrayHandleRecombineVec.h @@ -445,6 +445,7 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, const vtkm::internal::RecombineVec&, vtkm::Id, + vtkm::Id, vtkm::cont::Token&) { throw vtkm::cont::ErrorBadType("Fill not supported for ArrayHandleRecombineVec."); diff --git a/vtkm/cont/ArrayHandleReverse.h b/vtkm/cont/ArrayHandleReverse.h index 6074648e7..a66ca9f07 100644 --- a/vtkm/cont/ArrayHandleReverse.h +++ b/vtkm/cont/ArrayHandleReverse.h @@ -149,16 +149,11 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const T& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { - if (startIndex == 0) - { - SourceStorage::Fill(buffers, fillValue, 0, token); - } - else - { - throw vtkm::cont::ErrorBadValue("ArrayHandleReverse cannot Fill partial array."); - } + vtkm::Id numValues = GetNumberOfValues(buffers); + SourceStorage::Fill(buffers, fillValue, numValues - endIndex, numValues - startIndex, token); } VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer* buffers, diff --git a/vtkm/cont/ArrayHandleSOA.h b/vtkm/cont/ArrayHandleSOA.h index 22cee8d2b..c69be342e 100644 --- a/vtkm/cont/ArrayHandleSOA.h +++ b/vtkm/cont/ArrayHandleSOA.h @@ -165,15 +165,17 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const ValueType& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { constexpr vtkm::BufferSizeType sourceSize = static_cast(sizeof(ComponentType)); vtkm::BufferSizeType startByte = startIndex * sourceSize; + vtkm::BufferSizeType endByte = endIndex * sourceSize; for (vtkm::IdComponent componentIndex = 0; componentIndex < NUM_COMPONENTS; ++componentIndex) { ComponentType source = fillValue[componentIndex]; - buffers[componentIndex].Fill(&source, sourceSize, startByte, token); + buffers[componentIndex].Fill(&source, sourceSize, startByte, endByte, token); } } diff --git a/vtkm/cont/ArrayHandleStride.h b/vtkm/cont/ArrayHandleStride.h index 68c65407e..cc7f8a081 100644 --- a/vtkm/cont/ArrayHandleStride.h +++ b/vtkm/cont/ArrayHandleStride.h @@ -175,7 +175,11 @@ public: return GetInfo(buffers).NumberOfValues; } - VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, const T&, vtkm::Id, vtkm::cont::Token&) + VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, + const T&, + vtkm::Id, + vtkm::Id, + vtkm::cont::Token&) { throw vtkm::cont::ErrorBadType("Fill not supported for ArrayHandleStride."); } diff --git a/vtkm/cont/ArrayHandleView.h b/vtkm/cont/ArrayHandleView.h index 0898cef7e..ae97a2396 100644 --- a/vtkm/cont/ArrayHandleView.h +++ b/vtkm/cont/ArrayHandleView.h @@ -168,9 +168,18 @@ public: return ReadPortalType(SourceStorage::CreateReadPortal(buffers + 1, device, token), indices); } - VTKM_CONT static void Fill(vtkm::cont::internal::Buffer*, const T&, vtkm::Id, vtkm::cont::Token&) + VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, + const T& fillValue, + vtkm::Id startIndex, + vtkm::Id endIndex, + vtkm::cont::Token& token) { - throw vtkm::cont::ErrorBadType("Fill not supported for ArrayHandleView."); + vtkm::internal::ViewIndices indices = buffers[0].GetMetaData(); + vtkm::Id adjustedStartIndex = startIndex + indices.StartIndex; + vtkm::Id adjustedEndIndex = (endIndex < indices.NumberOfValues) + ? endIndex + indices.StartIndex + : indices.NumberOfValues + indices.StartIndex; + SourceStorage::Fill(buffers, fillValue, adjustedStartIndex, adjustedEndIndex, token); } VTKM_CONT static WritePortalType CreateWritePortal(vtkm::cont::internal::Buffer* buffers, diff --git a/vtkm/cont/ArrayHandleZip.h b/vtkm/cont/ArrayHandleZip.h index 30b18b897..dcb649147 100644 --- a/vtkm/cont/ArrayHandleZip.h +++ b/vtkm/cont/ArrayHandleZip.h @@ -184,10 +184,11 @@ public: VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const ValueType& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token) { - FirstStorage::Fill(FirstArrayBuffers(buffers), fillValue.first, startIndex, token); - SecondStorage::Fill(SecondArrayBuffers(buffers), fillValue.second, startIndex, token); + FirstStorage::Fill(FirstArrayBuffers(buffers), fillValue.first, startIndex, endIndex, token); + SecondStorage::Fill(SecondArrayBuffers(buffers), fillValue.second, startIndex, endIndex, token); } VTKM_CONT static ReadPortalType CreateReadPortal(const vtkm::cont::internal::Buffer* buffers, diff --git a/vtkm/cont/BitField.cxx b/vtkm/cont/BitField.cxx index f780d95ae..cef32e6cd 100644 --- a/vtkm/cont/BitField.cxx +++ b/vtkm/cont/BitField.cxx @@ -74,7 +74,7 @@ void BitField::FillImpl(const void* word, vtkm::BufferSizeType wordSize, vtkm::cont::Token& token) const { - this->Buffer.Fill(word, wordSize, 0, token); + this->Buffer.Fill(word, wordSize, 0, this->Buffer.GetNumberOfBytes(), token); } void BitField::ReleaseResourcesExecution() diff --git a/vtkm/cont/Storage.h b/vtkm/cont/Storage.h index 6135d1f18..c5579666c 100644 --- a/vtkm/cont/Storage.h +++ b/vtkm/cont/Storage.h @@ -134,11 +134,12 @@ public: /// \brief Returns the number of entries allocated in the array. VTKM_CONT static vtkm::Id GetNumberOfValues(const vtkm::cont::internal::Buffer* buffers); - /// \brief Fills the array with the given value starting at the given index. + /// \brief Fills the array with the given value starting and ending at the given indices. /// VTKM_CONT static void Fill(vtkm::cont::internal::Buffer* buffers, const ValueType& fillValue, vtkm::Id startIndex, + vtkm::Id endIndex, vtkm::cont::Token& token); /// \brief Create a read-only portal on the specified device. @@ -192,6 +193,7 @@ struct StorageTraits> vtkm::cont::internal::Buffer*, \ const typename vtkm::cont::internal::StorageTraits::ValueType&, \ vtkm::Id, \ + vtkm::Id, \ vtkm::cont::Token&) \ { \ throw vtkm::cont::ErrorBadAllocation( \ diff --git a/vtkm/cont/internal/Buffer.cxx b/vtkm/cont/internal/Buffer.cxx index 28f533372..bc0a8fdc4 100644 --- a/vtkm/cont/internal/Buffer.cxx +++ b/vtkm/cont/internal/Buffer.cxx @@ -202,6 +202,7 @@ template void FillBuffer(const vtkm::cont::internal::Buffer& target, const vtkm::cont::internal::Buffer& source, vtkm::BufferSizeType start, + vtkm::BufferSizeType end, Device device, vtkm::cont::Token& token) { @@ -217,8 +218,16 @@ void FillBuffer(const vtkm::cont::internal::Buffer& target, } VTKM_ASSERT((targetSize % sourceSize) == 0); VTKM_ASSERT((start % sourceSize) == 0); + VTKM_ASSERT((end % sourceSize) == 0); + VTKM_ASSERT(end <= targetSize); + VTKM_ASSERT(end >= start); + if (end <= start) + { + // Nothing to set. + return; + } - vtkm::Id numSourceRepetitions = (targetSize - start) / sourceSize; + vtkm::Id numSourceRepetitions = (end - start) / sourceSize; if ((sourceSize >= 8) && ((sourceSize % 8) == 0)) { @@ -1107,6 +1116,7 @@ vtkm::cont::internal::BufferInfo Buffer::GetDeviceBufferInfo( void Buffer::Fill(const void* source, vtkm::BufferSizeType sourceSize, vtkm::BufferSizeType start, + vtkm::BufferSizeType end, vtkm::cont::Token& token) const { vtkm::cont::internal::Buffer sourceBuffer; @@ -1122,7 +1132,7 @@ void Buffer::Fill(const void* source, bool success = vtkm::cont::TryExecute([&](auto device) { if (this->IsAllocatedOnDevice(device)) { - FillBuffer(*this, sourceBuffer, start, device, token); + FillBuffer(*this, sourceBuffer, start, end, device, token); return true; } else @@ -1135,7 +1145,7 @@ void Buffer::Fill(const void* source, { // Likely the data was not on any device. Fill on any device. vtkm::cont::TryExecute([&](auto device) { - FillBuffer(*this, sourceBuffer, start, device, token); + FillBuffer(*this, sourceBuffer, start, end, device, token); return true; }); } diff --git a/vtkm/cont/internal/Buffer.h b/vtkm/cont/internal/Buffer.h index 542e541f7..b8dfc1d9a 100644 --- a/vtkm/cont/internal/Buffer.h +++ b/vtkm/cont/internal/Buffer.h @@ -314,14 +314,15 @@ public: /// /// Given a short `source` C array (defined on the host), sets all values in the buffer /// to that source. The `sourceSize`, in bytes, is also specified. You also specify an - /// offset to where the fill should `start`. Values before the `start` are not affected. + /// offset to where the fill should `start` and `end`. Values before the `start` and + /// after the `end` are not affected. /// - /// Both the size of the buffer (i.e. `GetNumberOfBytes`) and the `start` must be - /// divisible by `sourceSize`. + /// Both `start` and `end` must be divisible by `sourceSize`. /// VTKM_CONT void Fill(const void* source, vtkm::BufferSizeType sourceSize, vtkm::BufferSizeType start, + vtkm::BufferSizeType end, vtkm::cont::Token& token) const; VTKM_CONT bool operator==(const vtkm::cont::internal::Buffer& rhs) const diff --git a/vtkm/cont/internal/testing/UnitTestBuffer.cxx b/vtkm/cont/internal/testing/UnitTestBuffer.cxx index 9c0b1ba94..9e52fb35a 100644 --- a/vtkm/cont/internal/testing/UnitTestBuffer.cxx +++ b/vtkm/cont/internal/testing/UnitTestBuffer.cxx @@ -186,17 +186,26 @@ void DoTest() VTKM_TEST_ASSERT(buffer.IsAllocatedOnHost()); VTKM_TEST_ASSERT(!buffer.IsAllocatedOnDevice(device)); - std::cout << "Fill end of buffer" << std::endl; + std::cout << "Fill buffer" << std::endl; { + constexpr vtkm::BufferSizeType fillValueSize = static_cast(sizeof(T)); vtkm::cont::Token token; - T fillValue = 1.234f; - buffer.Fill( - &fillValue, static_cast(sizeof(fillValue)), BUFFER_SIZE / 2, token); - CheckPortal(MakePortal(buffer.ReadPointerHost(token), ARRAY_SIZE / 2)); + T fillValue1 = 1.234f; + T fillValue2 = 5.678f; + buffer.Fill(&fillValue1, fillValueSize, 0, BUFFER_SIZE * 2, token); + buffer.Fill(&fillValue2, fillValueSize, BUFFER_SIZE / 2, BUFFER_SIZE, token); const T* array = reinterpret_cast(buffer.ReadPointerHost(token)); - for (vtkm::Id index = (ARRAY_SIZE / 2); index < (ARRAY_SIZE * 2); ++index) + for (vtkm::Id index = 0; index < ARRAY_SIZE / 2; ++index) { - VTKM_TEST_ASSERT(array[index] == fillValue); + VTKM_TEST_ASSERT(array[index] == fillValue1); + } + for (vtkm::Id index = ARRAY_SIZE / 2; index < ARRAY_SIZE; ++index) + { + VTKM_TEST_ASSERT(array[index] == fillValue2); + } + for (vtkm::Id index = ARRAY_SIZE; index < ARRAY_SIZE * 2; ++index) + { + VTKM_TEST_ASSERT(array[index] == fillValue1); } } diff --git a/vtkm/cont/testing/UnitTestArrayHandleConcatenate.cxx b/vtkm/cont/testing/UnitTestArrayHandleConcatenate.cxx index a64c0a61a..e3d318c97 100644 --- a/vtkm/cont/testing/UnitTestArrayHandleConcatenate.cxx +++ b/vtkm/cont/testing/UnitTestArrayHandleConcatenate.cxx @@ -94,9 +94,9 @@ void TestConcatenateFill() VTKM_STATIC_ASSERT_MSG((ARRAY_SIZE % 2) == 0, "ARRAY_SIZE must be even for this test."); - concatArray.Fill(value0); - concatArray.Fill(value1, ARRAY_SIZE / 2); concatArray.Fill(value2, 3 * ARRAY_SIZE / 2); + concatArray.Fill(value1, ARRAY_SIZE / 2, 3 * ARRAY_SIZE / 2); + concatArray.Fill(value0, 0, ARRAY_SIZE / 2); vtkm::cont::printSummary_ArrayHandle(concatArray, std::cout, true);