VTK-m  2.0
ZFPEncode2.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_encode2_h
11 #define vtk_m_worklet_zfp_encode2_h
12 
13 #include <vtkm/Types.h>
15 
22 
23 
24 
25 namespace vtkm
26 {
27 namespace worklet
28 {
29 namespace zfp
30 {
31 
32 template <typename Scalar, typename PortalType>
33 VTKM_EXEC inline void GatherPartial2(Scalar* q,
34  const PortalType& scalars,
35  vtkm::Id offset,
36  vtkm::Int32 nx,
37  vtkm::Int32 ny,
38  vtkm::Int32 sx,
39  vtkm::Int32 sy)
40 {
41  vtkm::Id x, y;
42  for (y = 0; y < ny; y++, offset += sy - nx * sx)
43  {
44  for (x = 0; x < nx; x++, offset += 1)
45  q[4 * y + x] = scalars.Get(offset);
46  PadBlock(q + 4 * y, vtkm::UInt32(nx), 1);
47  }
48  for (x = 0; x < 4; x++)
49  PadBlock(q + x, vtkm::UInt32(ny), 4);
50 }
51 
52 template <typename Scalar, typename PortalType>
53 VTKM_EXEC inline void Gather2(Scalar* fblock,
54  const PortalType& scalars,
55  vtkm::Id offset,
56  int sx,
57  int sy)
58 {
59  vtkm::Id counter = 0;
60 
61  for (vtkm::Id y = 0; y < 4; y++, offset += sy - 4 * sx)
62  for (vtkm::Id x = 0; x < 4; x++, offset += sx)
63  {
64  fblock[counter] = scalars.Get(offset);
65  counter++;
66  }
67 }
68 
70 {
71 protected:
72  vtkm::Id2 Dims; // field dims
73  vtkm::Id2 PaddedDims; // dims padded to a multiple of zfp block size
74  vtkm::Id2 ZFPDims; // zfp block dims
75  vtkm::UInt32 MaxBits; // bits per zfp block
76 
77 public:
78  Encode2(const vtkm::Id2 dims, const vtkm::Id2 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  }
86  using ControlSignature = void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream);
87 
88  template <class InputScalarPortal, typename BitstreamPortal>
89  VTKM_EXEC void operator()(const vtkm::Id blockIdx,
90  const InputScalarPortal& scalars,
91  BitstreamPortal& stream) const
92  {
93  using Scalar = typename InputScalarPortal::ValueType;
94 
95  vtkm::Id2 zfpBlock;
96  zfpBlock[0] = blockIdx % ZFPDims[0];
97  zfpBlock[1] = (blockIdx / ZFPDims[0]) % ZFPDims[1];
98  vtkm::Id2 logicalStart = zfpBlock * vtkm::Id(4);
99  vtkm::Id offset = logicalStart[1] * Dims[0] + logicalStart[0];
100 
101  constexpr vtkm::Int32 BlockSize = 16;
102  Scalar fblock[BlockSize];
103 
104  bool partial = false;
105  if (logicalStart[0] + 4 > Dims[0])
106  partial = true;
107  if (logicalStart[1] + 4 > Dims[1])
108  partial = true;
109 
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  GatherPartial2(fblock, scalars, offset, nx, ny, 1, static_cast<vtkm::Int32>(Dims[0]));
117  }
118  else
119  {
120  Gather2(fblock, scalars, offset, 1, static_cast<vtkm::Int32>(Dims[0]));
121  }
122 
124  encoder.encode(fblock, vtkm::Int32(MaxBits), vtkm::UInt32(blockIdx), stream);
125  }
126 };
127 }
128 }
129 }
130 #endif
vtkm::worklet::zfp::ZFPBlockEncoder
Definition: ZFPEncode.h:314
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
vtkm::worklet::zfp::Encode2::Dims
vtkm::Id2 Dims
Definition: ZFPEncode2.h:72
vtkm::worklet::zfp::Encode2::operator()
VTKM_EXEC void operator()(const vtkm::Id blockIdx, const InputScalarPortal &scalars, BitstreamPortal &stream) const
Definition: ZFPEncode2.h:89
Types.h
WorkletMapField.h
ZFPTypeInfo.h
vtkm::worklet::zfp::Encode2::ControlSignature
void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream) ControlSignature
Definition: ZFPEncode2.h:86
vtkm::worklet::zfp::Encode2::PaddedDims
vtkm::Id2 PaddedDims
Definition: ZFPEncode2.h:73
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ExportMacros.h
ZFPStructs.h
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::zfp::PadBlock
VTKM_EXEC void PadBlock(Scalar *p, vtkm::UInt32 n, vtkm::UInt32 s)
Definition: ZFPEncode.h:27
vtkm::worklet::zfp::Encode2
Definition: ZFPEncode2.h:69
ZFPEncode.h
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::Gather2
VTKM_EXEC void Gather2(Scalar *fblock, const PortalType &scalars, vtkm::Id offset, int sx, int sy)
Definition: ZFPEncode2.h:53
vtkm::worklet::zfp::GatherPartial2
VTKM_EXEC void GatherPartial2(Scalar *q, const PortalType &scalars, vtkm::Id offset, vtkm::Int32 nx, vtkm::Int32 ny, vtkm::Int32 sx, vtkm::Int32 sy)
Definition: ZFPEncode2.h:33
vtkm::worklet::zfp::Encode2::ZFPDims
vtkm::Id2 ZFPDims
Definition: ZFPEncode2.h:74
vtkm::worklet::zfp::Encode2::MaxBits
vtkm::UInt32 MaxBits
Definition: ZFPEncode2.h:75
ZFPBlockWriter.h
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
vtkm::worklet::zfp::Encode2::Encode2
Encode2(const vtkm::Id2 dims, const vtkm::Id2 paddedDims, const vtkm::UInt32 maxbits)
Definition: ZFPEncode2.h:78