VTK-m  2.0
ZFP2DDecompress.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_decompressor_h
11 #define vtk_m_worklet_zfp_2d_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 {
32 namespace detail
33 {
34 
35 
36 
37 } // namespace detail
38 
39 
41 {
42 public:
43  template <typename Scalar, typename StorageIn, typename StorageOut>
46  const vtkm::Float64 requestedRate,
47  vtkm::Id2 dims)
48  {
49  //DataDumpb(data, "uncompressed");
50  zfp::ZFPStream stream;
51  constexpr vtkm::Int32 topoDims = 2;
52  ;
53  stream.SetRate(requestedRate, topoDims, vtkm::Float64());
54 
55 
56  // Check to see if we need to increase the block sizes
57  // in the case where dim[x] is not a multiple of 4
58 
59  vtkm::Id2 paddedDims = dims;
60  // ensure that we have block sizes
61  // that are a multiple of 4
62  if (paddedDims[0] % 4 != 0)
63  paddedDims[0] += 4 - dims[0] % 4;
64  if (paddedDims[1] % 4 != 0)
65  paddedDims[1] += 4 - dims[1] % 4;
66  constexpr vtkm::Id four = 4;
67  vtkm::Id totalBlocks = (paddedDims[0] / four) * (paddedDims[1] / (four));
68 
69 
70  zfp::detail::CalcMem2d(paddedDims, stream.minbits);
71 
72  // hopefully this inits/allocates the mem only on the device
73  output.Allocate(dims[0] * dims[1]);
74 
75 
76  // launch 1 thread per zfp block
77  vtkm::cont::ArrayHandleCounting<vtkm::Id> blockCounter(0, 1, totalBlocks);
78 
79  // using Timer = vtkm::cont::Timer<vtkm::cont::DeviceAdapterTagSerial>;
80  // Timer timer;
82  zfp::Decode2(dims, paddedDims, stream.maxbits));
83  decompressDispatcher.Invoke(blockCounter, output, encodedData);
84 
85  // vtkm::Float64 time = timer.GetElapsedTime();
86  // size_t total_bytes = output.GetNumberOfValues() * sizeof(vtkm::Float64);
87  // vtkm::Float64 gB = vtkm::Float64(total_bytes) / (1024. * 1024. * 1024.);
88  // vtkm::Float64 rate = gB / time;
89  // std::cout<<"Decompress time "<<time<<" sec\n";
90  // std::cout<<"Decompress rate "<<rate<<" GB / sec\n";
91  // DataDump(output, "decompressed");
92  }
93 };
94 } // namespace worklet
95 } // namespace vtkm
96 #endif // vtk_m_worklet_zfp_2d_decompressor_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
vtkm::worklet::zfp::Decode2
Definition: ZFPDecode2.h:63
ArrayHandleConstant.h
vtkm::worklet::ZFP2DDecompressor::Decompress
void Decompress(const vtkm::cont::ArrayHandle< vtkm::Int64, StorageIn > &encodedData, vtkm::cont::ArrayHandle< Scalar, StorageOut > &output, const vtkm::Float64 requestedRate, vtkm::Id2 dims)
Definition: ZFP2DDecompress.h:44
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::worklet::ZFP2DDecompressor
Definition: ZFP2DDecompress.h:40
vtkm::Vec< vtkm::Id, 2 >
ZFPDecode2.h
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