VTK-m  2.0
ZFPTools.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_tool_h
11 #define vtk_m_worklet_zfp_tool_h
12 
13 #include <vtkm/Math.h>
14 #include <vtkm/cont/Algorithm.h>
15 #include <vtkm/cont/ArrayHandle.h>
18 #include <vtkm/cont/AtomicArray.h>
19 #include <vtkm/cont/Timer.h>
21 
23 
24 using ZFPWord = vtkm::UInt64;
25 
26 #include <stdio.h>
27 
28 namespace vtkm
29 {
30 namespace worklet
31 {
32 namespace zfp
33 {
34 namespace detail
35 {
36 
37 class MemTransfer : public vtkm::worklet::WorkletMapField
38 {
39 public:
40  VTKM_CONT
41  MemTransfer() {}
42  using ControlSignature = void(FieldIn, WholeArrayInOut);
43  using ExecutionSignature = void(_1, _2);
44 
45  template <typename PortalType>
46  VTKM_EXEC void operator()(const vtkm::Id id, PortalType& outValue) const
47  {
48  (void)id;
49  (void)outValue;
50  }
51 }; //class MemTransfer
52 
53 inline size_t CalcMem3d(const vtkm::Id3 dims, const vtkm::UInt32 bits_per_block)
54 {
55  const size_t vals_per_block = 64;
56  const size_t size = static_cast<size_t>(dims[0] * dims[1] * dims[2]);
57  size_t total_blocks = size / vals_per_block;
58  const size_t bits_per_word = sizeof(ZFPWord) * 8;
59  const size_t total_bits = bits_per_block * total_blocks;
60  const size_t alloc_size = total_bits / bits_per_word;
61  return alloc_size * sizeof(ZFPWord);
62 }
63 
64 inline size_t CalcMem2d(const vtkm::Id2 dims, const vtkm::UInt32 bits_per_block)
65 {
66  constexpr size_t vals_per_block = 16;
67  const size_t size = static_cast<size_t>(dims[0] * dims[1]);
68  size_t total_blocks = size / vals_per_block;
69  constexpr size_t bits_per_word = sizeof(ZFPWord) * 8;
70  const size_t total_bits = bits_per_block * total_blocks;
71  const size_t alloc_size = total_bits / bits_per_word;
72  return alloc_size * sizeof(ZFPWord);
73 }
74 
75 inline size_t CalcMem1d(const vtkm::Id dims, const vtkm::UInt32 bits_per_block)
76 {
77  constexpr size_t vals_per_block = 4;
78  const size_t size = static_cast<size_t>(dims);
79  size_t total_blocks = size / vals_per_block;
80  constexpr size_t bits_per_word = sizeof(ZFPWord) * 8;
81  const size_t total_bits = bits_per_block * total_blocks;
82  const size_t alloc_size = total_bits / bits_per_word;
83  return alloc_size * sizeof(ZFPWord);
84 }
85 
86 
87 template <typename T>
88 T* GetVTKMPointer(vtkm::cont::ArrayHandle<T>& handle)
89 {
90  typedef typename vtkm::cont::ArrayHandle<T> HandleType;
91  typedef typename HandleType::template ExecutionTypes<vtkm::cont::DeviceAdapterTagSerial>::Portal
92  PortalType;
94  IteratorType iter =
96  return &(*iter);
97 }
98 
99 template <typename T, typename S>
100 void DataDump(vtkm::cont::ArrayHandle<T, S> handle, std::string fileName)
101 {
102 
103  T* ptr = GetVTKMPointer(handle);
104  vtkm::Id osize = handle.GetNumberOfValues();
105  FILE* fp = fopen(fileName.c_str(), "wb");
106  ;
107  if (fp != NULL)
108  {
109  fwrite(ptr, sizeof(T), static_cast<size_t>(osize), fp);
110  }
111 
112  fclose(fp);
113 }
114 
115 
116 } // namespace detail
117 } // namespace zfp
118 } // namespace worklet
119 } // namespace vtkm
120 #endif // vtk_m_worklet_zfp_tools_h
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
ArrayHandleConstant.h
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
DispatcherMapField.h
vtkm::cont::ArrayPortalToIterators
Definition: ArrayPortalToIterators.h:27
Math.h
Timer.h
Algorithm.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ArrayHandle::WritePortal
VTKM_CONT WritePortalType WritePortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:435
vtkm::Vec< vtkm::Id, 3 >
vtkm::UInt32
uint32_t UInt32
Definition: Types.h:161
ArrayHandleCounting.h
ZFPWord
vtkm::UInt64 ZFPWord
Definition: ZFPTools.h:24
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
AtomicArray.h
ZFPEncode3.h