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