Commit 50bfb1d2 authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Add utility to serialize ArrayHandles for DIY.

parent adfff37e
......@@ -137,6 +137,7 @@ vtkm_library( NAME vtkm_cont
)
add_subdirectory(internal)
add_subdirectory(arg)
add_subdirectory(diy)
add_subdirectory(serial)
add_subdirectory(tbb)
add_subdirectory(cuda)
......
##============================================================================
## Copyright (c) Kitware, Inc.
## All rights reserved.
## See LICENSE.txt for details.
## This software is distributed WITHOUT ANY WARRANTY; without even
## the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
## PURPOSE. See the above copyright notice for more information.
##
## Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
## Copyright 2014 UT-Battelle, LLC.
## Copyright 2014 Los Alamos National Security.
##
## Under the terms of Contract DE-NA0003525 with NTESS,
## the U.S. Government retains certain rights in this software.
##
## Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
## Laboratory (LANL), the U.S. Government retains certain rights in
## this software.
##============================================================================
set(headers
Serialization.h)
set(header_template_sources
Serialization.hxx)
vtkm_declare_headers(${headers}
EXCLUDE_FROM_TESTING ${header_template_sources})
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_cont_diy_Serialization_h
#define vtk_m_cont_diy_Serialization_h
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/internal/ExportMacros.h>
// clang-format off
VTKM_THIRDPARTY_PRE_INCLUDE
#include <vtkm/thirdparty/diy/Configure.h>
#include VTKM_DIY(diy/serialization.hpp)
VTKM_THIRDPARTY_POST_INCLUDE
namespace diy
{
/// This provides specializations to extend DIY's serialization code to
/// load/save vtkm::cont::ArrayHandle instances.
template <typename T, typename StorageTag>
struct Serialization<vtkm::cont::ArrayHandle<T, StorageTag>>
{
VTKM_CONT
static void save(BinaryBuffer& bb, const vtkm::cont::ArrayHandle<T, StorageTag>& indata);
VTKM_CONT
static void load(BinaryBuffer& bb, vtkm::cont::ArrayHandle<T, StorageTag>& outdata);
};
} // namespace diy
#include <vtkm/cont/diy/Serialization.hxx>
#endif
//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#include <vtkm/cont/ArrayPortalToIterators.h>
namespace diy
{
template <typename T, typename S>
inline VTKM_CONT void Serialization<vtkm::cont::ArrayHandle<T, S>>::save(
BinaryBuffer& bb,
const vtkm::cont::ArrayHandle<T, S>& indata)
{
const vtkm::Id numValues = indata.GetNumberOfValues();
diy::Serialization<vtkm::Id>::save(bb, numValues);
auto const_portal = indata.GetPortalConstControl();
for (vtkm::Id index = 0; index < numValues; ++index)
{
diy::Serialization<T>::save(bb, const_portal.Get(index));
}
}
template <typename T, typename S>
inline VTKM_CONT void Serialization<vtkm::cont::ArrayHandle<T, S>>::load(
BinaryBuffer& bb,
vtkm::cont::ArrayHandle<T, S>& outdata)
{
vtkm::Id numValues;
diy::Serialization<vtkm::Id>::load(bb, numValues);
outdata.Allocate(numValues);
T val;
auto portal = outdata.GetPortalControl();
for (vtkm::Id index = 0; index < numValues; ++index)
{
diy::Serialization<T>::load(bb, val);
portal.Set(index, val);
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment