VTK-m  2.0
ZFPDecode1.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_decode1_h
11 #define vtk_m_worklet_zfp_decode1_h
12 
13 #include <vtkm/Types.h>
15 
22 
23 namespace vtkm
24 {
25 namespace worklet
26 {
27 namespace zfp
28 {
29 
30 template <typename Scalar, typename PortalType>
31 VTKM_EXEC inline void ScatterPartial1(const Scalar* q,
32  PortalType& scalars,
33  vtkm::Id offset,
34  vtkm::Int32 nx)
35 {
36  vtkm::Id x;
37  for (x = 0; x < nx; x++, offset++, q++)
38  {
39  scalars.Set(offset, *q);
40  }
41 }
42 
43 template <typename Scalar, typename PortalType>
44 VTKM_EXEC inline void Scatter1(const Scalar* q, PortalType& scalars, vtkm::Id offset)
45 {
46  for (vtkm::Id x = 0; x < 4; x++, ++offset)
47  {
48  scalars.Set(offset, *q++);
49  } // x
50 }
51 
53 {
54 protected:
55  vtkm::Id Dims; // field dims
56  vtkm::Id PaddedDims; // dims padded to a multiple of zfp block size
57  vtkm::Id ZFPDims; // zfp block dims
58  vtkm::UInt32 MaxBits; // bits per zfp block
59 public:
60  Decode1(const vtkm::Id dims, const vtkm::Id paddedDims, const vtkm::UInt32 maxbits)
61  : Dims(dims)
62  , PaddedDims(paddedDims)
63  , MaxBits(maxbits)
64  {
65  ZFPDims = PaddedDims / 4;
66  }
67  using ControlSignature = void(FieldIn, WholeArrayOut, WholeArrayIn bitstream);
68 
69  template <typename InputScalarPortal, typename BitstreamPortal>
70  VTKM_EXEC void operator()(const vtkm::Id blockIdx,
71  InputScalarPortal& scalars,
72  BitstreamPortal& stream) const
73  {
74  using Scalar = typename InputScalarPortal::ValueType;
75  constexpr vtkm::Int32 BlockSize = 4;
76  Scalar fblock[BlockSize];
77  // clear
78  for (vtkm::Int32 i = 0; i < BlockSize; ++i)
79  {
80  fblock[i] = static_cast<Scalar>(0);
81  }
82 
83 
84  zfp::zfp_decode<BlockSize>(
85  fblock, vtkm::Int32(MaxBits), static_cast<vtkm::UInt32>(blockIdx), stream);
86 
87 
88  vtkm::Id zfpBlock;
89  zfpBlock = blockIdx % ZFPDims;
90  vtkm::Id logicalStart = zfpBlock * vtkm::Id(4);
91 
92  bool partial = false;
93  if (logicalStart + 4 > Dims)
94  partial = true;
95  if (partial)
96  {
97  const vtkm::Int32 nx =
98  logicalStart + 4 > Dims ? vtkm::Int32(Dims - logicalStart) : vtkm::Int32(4);
99  ScatterPartial1(fblock, scalars, logicalStart, nx);
100  }
101  else
102  {
103  Scatter1(fblock, scalars, logicalStart);
104  }
105  }
106 };
107 }
108 }
109 } // namespace vtkm::worklet::zfp
110 #endif
vtkm::worklet::zfp::Decode1::ZFPDims
vtkm::Id ZFPDims
Definition: ZFPDecode1.h:57
vtkm::worklet::zfp::Decode1::Dims
vtkm::Id Dims
Definition: ZFPDecode1.h:55
vtkm::worklet::zfp::Decode1::operator()
VTKM_EXEC void operator()(const vtkm::Id blockIdx, InputScalarPortal &scalars, BitstreamPortal &stream) const
Definition: ZFPDecode1.h:70
ZFPFunctions.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
Types.h
WorkletMapField.h
vtkm::worklet::zfp::Decode1::MaxBits
vtkm::UInt32 MaxBits
Definition: ZFPDecode1.h:58
ZFPTypeInfo.h
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ExportMacros.h
vtkm::worklet::zfp::Decode1::PaddedDims
vtkm::Id PaddedDims
Definition: ZFPDecode1.h:56
vtkm::worklet::zfp::Scatter1
VTKM_EXEC void Scatter1(const Scalar *q, PortalType &scalars, vtkm::Id offset)
Definition: ZFPDecode1.h:44
vtkm::worklet::zfp::Decode1
Definition: ZFPDecode1.h:52
vtkm::worklet::zfp::Decode1::Decode1
Decode1(const vtkm::Id dims, const vtkm::Id paddedDims, const vtkm::UInt32 maxbits)
Definition: ZFPDecode1.h:60
ZFPStructs.h
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
ZFPDecode.h
vtkm::worklet::zfp::ScatterPartial1
VTKM_EXEC void ScatterPartial1(const Scalar *q, PortalType &scalars, vtkm::Id offset, vtkm::Int32 nx)
Definition: ZFPDecode1.h:31
vtkm::UInt32
uint32_t UInt32
Definition: Types.h:161
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::worklet::zfp::Decode1::ControlSignature
void(FieldIn, WholeArrayOut, WholeArrayIn bitstream) ControlSignature
Definition: ZFPDecode1.h:67
ZFPBlockWriter.h
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38