2020-03-26 23:34:18 +00:00
|
|
|
//============================================================================
|
|
|
|
// 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.
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
#include <vtkm/cont/internal/DeviceAdapterMemoryManagerShared.h>
|
|
|
|
|
2020-04-22 19:58:59 +00:00
|
|
|
#include <cstring>
|
2020-03-26 23:34:18 +00:00
|
|
|
|
2020-04-22 19:58:59 +00:00
|
|
|
namespace vtkm
|
2020-03-26 23:34:18 +00:00
|
|
|
{
|
2020-04-22 19:58:59 +00:00
|
|
|
namespace cont
|
2020-03-26 23:34:18 +00:00
|
|
|
{
|
2020-04-22 19:58:59 +00:00
|
|
|
namespace internal
|
2020-03-26 23:34:18 +00:00
|
|
|
{
|
|
|
|
|
2020-04-22 19:58:59 +00:00
|
|
|
vtkm::cont::internal::BufferInfo DeviceAdapterMemoryManagerShared::Allocate(
|
|
|
|
vtkm::BufferSizeType size) const
|
2020-03-26 23:34:18 +00:00
|
|
|
{
|
2020-04-22 19:58:59 +00:00
|
|
|
return vtkm::cont::internal::BufferInfo(vtkm::cont::internal::AllocateOnHost(size),
|
|
|
|
this->GetDevice());
|
2020-03-26 23:34:18 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 19:58:59 +00:00
|
|
|
vtkm::cont::internal::BufferInfo DeviceAdapterMemoryManagerShared::CopyHostToDevice(
|
|
|
|
const vtkm::cont::internal::BufferInfo& src) const
|
2020-03-26 23:34:18 +00:00
|
|
|
{
|
2020-04-22 19:58:59 +00:00
|
|
|
VTKM_ASSERT(src.GetDevice() == vtkm::cont::DeviceAdapterTagUndefined{});
|
|
|
|
return vtkm::cont::internal::BufferInfo(src, this->GetDevice());
|
2020-03-26 23:34:18 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 23:27:36 +00:00
|
|
|
void DeviceAdapterMemoryManagerShared::CopyHostToDevice(
|
|
|
|
const vtkm::cont::internal::BufferInfo& src,
|
|
|
|
const vtkm::cont::internal::BufferInfo& dest) const
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(src.GetDevice() == vtkm::cont::DeviceAdapterTagUndefined{});
|
|
|
|
VTKM_ASSERT(dest.GetDevice() == this->GetDevice());
|
|
|
|
if (src.GetPointer() != dest.GetPointer())
|
|
|
|
{
|
|
|
|
this->CopyDeviceToDevice(src, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 19:58:59 +00:00
|
|
|
vtkm::cont::internal::BufferInfo DeviceAdapterMemoryManagerShared::CopyDeviceToHost(
|
|
|
|
const vtkm::cont::internal::BufferInfo& src) const
|
2020-03-26 23:34:18 +00:00
|
|
|
{
|
2020-04-22 19:58:59 +00:00
|
|
|
VTKM_ASSERT(src.GetDevice() == this->GetDevice());
|
|
|
|
return vtkm::cont::internal::BufferInfo(src, vtkm::cont::DeviceAdapterTagUndefined{});
|
2020-03-26 23:34:18 +00:00
|
|
|
}
|
|
|
|
|
2020-06-24 23:27:36 +00:00
|
|
|
void DeviceAdapterMemoryManagerShared::CopyDeviceToHost(
|
|
|
|
const vtkm::cont::internal::BufferInfo& src,
|
|
|
|
const vtkm::cont::internal::BufferInfo& dest) const
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(src.GetDevice() == this->GetDevice());
|
|
|
|
VTKM_ASSERT(dest.GetDevice() == vtkm::cont::DeviceAdapterTagUndefined{});
|
|
|
|
if (src.GetPointer() != dest.GetPointer())
|
|
|
|
{
|
|
|
|
this->CopyDeviceToDevice(src, dest);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-22 19:58:59 +00:00
|
|
|
vtkm::cont::internal::BufferInfo DeviceAdapterMemoryManagerShared::CopyDeviceToDevice(
|
|
|
|
const vtkm::cont::internal::BufferInfo& src) const
|
2020-03-26 23:34:18 +00:00
|
|
|
{
|
2020-04-22 19:58:59 +00:00
|
|
|
VTKM_ASSERT(src.GetDevice() == this->GetDevice());
|
2020-03-26 23:34:18 +00:00
|
|
|
|
2020-04-22 19:58:59 +00:00
|
|
|
vtkm::BufferSizeType size = src.GetSize();
|
|
|
|
vtkm::cont::internal::BufferInfo dest = this->Allocate(size);
|
2020-06-24 23:27:36 +00:00
|
|
|
this->CopyDeviceToDevice(src, dest);
|
2020-04-22 19:58:59 +00:00
|
|
|
return dest;
|
|
|
|
}
|
2020-06-24 23:27:36 +00:00
|
|
|
|
|
|
|
void DeviceAdapterMemoryManagerShared::CopyDeviceToDevice(
|
|
|
|
const vtkm::cont::internal::BufferInfo& src,
|
|
|
|
const vtkm::cont::internal::BufferInfo& dest) const
|
|
|
|
{
|
|
|
|
VTKM_ASSERT(src.GetSize() == dest.GetSize());
|
|
|
|
|
|
|
|
std::memcpy(dest.GetPointer(), src.GetPointer(), static_cast<std::size_t>(src.GetSize()));
|
|
|
|
}
|
2023-03-22 23:14:21 +00:00
|
|
|
|
|
|
|
void DeviceAdapterMemoryManagerShared::DeleteRawPointer(void* mem) const
|
|
|
|
{
|
|
|
|
vtkm::cont::internal::HostDeleter(mem);
|
|
|
|
}
|
|
|
|
|
2020-03-26 23:34:18 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-22 19:58:59 +00:00
|
|
|
} // namespace vtkm::cont::internal
|