mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-08 13:23:51 +00:00
Add DeviceAdapterId::GetName.
This commit is contained in:
parent
cf15654112
commit
716f393c32
@ -132,6 +132,7 @@ set(sources
|
||||
FieldRangeGlobalCompute.cxx
|
||||
internal/ArrayHandleBasicImpl.cxx
|
||||
internal/ArrayManagerExecutionShareWithControl.cxx
|
||||
internal/DeviceAdapterTag.cxx
|
||||
internal/SimplePolymorphicContainer.cxx
|
||||
MultiBlock.cxx
|
||||
PresetColorTables.cxx
|
||||
|
@ -34,6 +34,34 @@
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
struct VTKM_NEVER_EXPORT GetDeviceNameFunctor
|
||||
{
|
||||
vtkm::cont::DeviceAdapterNameType* Names;
|
||||
|
||||
VTKM_CONT
|
||||
GetDeviceNameFunctor(vtkm::cont::DeviceAdapterNameType* names)
|
||||
: Names(names)
|
||||
{
|
||||
std::fill_n(this->Names, VTKM_MAX_DEVICE_ADAPTER_ID, "InvalidDeviceId");
|
||||
}
|
||||
|
||||
template <typename Device>
|
||||
VTKM_CONT void operator()(Device device)
|
||||
{
|
||||
auto id = device.GetValue();
|
||||
|
||||
if (id > 0 && id < VTKM_MAX_DEVICE_ADAPTER_ID)
|
||||
{
|
||||
this->Names[id] = vtkm::cont::DeviceAdapterTraits<Device>::GetName();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // end anon namespace
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
@ -45,6 +73,7 @@ namespace detail
|
||||
struct RuntimeDeviceTrackerInternals
|
||||
{
|
||||
bool RuntimeValid[VTKM_MAX_DEVICE_ADAPTER_ID];
|
||||
DeviceAdapterNameType DeviceNames[VTKM_MAX_DEVICE_ADAPTER_ID];
|
||||
};
|
||||
}
|
||||
|
||||
@ -52,6 +81,9 @@ VTKM_CONT
|
||||
RuntimeDeviceTracker::RuntimeDeviceTracker()
|
||||
: Internals(new detail::RuntimeDeviceTrackerInternals)
|
||||
{
|
||||
GetDeviceNameFunctor functor(this->Internals->DeviceNames);
|
||||
vtkm::ListForEach(functor, VTKM_DEFAULT_DEVICE_ADAPTER_LIST_TAG());
|
||||
|
||||
this->Reset();
|
||||
}
|
||||
|
||||
@ -177,5 +209,41 @@ vtkm::cont::RuntimeDeviceTracker GetGlobalRuntimeDeviceTracker()
|
||||
return runtimeDeviceTracker;
|
||||
#endif
|
||||
}
|
||||
|
||||
VTKM_CONT
|
||||
DeviceAdapterNameType RuntimeDeviceTracker::GetDeviceName(DeviceAdapterId device) const
|
||||
{
|
||||
auto id = device.GetValue();
|
||||
|
||||
if (id < 0)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case VTKM_DEVICE_ADAPTER_ERROR:
|
||||
return vtkm::cont::DeviceAdapterTraits<vtkm::cont::DeviceAdapterTagError>::GetName();
|
||||
case VTKM_DEVICE_ADAPTER_UNDEFINED:
|
||||
return "Undefined"; // This device id does not have traits.
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (id >= VTKM_MAX_DEVICE_ADAPTER_ID)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case VTKM_DEVICE_ADAPTER_ANY:
|
||||
return "Any"; // This device id does not have traits
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else // id is valid:
|
||||
{
|
||||
return this->Internals->DeviceNames[id];
|
||||
}
|
||||
|
||||
// Device 0 is invalid:
|
||||
return this->Internals->DeviceNames[0];
|
||||
}
|
||||
}
|
||||
} // namespace vtkm::cont
|
||||
|
@ -204,6 +204,10 @@ public:
|
||||
this->ForceDeviceImpl(device, Traits::GetName(), runtimeDevice.Exists());
|
||||
}
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
VTKM_CONT
|
||||
DeviceAdapterNameType GetDeviceName(DeviceAdapterId id) const;
|
||||
|
||||
private:
|
||||
std::shared_ptr<detail::RuntimeDeviceTrackerInternals> Internals;
|
||||
|
||||
|
35
vtkm/cont/internal/DeviceAdapterTag.cxx
Normal file
35
vtkm/cont/internal/DeviceAdapterTag.cxx
Normal file
@ -0,0 +1,35 @@
|
||||
//============================================================================
|
||||
// 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 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2018 UT-Battelle, LLC.
|
||||
// Copyright 2018 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/internal/DeviceAdapterTag.h>
|
||||
|
||||
#include <vtkm/cont/RuntimeDeviceTracker.h>
|
||||
|
||||
namespace vtkm
|
||||
{
|
||||
namespace cont
|
||||
{
|
||||
|
||||
DeviceAdapterNameType DeviceAdapterId::GetName() const
|
||||
{
|
||||
return vtkm::cont::GetGlobalRuntimeDeviceTracker().GetDeviceName(*this);
|
||||
}
|
||||
}
|
||||
} // end namespace vtkm::cont
|
@ -25,6 +25,8 @@
|
||||
#include <vtkm/internal/Configure.h>
|
||||
#include <vtkm/internal/ExportMacros.h>
|
||||
|
||||
#include <vtkm/cont/vtkm_cont_export.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#define VTKM_DEVICE_ADAPTER_ERROR -2
|
||||
@ -42,6 +44,8 @@ namespace vtkm
|
||||
namespace cont
|
||||
{
|
||||
|
||||
using DeviceAdapterNameType = std::string;
|
||||
|
||||
struct DeviceAdapterId
|
||||
{
|
||||
constexpr bool operator==(DeviceAdapterId other) const { return this->Value == other.Value; }
|
||||
@ -55,6 +59,9 @@ struct DeviceAdapterId
|
||||
|
||||
constexpr vtkm::Int8 GetValue() const { return this->Value; }
|
||||
|
||||
VTKM_CONT_EXPORT
|
||||
DeviceAdapterNameType GetName() const;
|
||||
|
||||
protected:
|
||||
constexpr explicit DeviceAdapterId(vtkm::Int8 id)
|
||||
: Value(id)
|
||||
@ -84,8 +91,6 @@ struct DeviceAdapterIdUndefined : DeviceAdapterId
|
||||
}
|
||||
};
|
||||
|
||||
using DeviceAdapterNameType = std::string;
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
struct DeviceAdapterTraits;
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ set(unit_tests
|
||||
UnitTestFieldRangeCompute.cxx
|
||||
UnitTestMultiBlock.cxx
|
||||
UnitTestRuntimeDeviceInformation.cxx
|
||||
UnitTestRuntimeDeviceNames.cxx
|
||||
UnitTestStorageBasic.cxx
|
||||
UnitTestStorageImplicit.cxx
|
||||
UnitTestStorageListTag.cxx
|
||||
|
88
vtkm/cont/testing/UnitTestRuntimeDeviceNames.cxx
Normal file
88
vtkm/cont/testing/UnitTestRuntimeDeviceNames.cxx
Normal file
@ -0,0 +1,88 @@
|
||||
//============================================================================
|
||||
// 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 2018 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
||||
// Copyright 2018 UT-Battelle, LLC.
|
||||
// Copyright 2018 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/RuntimeDeviceTracker.h>
|
||||
|
||||
#include <vtkm/cont/cuda/DeviceAdapterCuda.h>
|
||||
#include <vtkm/cont/internal/DeviceAdapterError.h>
|
||||
#include <vtkm/cont/openmp/DeviceAdapterOpenMP.h>
|
||||
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
|
||||
#include <vtkm/cont/tbb/DeviceAdapterTBB.h>
|
||||
|
||||
#include <vtkm/cont/testing/Testing.h>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
// Invalid tag for testing. Returns the default "InvalidDeviceId" from
|
||||
// vtkm::cont::RuntimeDeviceTracker::GetName.
|
||||
struct VTKM_ALWAYS_EXPORT DeviceAdapterTagInvalidDeviceId : vtkm::cont::DeviceAdapterId
|
||||
{
|
||||
constexpr DeviceAdapterTagInvalidDeviceId()
|
||||
: DeviceAdapterId(VTKM_MAX_DEVICE_ADAPTER_ID)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tag>
|
||||
void TestName(const std::string& name, Tag tag, vtkm::cont::DeviceAdapterId id)
|
||||
{
|
||||
auto tracker = vtkm::cont::GetGlobalRuntimeDeviceTracker();
|
||||
|
||||
#if 0
|
||||
std::cerr << "Expected: " << name << "\n"
|
||||
<< "\t" << id.GetName() << "\n"
|
||||
<< "\t" << tag.GetName() << "\n"
|
||||
<< "\t" << tracker.GetDeviceName(id) << "\n"
|
||||
<< "\t" << tracker.GetDeviceName(tag) << "\n";
|
||||
#endif
|
||||
|
||||
VTKM_TEST_ASSERT(id.GetName() == name, "Id::GetName() failed.");
|
||||
VTKM_TEST_ASSERT(tag.GetName() == name, "Tag::GetName() failed.");
|
||||
VTKM_TEST_ASSERT(tracker.GetDeviceName(id) == name, "RTDeviceTracker::GetDeviceName(Id) failed.");
|
||||
VTKM_TEST_ASSERT(tracker.GetDeviceName(tag) == name,
|
||||
"RTDeviceTracker::GetDeviceName(Tag) failed.");
|
||||
}
|
||||
|
||||
void TestNames()
|
||||
{
|
||||
DeviceAdapterTagInvalidDeviceId invalidTag;
|
||||
vtkm::cont::DeviceAdapterTagError errorTag;
|
||||
vtkm::cont::DeviceAdapterIdUndefined undefinedTag;
|
||||
vtkm::cont::DeviceAdapterTagSerial serialTag;
|
||||
vtkm::cont::DeviceAdapterTagTBB tbbTag;
|
||||
vtkm::cont::DeviceAdapterTagOpenMP openmpTag;
|
||||
vtkm::cont::DeviceAdapterTagCuda cudaTag;
|
||||
|
||||
TestName("InvalidDeviceId", invalidTag, invalidTag);
|
||||
TestName("Error", errorTag, errorTag);
|
||||
TestName("Undefined", undefinedTag, undefinedTag);
|
||||
TestName("Serial", serialTag, serialTag);
|
||||
TestName("TBB", tbbTag, tbbTag);
|
||||
TestName("OpenMP", openmpTag, openmpTag);
|
||||
TestName("Cuda", cudaTag, cudaTag);
|
||||
}
|
||||
|
||||
} // end anon namespace
|
||||
|
||||
int UnitTestRuntimeDeviceNames(int, char* [])
|
||||
{
|
||||
return vtkm::cont::testing::Testing::Run(TestNames);
|
||||
}
|
Loading…
Reference in New Issue
Block a user