VTK-m  2.0
ZFPEncode1.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_encode1_h
11 #define vtk_m_worklet_zfp_encode1_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 GatherPartial1(Scalar* q,
34  const PortalType& scalars,
35  vtkm::Id offset,
36  int nx,
37  int sx)
38 {
39  vtkm::Id x;
40  for (x = 0; x < nx; x++, offset += sx)
41  q[x] = scalars.Get(offset);
42  PadBlock(q, vtkm::UInt32(nx), 1);
43 }
44 
45 template <typename Scalar, typename PortalType>
46 VTKM_EXEC inline void Gather1(Scalar* fblock, const PortalType& scalars, vtkm::Id offset, int sx)
47 {
48  vtkm::Id counter = 0;
49 
50  for (vtkm::Id x = 0; x < 4; x++, offset += sx)
51  {
52  fblock[counter] = scalars.Get(offset);
53  counter++;
54  }
55 }
56 
58 {
59 protected:
60  vtkm::Id Dims; // field dims
61  vtkm::Id PaddedDims; // dims padded to a multiple of zfp block size
62  vtkm::Id ZFPDims; // zfp block dims
63  vtkm::UInt32 MaxBits; // bits per zfp block
64 
65 public:
66  Encode1(const vtkm::Id dims, const vtkm::Id paddedDims, const vtkm::UInt32 maxbits)
67  : Dims(dims)
68  , PaddedDims(paddedDims)
69  , MaxBits(maxbits)
70  {
71  ZFPDims = PaddedDims / 4;
72  }
73  using ControlSignature = void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream);
74 
75  template <class InputScalarPortal, typename BitstreamPortal>
76  VTKM_EXEC void operator()(const vtkm::Id blockIdx,
77  const InputScalarPortal& scalars,
78  BitstreamPortal& stream) const
79  {
80  using Scalar = typename InputScalarPortal::ValueType;
81 
82  vtkm::Id zfpBlock;
83  zfpBlock = blockIdx % ZFPDims;
84  vtkm::Id logicalStart = zfpBlock * vtkm::Id(4);
85 
86  constexpr vtkm::Int32 BlockSize = 4;
87  Scalar fblock[BlockSize];
88 
89  bool partial = false;
90  if (logicalStart + 4 > Dims)
91  partial = true;
92 
93  if (partial)
94  {
95  const vtkm::Int32 nx =
96  logicalStart + 4 > Dims ? vtkm::Int32(Dims - logicalStart) : vtkm::Int32(4);
97  GatherPartial1(fblock, scalars, logicalStart, nx, 1);
98  }
99  else
100  {
101  Gather1(fblock, scalars, logicalStart, 1);
102  }
103 
105  encoder.encode(fblock, static_cast<vtkm::Int32>(MaxBits), vtkm::UInt32(blockIdx), stream);
106  }
107 };
108 }
109 }
110 }
111 #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
Types.h
WorkletMapField.h
vtkm::worklet::zfp::Encode1::operator()
VTKM_EXEC void operator()(const vtkm::Id blockIdx, const InputScalarPortal &scalars, BitstreamPortal &stream) const
Definition: ZFPEncode1.h:76
ZFPTypeInfo.h
vtkm::worklet::zfp::Encode1::Encode1
Encode1(const vtkm::Id dims, const vtkm::Id paddedDims, const vtkm::UInt32 maxbits)
Definition: ZFPEncode1.h:66
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
ExportMacros.h
vtkm::worklet::zfp::GatherPartial1
VTKM_EXEC void GatherPartial1(Scalar *q, const PortalType &scalars, vtkm::Id offset, int nx, int sx)
Definition: ZFPEncode1.h:33
vtkm::worklet::zfp::Encode1::ControlSignature
void(FieldIn, WholeArrayIn, AtomicArrayInOut bitstream) ControlSignature
Definition: ZFPEncode1.h:73
ZFPStructs.h
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::zfp::Gather1
VTKM_EXEC void Gather1(Scalar *fblock, const PortalType &scalars, vtkm::Id offset, int sx)
Definition: ZFPEncode1.h:46
vtkm::worklet::zfp::PadBlock
VTKM_EXEC void PadBlock(Scalar *p, vtkm::UInt32 n, vtkm::UInt32 s)
Definition: ZFPEncode.h:27
vtkm::worklet::zfp::Encode1::MaxBits
vtkm::UInt32 MaxBits
Definition: ZFPEncode1.h:63
ZFPEncode.h
vtkm::UInt32
uint32_t UInt32
Definition: Types.h:161
vtkm::worklet::zfp::Encode1::Dims
vtkm::Id Dims
Definition: ZFPEncode1.h:60
vtkm::Int32
int32_t Int32
Definition: Types.h:160
vtkm::worklet::zfp::Encode1::PaddedDims
vtkm::Id PaddedDims
Definition: ZFPEncode1.h:61
vtkm::worklet::zfp::Encode1
Definition: ZFPEncode1.h:57
vtkm::worklet::zfp::Encode1::ZFPDims
vtkm::Id ZFPDims
Definition: ZFPEncode1.h:62
ZFPBlockWriter.h
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38