VTK-m  2.0
ZFPEncode3.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_encode3_h
11 #define vtk_m_worklet_zfp_encode3_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 GatherPartial3(Scalar* q,
32  const 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 
41  for (z = 0; z < nz; z++, offset += dims[0] * dims[1] - ny * dims[0])
42  {
43  for (y = 0; y < ny; y++, offset += dims[0] - nx)
44  {
45  for (x = 0; x < nx; x++, offset += 1)
46  {
47  q[16 * z + 4 * y + x] = scalars.Get(offset);
48  }
49  PadBlock(q + 16 * z + 4 * y, static_cast<vtkm::UInt32>(nx), 1);
50  }
51 
52  for (x = 0; x < 4; x++)
53  {
54  PadBlock(q + 16 * z + x, vtkm::UInt32(ny), 4);
55  }
56  }
57 
58  for (y = 0; y < 4; y++)
59  {
60  for (x = 0; x < 4; x++)
61  {
62  PadBlock(q + 4 * y + x, vtkm::UInt32(nz), 16);
63  }
64  }
65 }
66 
67 template <typename Scalar, typename PortalType>
68 VTKM_EXEC inline void Gather3(Scalar* fblock,
69  const PortalType& scalars,
70  const vtkm::Id3 dims,
71  vtkm::Id offset)
72 {
73  // TODO: gather partial
74  vtkm::Id counter = 0;
75  for (vtkm::Id z = 0; z < 4; z++, offset += dims[0] * dims[1] - 4 * dims[0])
76  {
77  for (vtkm::Id y = 0; y < 4; y++, offset += dims[0] - 4)
78  {
79  for (vtkm::Id x = 0; x < 4; x++, ++offset)
80  {
81  fblock[counter] = scalars.Get(offset);
82  counter++;
83  } // x
84  } // y
85  } // z
86 }
87 
89 {
90 protected:
91  vtkm::Id3 Dims; // field dims
92  vtkm::Id3 PaddedDims; // dims padded to a multiple of zfp block size
93  vtkm::Id3 ZFPDims; // zfp block dims
94  vtkm::UInt32 MaxBits; // bits per zfp block
95 public:
96  Encode3(const vtkm::Id3 dims, const vtkm::Id3 paddedDims, const vtkm::UInt32 maxbits)
97  : Dims(dims)
98  , PaddedDims(paddedDims)
99  , MaxBits(maxbits)
100  {
101  ZFPDims[0] = PaddedDims[0] / 4;
102  ZFPDims[1] = PaddedDims[1] / 4;
103  ZFPDims[2] = PaddedDims[2] / 4;
104  }
105  using ControlSignature = void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream);
106 
107  template <typename InputScalarPortal, typename BitstreamPortal>
108  VTKM_EXEC void operator()(const vtkm::Id blockIdx,
109  const InputScalarPortal& scalars,
110  BitstreamPortal& stream) const
111  {
112  using Scalar = typename InputScalarPortal::ValueType;
113  constexpr vtkm::Int32 BlockSize = 64;
114  Scalar fblock[BlockSize];
115 
116  vtkm::Id3 zfpBlock;
117  zfpBlock[0] = blockIdx % ZFPDims[0];
118  zfpBlock[1] = (blockIdx / ZFPDims[0]) % ZFPDims[1];
119  zfpBlock[2] = blockIdx / (ZFPDims[0] * ZFPDims[1]);
120  vtkm::Id3 logicalStart = zfpBlock * vtkm::Id(4);
121 
122  // get the offset into the field
123  //vtkm::Id offset = (zfpBlock[2]*4*ZFPDims[1] + zfpBlock[1] * 4)*ZFPDims[0] * 4 + zfpBlock[0] * 4;
124  vtkm::Id offset = (logicalStart[2] * Dims[1] + logicalStart[1]) * Dims[0] + logicalStart[0];
125 
126  bool partial = false;
127  if (logicalStart[0] + 4 > Dims[0])
128  partial = true;
129  if (logicalStart[1] + 4 > Dims[1])
130  partial = true;
131  if (logicalStart[2] + 4 > Dims[2])
132  partial = true;
133  if (partial)
134  {
135  const vtkm::Int32 nx =
136  logicalStart[0] + 4 > Dims[0] ? vtkm::Int32(Dims[0] - logicalStart[0]) : vtkm::Int32(4);
137  const vtkm::Int32 ny =
138  logicalStart[1] + 4 > Dims[1] ? vtkm::Int32(Dims[1] - logicalStart[1]) : vtkm::Int32(4);
139  const vtkm::Int32 nz =
140  logicalStart[2] + 4 > Dims[2] ? vtkm::Int32(Dims[2] - logicalStart[2]) : vtkm::Int32(4);
141 
142  GatherPartial3(fblock, scalars, Dims, offset, nx, ny, nz);
143  }
144  else
145  {
146  Gather3(fblock, scalars, Dims, offset);
147  }
148 
150 
151  encoder.encode(fblock, vtkm::Int32(MaxBits), vtkm::UInt32(blockIdx), stream);
152  }
153 };
154 }
155 }
156 } // namespace vtkm::worklet::zfp
157 #endif
vtkm::worklet::zfp::Encode3::operator()
VTKM_EXEC void operator()(const vtkm::Id blockIdx, const InputScalarPortal &scalars, BitstreamPortal &stream) const
Definition: ZFPEncode3.h:108
vtkm::worklet::zfp::ZFPBlockEncoder
Definition: ZFPEncode.h:314
ZFPFunctions.h
vtkm::worklet::zfp::Gather3
VTKM_EXEC void Gather3(Scalar *fblock, const PortalType &scalars, const vtkm::Id3 dims, vtkm::Id offset)
Definition: ZFPEncode3.h:68
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::zfp::GatherPartial3
VTKM_EXEC void GatherPartial3(Scalar *q, const PortalType &scalars, const vtkm::Id3 dims, vtkm::Id offset, vtkm::Int32 nx, vtkm::Int32 ny, vtkm::Int32 nz)
Definition: ZFPEncode3.h:31
Types.h
WorkletMapField.h
ZFPTypeInfo.h
vtkm::worklet::zfp::Encode3
Definition: ZFPEncode3.h:88
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::zfp::Encode3::Dims
vtkm::Id3 Dims
Definition: ZFPEncode3.h:91
ExportMacros.h
vtkm::worklet::zfp::Encode3::Encode3
Encode3(const vtkm::Id3 dims, const vtkm::Id3 paddedDims, const vtkm::UInt32 maxbits)
Definition: ZFPEncode3.h:96
ZFPStructs.h
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::zfp::Encode3::ControlSignature
void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream) ControlSignature
Definition: ZFPEncode3.h:105
vtkm::worklet::zfp::PadBlock
VTKM_EXEC void PadBlock(Scalar *p, vtkm::UInt32 n, vtkm::UInt32 s)
Definition: ZFPEncode.h:27
ZFPEncode.h
vtkm::Vec< vtkm::Id, 3 >
vtkm::UInt32
uint32_t UInt32
Definition: Types.h:161
vtkm::worklet::zfp::Encode3::ZFPDims
vtkm::Id3 ZFPDims
Definition: ZFPEncode3.h:93
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::worklet::zfp::Encode3::PaddedDims
vtkm::Id3 PaddedDims
Definition: ZFPEncode3.h:92
vtkm::worklet::zfp::Encode3::MaxBits
vtkm::UInt32 MaxBits
Definition: ZFPEncode3.h:94
ZFPBlockWriter.h
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38