//============================================================================ // Copyright (c) Kitware, Inc. // All rights reserved. // See LICENSE.txt for details. // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notice for more information. // // Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS). // Copyright 2014 UT-Battelle, LLC. // Copyright 2014 Los Alamos National Security. // // Under the terms of Contract DE-NA0003525 with NTESS, // the U.S. Government retains certain rights in this software. // // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National // Laboratory (LANL), the U.S. Government retains certain rights in // this software. //============================================================================ #ifndef vtk_m_worklet_zfp_tool_h #define vtk_m_worklet_zfp_tool_h #include #include #include #include #include #include #include #include #include using ZFPWord = vtkm::UInt64; #include namespace vtkm { namespace worklet { namespace detail { class MemTransfer : public vtkm::worklet::WorkletMapField { public: VTKM_CONT MemTransfer() {} using ControlSignature = void(FieldIn<>, WholeArrayInOut<>); using ExecutionSignature = void(_1, _2); template VTKM_EXEC void operator()(const vtkm::Id id, PortalType& outValue) const { (void)id; (void)outValue; } }; //class MemTransfer size_t CalcMem3d(const vtkm::Id3 dims, const vtkm::UInt32 bits_per_block) { const size_t vals_per_block = 64; const size_t size = static_cast(dims[0] * dims[1] * dims[2]); size_t total_blocks = size / vals_per_block; const size_t bits_per_word = sizeof(ZFPWord) * 8; const size_t total_bits = bits_per_block * total_blocks; const size_t alloc_size = total_bits / bits_per_word; return alloc_size * sizeof(ZFPWord); } size_t CalcMem2d(const vtkm::Id2 dims, const vtkm::UInt32 bits_per_block) { constexpr size_t vals_per_block = 16; const size_t size = static_cast(dims[0] * dims[1]); size_t total_blocks = size / vals_per_block; constexpr size_t bits_per_word = sizeof(ZFPWord) * 8; const size_t total_bits = bits_per_block * total_blocks; const size_t alloc_size = total_bits / bits_per_word; return alloc_size * sizeof(ZFPWord); } size_t CalcMem1d(const vtkm::Id dims, const vtkm::UInt32 bits_per_block) { constexpr size_t vals_per_block = 4; const size_t size = static_cast(dims); size_t total_blocks = size / vals_per_block; constexpr size_t bits_per_word = sizeof(ZFPWord) * 8; const size_t total_bits = bits_per_block * total_blocks; const size_t alloc_size = total_bits / bits_per_word; return alloc_size * sizeof(ZFPWord); } } // namespace detail template T* GetVTKMPointer(vtkm::cont::ArrayHandle& handle) { typedef typename vtkm::cont::ArrayHandle HandleType; typedef typename HandleType::template ExecutionTypes::Portal PortalType; typedef typename vtkm::cont::ArrayPortalToIterators::IteratorType IteratorType; IteratorType iter = vtkm::cont::ArrayPortalToIterators(handle.GetPortalControl()).GetBegin(); return &(*iter); } template void DataDump(vtkm::cont::ArrayHandle handle, std::string fileName) { T* ptr = GetVTKMPointer(handle); vtkm::Id osize = handle.GetNumberOfValues(); FILE* fp = fopen(fileName.c_str(), "wb"); ; if (fp != NULL) { fwrite(ptr, sizeof(T), static_cast(osize), fp); } fclose(fp); } } // namespace worklet } // namespace vtkm #endif // vtk_m_worklet_zfp_tools_h