VTK-m  2.0
ZFP2DCompressor.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_worklet_zfp_2d_compressor_h
11 #define vtk_m_worklet_zfp_2d_compressor_h
12 
13 #include <vtkm/Math.h>
14 #include <vtkm/cont/Algorithm.h>
15 #include <vtkm/cont/ArrayHandle.h>
18 #include <vtkm/cont/AtomicArray.h>
19 #include <vtkm/cont/Timer.h>
21 
24 
25 using ZFPWord = vtkm::UInt64;
26 
27 #include <stdio.h>
28 
29 namespace vtkm
30 {
31 namespace worklet
32 {
33 
34 
36 {
37 public:
38  template <typename Scalar, typename Storage>
41  const vtkm::Float64 requestedRate,
42  const vtkm::Id2 dims)
43  {
44  // DataDump(data, "uncompressed");
45  zfp::ZFPStream stream;
46  constexpr vtkm::Int32 topoDims = 2;
47  stream.SetRate(requestedRate, topoDims, vtkm::Float64());
48  //VTKM_ASSERT(
49 
50  // Check to see if we need to increase the block sizes
51  // in the case where dim[x] is not a multiple of 4
52 
53  vtkm::Id2 paddedDims = dims;
54  // ensure that we have block sizes
55  // that are a multiple of 4
56  if (paddedDims[0] % 4 != 0)
57  paddedDims[0] += 4 - dims[0] % 4;
58  if (paddedDims[1] % 4 != 0)
59  paddedDims[1] += 4 - dims[1] % 4;
60  constexpr vtkm::Id four = 4;
61  const vtkm::Id totalBlocks = (paddedDims[0] / four) * (paddedDims[1] / (four));
62 
63 
64  size_t outbits = zfp::detail::CalcMem2d(paddedDims, stream.minbits);
65  vtkm::Id outsize = vtkm::Id(outbits / sizeof(ZFPWord));
66 
68  // hopefully this inits/allocates the mem only on the device
70  vtkm::cont::Algorithm::Copy(zero, output);
71 
72  // launch 1 thread per zfp block
73  vtkm::cont::ArrayHandleCounting<vtkm::Id> blockCounter(0, 1, totalBlocks);
74 
75  // using Timer = vtkm::cont::Timer<vtkm::cont::DeviceAdapterTagSerial>;
76  // Timer timer;
78  zfp::Encode2(dims, paddedDims, stream.maxbits));
79  compressDispatcher.Invoke(blockCounter, data, output);
80 
81  // vtkm::Float64 time = timer.GetElapsedTime();
82  // size_t total_bytes = data.GetNumberOfValues() * sizeof(vtkm::Float64);
83  // vtkm::Float64 gB = vtkm::Float64(total_bytes) / (1024. * 1024. * 1024.);
84  // vtkm::Float64 rate = gB / time;
85  // std::cout<<"Compress time "<<time<<" sec\n";
86  // std::cout<<"Compress rate "<<rate<<" GB / sec\n";
87  // DataDump(output, "compressed");
88 
89  return output;
90  }
91 };
92 } // namespace worklet
93 } // namespace vtkm
94 #endif // vtk_m_worklet_zfp_2d_compressor_h
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
vtkm::worklet::zfp::ZFPStream::SetRate
vtkm::Float64 SetRate(const vtkm::Float64 rate, const vtkm::Int32 dims, T vtkmNotUsed(valueType))
Definition: ZFPStructs.h:36
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ArrayHandleConstant.h
vtkm::cont::Algorithm::Copy
static VTKM_CONT bool Copy(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:410
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ZFPTools.h
DispatcherMapField.h
vtkm::worklet::zfp::ZFPStream::minbits
vtkm::UInt32 minbits
Definition: ZFPStructs.h:30
vtkm::worklet::DispatcherMapField
Dispatcher for worklets that inherit from WorkletMapField.
Definition: DispatcherMapField.h:25
Math.h
Timer.h
Algorithm.h
vtkm::cont::ArrayHandleCounting< vtkm::Id >
vtkm::worklet::zfp::ZFPStream::maxbits
vtkm::UInt32 maxbits
Definition: ZFPStructs.h:31
vtkm::cont::ArrayHandleConstant
An array handle with a constant value.
Definition: ArrayHandleConstant.h:63
vtkm::worklet::zfp::Encode2
Definition: ZFPEncode2.h:69
vtkm::Vec< vtkm::Id, 2 >
ZFPEncode2.h
ArrayHandleCounting.h
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::ZFP2DCompressor::Compress
vtkm::cont::ArrayHandle< vtkm::Int64 > Compress(const vtkm::cont::ArrayHandle< Scalar, Storage > &data, const vtkm::Float64 requestedRate, const vtkm::Id2 dims)
Definition: ZFP2DCompressor.h:39
vtkm::worklet::zfp::ZFPStream
Definition: ZFPStructs.h:28
ZFPWord
vtkm::UInt64 ZFPWord
Definition: ZFPTools.h:24
vtkm::worklet::ZFP2DCompressor
Definition: ZFP2DCompressor.h:35
AtomicArray.h