VTK-m  2.0
ZFPCompressor.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_compressor_h
11 #define vtk_m_worklet_zfp_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 
35 {
36 public:
37  template <typename Scalar, typename Storage>
40  const vtkm::Float64 requestedRate,
41  const vtkm::Id3 dims)
42  {
43  // DataDump(data, "uncompressed");
44  zfp::ZFPStream stream;
45  const vtkm::Int32 topoDims = 3;
46  stream.SetRate(requestedRate, topoDims, vtkm::Float64());
47  //VTKM_ASSERT(
48 
49  // Check to see if we need to increase the block sizes
50  // in the case where dim[x] is not a multiple of 4
51 
52  vtkm::Id3 paddedDims = dims;
53  // ensure that we have block sizes
54  // that are a multiple of 4
55  if (paddedDims[0] % 4 != 0)
56  paddedDims[0] += 4 - dims[0] % 4;
57  if (paddedDims[1] % 4 != 0)
58  paddedDims[1] += 4 - dims[1] % 4;
59  if (paddedDims[2] % 4 != 0)
60  paddedDims[2] += 4 - dims[2] % 4;
61  const vtkm::Id four = 4;
62  vtkm::Id totalBlocks =
63  (paddedDims[0] / four) * (paddedDims[1] / (four) * (paddedDims[2] / four));
64 
65 
66  size_t outbits = zfp::detail::CalcMem3d(paddedDims, stream.minbits);
67  vtkm::Id outsize = vtkm::Id(outbits / sizeof(ZFPWord));
68 
70  // hopefully this inits/allocates the mem only on the device
72  vtkm::cont::Algorithm::Copy(zero, output);
73 
74  // launch 1 thread per zfp block
75  vtkm::cont::ArrayHandleCounting<vtkm::Id> blockCounter(0, 1, totalBlocks);
76 
77  // using Timer = vtkm::cont::Timer<vtkm::cont::DeviceAdapterTagSerial>;
78  // Timer timer;
80  zfp::Encode3(dims, paddedDims, stream.maxbits));
81  compressDispatcher.Invoke(blockCounter, data, output);
82 
83  // vtkm::Float64 time = timer.GetElapsedTime();
84  // size_t total_bytes = data.GetNumberOfValues() * sizeof(vtkm::Float64);
85  // vtkm::Float64 gB = vtkm::Float64(total_bytes) / (1024. * 1024. * 1024.);
86  // vtkm::Float64 rate = gB / time;
87  // std::cout<<"Compress time "<<time<<" sec\n";
88  // std::cout<<"Compress rate "<<rate<<" GB / sec\n";
89  // DataDump(output, "compressed");
90 
91  return output;
92  }
93 };
94 } // namespace worklet
95 } // namespace vtkm
96 #endif // vtk_m_worklet_zfp_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
vtkm::worklet::zfp::Encode3
Definition: ZFPEncode3.h:88
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::worklet::ZFPCompressor::Compress
vtkm::cont::ArrayHandle< vtkm::Int64 > Compress(const vtkm::cont::ArrayHandle< Scalar, Storage > &data, const vtkm::Float64 requestedRate, const vtkm::Id3 dims)
Definition: ZFPCompressor.h:38
vtkm::cont::ArrayHandleCounting< vtkm::Id >
vtkm::worklet::ZFPCompressor
Definition: ZFPCompressor.h:34
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::Vec< vtkm::Id, 3 >
ArrayHandleCounting.h
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::zfp::ZFPStream
Definition: ZFPStructs.h:28
ZFPWord
vtkm::UInt64 ZFPWord
Definition: ZFPTools.h:24
AtomicArray.h
ZFPEncode3.h