VTK-m  2.0
ZFPDecompress.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_decompressor_h
11 #define vtk_m_worklet_zfp_decompressor_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>
23 
24 using ZFPWord = vtkm::UInt64;
25 
26 #include <stdio.h>
27 
28 namespace vtkm
29 {
30 namespace worklet
31 {
33 {
34 public:
35  template <typename Scalar, typename StorageIn, typename StorageOut>
38  const vtkm::Float64 requestedRate,
39  vtkm::Id3 dims)
40  {
41  //DataDumpb(data, "uncompressed");
42  zfp::ZFPStream stream;
43  const vtkm::Int32 topoDims = 3;
44  ;
45  stream.SetRate(requestedRate, topoDims, vtkm::Float64());
46 
47 
48  // Check to see if we need to increase the block sizes
49  // in the case where dim[x] is not a multiple of 4
50 
51  vtkm::Id3 paddedDims = dims;
52  // ensure that we have block sizes
53  // that are a multiple of 4
54  if (paddedDims[0] % 4 != 0)
55  paddedDims[0] += 4 - dims[0] % 4;
56  if (paddedDims[1] % 4 != 0)
57  paddedDims[1] += 4 - dims[1] % 4;
58  if (paddedDims[2] % 4 != 0)
59  paddedDims[2] += 4 - dims[2] % 4;
60  const vtkm::Id four = 4;
61  vtkm::Id totalBlocks =
62  (paddedDims[0] / four) * (paddedDims[1] / (four) * (paddedDims[2] / four));
63 
64 
65  zfp::detail::CalcMem3d(paddedDims, stream.minbits);
66 
67  // hopefully this inits/allocates the mem only on the device
68  output.Allocate(dims[0] * dims[1] * dims[2]);
69 
70  // launch 1 thread per zfp block
71  vtkm::cont::ArrayHandleCounting<vtkm::Id> blockCounter(0, 1, totalBlocks);
72 
73  // using Timer = vtkm::cont::Timer<vtkm::cont::DeviceAdapterTagSerial>;
74  // Timer timer;
76  zfp::Decode3(dims, paddedDims, stream.maxbits));
77  decompressDispatcher.Invoke(blockCounter, output, encodedData);
78 
79  // vtkm::Float64 time = timer.GetElapsedTime();
80  // size_t total_bytes = output.GetNumberOfValues() * sizeof(vtkm::Float64);
81  // vtkm::Float64 gB = vtkm::Float64(total_bytes) / (1024. * 1024. * 1024.);
82  // vtkm::Float64 rate = gB / time;
83  // std::cout<<"Decompress time "<<time<<" sec\n";
84  // std::cout<<"Decompress rate "<<rate<<" GB / sec\n";
85  // DataDump(output, "decompressed");
86  }
87 };
88 } // namespace worklet
89 } // namespace vtkm
90 #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::cont::ArrayHandle::Allocate
VTKM_CONT void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:465
ArrayHandleConstant.h
vtkm::worklet::ZFPDecompressor::Decompress
void Decompress(const vtkm::cont::ArrayHandle< vtkm::Int64, StorageIn > &encodedData, vtkm::cont::ArrayHandle< Scalar, StorageOut > &output, const vtkm::Float64 requestedRate, vtkm::Id3 dims)
Definition: ZFPDecompress.h:36
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::ZFPDecompressor
Definition: ZFPDecompress.h:32
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::Decode3
Definition: ZFPDecode3.h:70
vtkm::worklet::zfp::ZFPStream::maxbits
vtkm::UInt32 maxbits
Definition: ZFPStructs.h:31
vtkm::Vec< vtkm::Id, 3 >
ArrayHandleCounting.h
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::Float64
double Float64
Definition: Types.h:155
ZFPDecode3.h
vtkm::worklet::zfp::ZFPStream
Definition: ZFPStructs.h:28
ZFPWord
vtkm::UInt64 ZFPWord
Definition: ZFPTools.h:24
AtomicArray.h