//============================================================================ // 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. //============================================================================ #ifndef vtk_m_worklet_zfp_2d_compressor_h #define vtk_m_worklet_zfp_2d_compressor_h #include #include #include #include #include #include #include #include #include #include using ZFPWord = vtkm::UInt64; #include namespace vtkm { namespace worklet { class ZFP2DCompressor { public: template vtkm::cont::ArrayHandle Compress( const vtkm::cont::ArrayHandle& data, const vtkm::Float64 requestedRate, const vtkm::Id2 dims) { // DataDump(data, "uncompressed"); zfp::ZFPStream stream; constexpr vtkm::Int32 topoDims = 2; stream.SetRate(requestedRate, topoDims, vtkm::Float64()); //VTKM_ASSERT( // Check to see if we need to increase the block sizes // in the case where dim[x] is not a multiple of 4 vtkm::Id2 paddedDims = dims; // ensure that we have block sizes // that are a multiple of 4 if (paddedDims[0] % 4 != 0) paddedDims[0] += 4 - dims[0] % 4; if (paddedDims[1] % 4 != 0) paddedDims[1] += 4 - dims[1] % 4; constexpr vtkm::Id four = 4; const vtkm::Id totalBlocks = (paddedDims[0] / four) * (paddedDims[1] / (four)); size_t outbits = zfp::detail::CalcMem2d(paddedDims, stream.minbits); vtkm::Id outsize = vtkm::Id(outbits / sizeof(ZFPWord)); vtkm::cont::ArrayHandle output; // hopefully this inits/allocates the mem only on the device vtkm::cont::ArrayHandleConstant zero(0, outsize); vtkm::cont::Algorithm::Copy(zero, output); // launch 1 thread per zfp block vtkm::cont::ArrayHandleCounting blockCounter(0, 1, totalBlocks); // using Timer = vtkm::cont::Timer; // Timer timer; vtkm::worklet::DispatcherMapField compressDispatcher( zfp::Encode2(dims, paddedDims, stream.maxbits)); compressDispatcher.Invoke(blockCounter, data, output); // vtkm::Float64 time = timer.GetElapsedTime(); // size_t total_bytes = data.GetNumberOfValues() * sizeof(vtkm::Float64); // vtkm::Float64 gB = vtkm::Float64(total_bytes) / (1024. * 1024. * 1024.); // vtkm::Float64 rate = gB / time; // std::cout<<"Compress time "<