VTK-m  2.0
ZFPDecode2.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_decode2_h
11 #define vtk_m_worklet_zfp_decode2_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 ScatterPartial2(const Scalar* q,
32  PortalType& scalars,
33  const vtkm::Id2 dims,
34  vtkm::Id offset,
35  vtkm::Int32 nx,
36  vtkm::Int32 ny)
37 {
38  vtkm::Id x, y;
39  for (y = 0; y < ny; y++, offset += dims[0] - nx, q += 4 - nx)
40  {
41  for (x = 0; x < nx; x++, offset++, q++)
42  {
43  scalars.Set(offset, *q);
44  }
45  }
46 }
47 
48 template <typename Scalar, typename PortalType>
49 VTKM_EXEC inline void Scatter2(const Scalar* q,
50  PortalType& scalars,
51  const vtkm::Id2 dims,
52  vtkm::Id offset)
53 {
54  for (vtkm::Id y = 0; y < 4; y++, offset += dims[0] - 4)
55  {
56  for (vtkm::Id x = 0; x < 4; x++, ++offset)
57  {
58  scalars.Set(offset, *q++);
59  } // x
60  } // y
61 }
62 
64 {
65 protected:
66  vtkm::Id2 Dims; // field dims
67  vtkm::Id2 PaddedDims; // dims padded to a multiple of zfp block size
68  vtkm::Id2 ZFPDims; // zfp block dims
69  vtkm::UInt32 MaxBits; // bits per zfp block
70 public:
71  Decode2(const vtkm::Id2 dims, const vtkm::Id2 paddedDims, const vtkm::UInt32 maxbits)
72  : Dims(dims)
73  , PaddedDims(paddedDims)
74  , MaxBits(maxbits)
75  {
76  ZFPDims[0] = PaddedDims[0] / 4;
77  ZFPDims[1] = PaddedDims[1] / 4;
78  }
79  using ControlSignature = void(FieldIn, WholeArrayOut, WholeArrayIn bitstream);
80 
81  template <typename InputScalarPortal, typename BitstreamPortal>
82  VTKM_EXEC void operator()(const vtkm::Id blockIdx,
83  InputScalarPortal& scalars,
84  BitstreamPortal& stream) const
85  {
86  using Scalar = typename InputScalarPortal::ValueType;
87  constexpr vtkm::Int32 BlockSize = 16;
88  Scalar fblock[BlockSize];
89  // clear
90  for (vtkm::Int32 i = 0; i < BlockSize; ++i)
91  {
92  fblock[i] = static_cast<Scalar>(0);
93  }
94 
95 
96  zfp::zfp_decode<BlockSize>(
97  fblock, vtkm::Int32(MaxBits), static_cast<vtkm::UInt32>(blockIdx), stream);
98 
99  vtkm::Id2 zfpBlock;
100  zfpBlock[0] = blockIdx % ZFPDims[0];
101  zfpBlock[1] = (blockIdx / ZFPDims[0]) % ZFPDims[1];
102  vtkm::Id2 logicalStart = zfpBlock * vtkm::Id(4);
103 
104  vtkm::Id offset = logicalStart[0] + logicalStart[1] * Dims[0];
105  bool partial = false;
106  if (logicalStart[0] + 4 > Dims[0])
107  partial = true;
108  if (logicalStart[1] + 4 > Dims[1])
109  partial = true;
110  if (partial)
111  {
112  const vtkm::Int32 nx =
113  logicalStart[0] + 4 > Dims[0] ? vtkm::Int32(Dims[0] - logicalStart[0]) : vtkm::Int32(4);
114  const vtkm::Int32 ny =
115  logicalStart[1] + 4 > Dims[1] ? vtkm::Int32(Dims[1] - logicalStart[1]) : vtkm::Int32(4);
116  ScatterPartial2(fblock, scalars, Dims, offset, nx, ny);
117  }
118  else
119  {
120  Scatter2(fblock, scalars, Dims, offset);
121  }
122  }
123 };
124 }
125 }
126 } // namespace vtkm::worklet::zfp
127 #endif
ZFPFunctions.h
vtkm::worklet::zfp::Scatter2
VTKM_EXEC void Scatter2(const Scalar *q, PortalType &scalars, const vtkm::Id2 dims, vtkm::Id offset)
Definition: ZFPDecode2.h:49
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
ZFPTypeInfo.h
vtkm::worklet::zfp::Decode2
Definition: ZFPDecode2.h:63
vtkm::worklet::zfp::Decode2::ControlSignature
void(FieldIn, WholeArrayOut, WholeArrayIn bitstream) ControlSignature
Definition: ZFPDecode2.h:79
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::zfp::Decode2::PaddedDims
vtkm::Id2 PaddedDims
Definition: ZFPDecode2.h:67
ExportMacros.h
vtkm::worklet::zfp::Decode2::Decode2
Decode2(const vtkm::Id2 dims, const vtkm::Id2 paddedDims, const vtkm::UInt32 maxbits)
Definition: ZFPDecode2.h:71
vtkm::worklet::zfp::Decode2::Dims
vtkm::Id2 Dims
Definition: ZFPDecode2.h:66
ZFPStructs.h
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
ZFPDecode.h
vtkm::worklet::zfp::ScatterPartial2
VTKM_EXEC void ScatterPartial2(const Scalar *q, PortalType &scalars, const vtkm::Id2 dims, vtkm::Id offset, vtkm::Int32 nx, vtkm::Int32 ny)
Definition: ZFPDecode2.h:31
vtkm::worklet::zfp::Decode2::MaxBits
vtkm::UInt32 MaxBits
Definition: ZFPDecode2.h:69
vtkm::Vec< vtkm::Id, 2 >
vtkm::UInt32
uint32_t UInt32
Definition: Types.h:161
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::worklet::zfp::Decode2::ZFPDims
vtkm::Id2 ZFPDims
Definition: ZFPDecode2.h:68
vtkm::worklet::zfp::Decode2::operator()
VTKM_EXEC void operator()(const vtkm::Id blockIdx, InputScalarPortal &scalars, BitstreamPortal &stream) const
Definition: ZFPDecode2.h:82
ZFPBlockWriter.h
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38