VTK-m  2.0
ZFP1DCompressor.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_1d_compressor_h
11 #define vtk_m_worklet_zfp_1d_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::Id dims)
43  {
44  // DataDump(data, "uncompressed");
45  zfp::ZFPStream stream;
46  constexpr vtkm::Int32 topoDims = 1;
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::Id paddedDims = dims;
54  // ensure that we have block sizes
55  // that are a multiple of 4
56  if (paddedDims % 4 != 0)
57  paddedDims += 4 - dims % 4;
58  constexpr vtkm::Id four = 4;
59  const vtkm::Id totalBlocks = (paddedDims / four);
60 
61 
62  size_t outbits = zfp::detail::CalcMem1d(paddedDims, stream.minbits);
63  vtkm::Id outsize = vtkm::Id(outbits / sizeof(ZFPWord));
64 
66  // hopefully this inits/allocates the mem only on the device
68  vtkm::cont::Algorithm::Copy(zero, output);
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::Encode1(dims, paddedDims, stream.maxbits));
77  compressDispatcher.Invoke(blockCounter, data, output);
78 
79  // vtkm::Float64 time = timer.GetElapsedTime();
80  // size_t total_bytes = data.GetNumberOfValues() * sizeof(vtkm::Float64);
81  // vtkm::Float64 gB = vtkm::Float64(total_bytes) / (1024. * 1024. * 1024.);
82  // vtkm::Float64 rate = gB / time;
83  // std::cout<<"Compress time "<<time<<" sec\n";
84  // std::cout<<"Compress rate "<<rate<<" GB / sec\n";
85  // DataDump(output, "compressed");
86 
87  return output;
88  }
89 };
90 } // namespace worklet
91 } // namespace vtkm
92 #endif // vtk_m_worklet_zfp_1d_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::ZFP1DCompressor::Compress
vtkm::cont::ArrayHandle< vtkm::Int64 > Compress(const vtkm::cont::ArrayHandle< Scalar, Storage > &data, const vtkm::Float64 requestedRate, const vtkm::Id dims)
Definition: ZFP1DCompressor.h:39
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::worklet::ZFP1DCompressor
Definition: ZFP1DCompressor.h:35
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
ZFPEncode1.h
ArrayHandleCounting.h
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::zfp::Encode1
Definition: ZFPEncode1.h:57
vtkm::worklet::zfp::ZFPStream
Definition: ZFPStructs.h:28
ZFPWord
vtkm::UInt64 ZFPWord
Definition: ZFPTools.h:24
AtomicArray.h