VTK-m  2.0
RuntimeDeviceConfigurationCuda.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_cont_cuda_internal_RuntimeDeviceConfigurationCuda_h
11 #define vtk_m_cont_cuda_internal_RuntimeDeviceConfigurationCuda_h
12 
15 
16 #include <vtkm/cont/Logging.h>
18 
19 VTKM_THIRDPARTY_PRE_INCLUDE
20 #include <cuda.h>
21 VTKM_THIRDPARTY_POST_INCLUDE
22 
23 #include <vector>
24 
25 namespace vtkm
26 {
27 namespace cont
28 {
29 namespace internal
30 {
31 
32 template <>
33 class RuntimeDeviceConfiguration<vtkm::cont::DeviceAdapterTagCuda>
34  : public vtkm::cont::internal::RuntimeDeviceConfigurationBase
35 {
36 public:
37  RuntimeDeviceConfiguration<vtkm::cont::DeviceAdapterTagCuda>()
38  {
39  int tmp;
40  VTKM_CUDA_CALL(cudaGetDeviceCount(&tmp));
41  this->CudaDeviceCount = tmp;
42  this->CudaProp.resize(this->CudaDeviceCount);
43  for (int i = 0; i < this->CudaDeviceCount; ++i)
44  {
45  VTKM_CUDA_CALL(cudaGetDeviceProperties(&this->CudaProp[i], i));
46  }
47  }
48 
49  VTKM_CONT vtkm::cont::DeviceAdapterId GetDevice() const override final
50  {
51  return vtkm::cont::DeviceAdapterTagCuda{};
52  }
53 
54  VTKM_CONT virtual RuntimeDeviceConfigReturnCode SetDeviceInstance(
55  const vtkm::Id& value) override final
56  {
57  if (value >= this->CudaDeviceCount)
58  {
59  VTKM_LOG_S(
61  "Failed to set CudaDeviceInstance, supplied id exceeds the number of available devices: "
62  << value << " >= " << this->CudaDeviceCount);
63  return RuntimeDeviceConfigReturnCode::INVALID_VALUE;
64  }
65  VTKM_CUDA_CALL(cudaSetDevice(value));
66  return RuntimeDeviceConfigReturnCode::SUCCESS;
67  }
68 
69  VTKM_CONT virtual RuntimeDeviceConfigReturnCode GetDeviceInstance(
70  vtkm::Id& value) const override final
71  {
72  int tmp;
73  VTKM_CUDA_CALL(cudaGetDevice(&tmp));
74  value = tmp;
75  return RuntimeDeviceConfigReturnCode::SUCCESS;
76  }
77 
78  VTKM_CONT virtual RuntimeDeviceConfigReturnCode GetMaxDevices(
79  vtkm::Id& value) const override final
80  {
81  value = this->CudaDeviceCount;
82  return RuntimeDeviceConfigReturnCode::SUCCESS;
83  }
84 
87  VTKM_CONT RuntimeDeviceConfigReturnCode
88  GetCudaDeviceProp(std::vector<cudaDeviceProp>& value) const
89  {
90  value = CudaProp;
91  return RuntimeDeviceConfigReturnCode::SUCCESS;
92  }
93 
94 private:
95  std::vector<cudaDeviceProp> CudaProp;
96  vtkm::Id CudaDeviceCount;
97 };
98 } // namespace vtkm::cont::internal
99 } // namespace vtkm::cont
100 } // namespace vtkm
101 
102 #endif //vtk_m_cont_cuda_internal_RuntimeDeviceConfigurationCuda_h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
DeviceAdapterTagCuda.h
VTKM_CUDA_CALL
#define VTKM_CUDA_CALL(command)
A macro that can be wrapped around a CUDA command and will throw an ErrorCuda exception if the CUDA c...
Definition: ErrorCuda.h:38
RuntimeDeviceConfiguration.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::LogLevel::Error
@ Error
Important but non-fatal errors, such as device fail-over.
VTKM_LOG_S
#define VTKM_LOG_S(level,...)
Writes a message using stream syntax to the indicated log level.
Definition: Logging.h:261
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
Logging.h
Logging utilities.
ErrorCuda.h