MeshLib C++ Docs
Loading...
Searching...
No Matches
MRCudaAccessor.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRViewerFwd.h"
4#include "MRMesh/MRExpected.h"
5
6#include <functional>
7#include <memory>
8
9#ifndef MRVIEWER_NO_VOXELS
12#endif
13
14namespace MR
15{
16
17struct PointsToDistanceVolumeParams;
19class MRVIEWER_CLASS CudaAccessor
20{
21public:
23 using CudaFreeMemoryFunc = std::function<size_t()>;
25 using CudaFwnConstructor = std::function<std::unique_ptr<IFastWindingNumber>( const Mesh& )>;
27 using CudaMeshProjectorConstructor = std::function<std::unique_ptr<IPointsToMeshProjector>()>;
29 using CudaPointsProjectorConstructor = std::function<std::unique_ptr<IPointsProjector>()>;
30
31#ifndef MRVIEWER_NO_VOXELS
32 using CudaPointsToDistanceVolumeCallback = std::function<Expected<SimpleVolumeMinMax>( const PointCloud& cloud, const PointsToDistanceVolumeParams& params )>;
33 using CudaPointsToDistanceVolumeByPartsCallback = std::function<Expected<void>( const PointCloud& cloud, const PointsToDistanceVolumeParams& params, std::function<Expected<void> ( const SimpleVolumeMinMax& volume, int zOffset )> addPart, int layerOverlap )>;
35 using CudaComputeToolDistanceConstructor = std::function<std::unique_ptr<IComputeToolDistance>()>;
36#endif
37
38 // setup functions
39 MRVIEWER_API static void setCudaAvailable( bool val, int maxDriverVersion, int runtimeVersion, int computeMajor, int computeMinor );
40 MRVIEWER_API static void setCudaFreeMemoryFunc( CudaFreeMemoryFunc freeMemFunc );
41 MRVIEWER_API static void setCudaFastWindingNumberConstructor( CudaFwnConstructor fwnCtor );
44
45#ifndef MRVIEWER_NO_VOXELS
49#endif
50
51 // Returns true if CUDA is available on this computer
52 [[nodiscard]] MRVIEWER_API static bool isCudaAvailable();
53
54 // Returns maximum supported by driver version
55 [[nodiscard]] MRVIEWER_API static int getCudaMaxDriverSupportedVersion();
56
57 // Returns version of current runtime
58 [[nodiscard]] MRVIEWER_API static int getCudaRuntimeVersion();
59
60 // Returns Compute Capability major version of current device
61 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMajor();
62
63 // Returns Compute Capability minor version of current device
64 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMinor();
65
66 // Returns number of free bytes on cuda
67 [[nodiscard]] MRVIEWER_API static size_t getCudaFreeMemory();
68
69 // Returns cuda implementation of IFastWindingNumber
70 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IFastWindingNumber> getCudaFastWindingNumber( const Mesh& mesh );
71
72 // Returns cuda implementation of IPointsToMeshProjector
73 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IPointsToMeshProjector> getCudaPointsToMeshProjector();
74
75 // Returns cuda implementation of IPointsProjector
76 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IPointsProjector> getCudaPointsProjector();
77
78#ifndef MRVIEWER_NO_VOXELS
79 // Returns cuda implementation of PointsToDistanceVolumeCallback
81
82 // Returns cuda implementation of PointsToDistanceVolumeByPartsCallback
84
86 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IComputeToolDistance> getCudaComputeToolDistance();
87#endif
88
91 [[nodiscard]] MRVIEWER_API static size_t fastWindingNumberMeshMemory( const Mesh& mesh );
92
95 [[nodiscard]] MRVIEWER_API static size_t fromGridMemory( const Mesh& mesh, const Vector3i& dims );
96
101 [[nodiscard]] MRVIEWER_API static size_t fromVectorMemory( const Mesh& mesh, size_t inputSize );
102
107 [[nodiscard]] MRVIEWER_API static size_t selfIntersectionsMemory( const Mesh& mesh );
108
113 [[nodiscard]] MRVIEWER_API static size_t pointsToDistanceVolumeMemory( const PointCloud& pointCloud, const Vector3i& dims, const VertNormals* ptNormals );
114
115private:
116 CudaAccessor() = default;
117 ~CudaAccessor() = default;
118
119 static CudaAccessor& instance_();
120
121 bool isCudaAvailable_ = false;
122 int maxDriverVersion_ = 0;
123 int runtimeVersion_ = 0;
124 int computeMajor_ = 0;
125 int computeMinor_ = 0;
126 CudaFreeMemoryFunc freeMemFunc_;
127 CudaFwnConstructor fwnCtor_;
130#ifndef MRVIEWER_NO_VOXELS
131 CudaPointsToDistanceVolumeCallback pointsToDistanceVolumeCallback_;
132 CudaPointsToDistanceVolumeByPartsCallback pointsToDistanceVolumeByPartsCallback_;
134#endif
135};
136
137} //namespace MR
The purpose of this class is to access CUDA algorithms without explicit dependency on MRCuda.
Definition MRCudaAccessor.h:20
static MRVIEWER_API std::unique_ptr< IComputeToolDistance > getCudaComputeToolDistance()
Returns CUDA implementation of IComputeToolDistance.
std::function< std::unique_ptr< IComputeToolDistance >()> CudaComputeToolDistanceConstructor
Returns specific implementation of IComputeToolDistance interface that computes on GPU.
Definition MRCudaAccessor.h:35
static MRVIEWER_API size_t getCudaFreeMemory()
static MRVIEWER_API int getCudaRuntimeVersion()
static MRVIEWER_API size_t selfIntersectionsMemory(const Mesh &mesh)
returns amount of required GPU memory for CudaFastWindingNumber::calcSelfIntersections operation
static MRVIEWER_API void setCudaMeshProjectorConstructor(CudaMeshProjectorConstructor mpCtor)
std::function< std::unique_ptr< IFastWindingNumber >(const Mesh &)> CudaFwnConstructor
Returns specific implementation of IFastWindingNumber interface that computes windings on GPU.
Definition MRCudaAccessor.h:25
static MRVIEWER_API int getComputeCapabilityMinor()
static MRVIEWER_API std::unique_ptr< IPointsToMeshProjector > getCudaPointsToMeshProjector()
static MRVIEWER_API int getCudaMaxDriverSupportedVersion()
std::function< Expected< SimpleVolumeMinMax >(const PointCloud &cloud, const PointsToDistanceVolumeParams &params)> CudaPointsToDistanceVolumeCallback
Definition MRCudaAccessor.h:32
static MRVIEWER_API void setCudaFastWindingNumberConstructor(CudaFwnConstructor fwnCtor)
static MRVIEWER_API void setCudaAvailable(bool val, int maxDriverVersion, int runtimeVersion, int computeMajor, int computeMinor)
static MRVIEWER_API size_t fromGridMemory(const Mesh &mesh, const Vector3i &dims)
static MRVIEWER_API bool isCudaAvailable()
static MRVIEWER_API int getComputeCapabilityMajor()
static MRVIEWER_API void setCudaComputeToolDistanceConstructor(CudaComputeToolDistanceConstructor ctdCtor)
std::function< size_t()> CudaFreeMemoryFunc
Returns amount of free memory on GPU.
Definition MRCudaAccessor.h:23
std::function< std::unique_ptr< IPointsToMeshProjector >()> CudaMeshProjectorConstructor
Returns specific implementation of IPointsToMeshProjector interface projects on GPU.
Definition MRCudaAccessor.h:27
std::function< Expected< void >(const PointCloud &cloud, const PointsToDistanceVolumeParams &params, std::function< Expected< void >(const SimpleVolumeMinMax &volume, int zOffset)> addPart, int layerOverlap)> CudaPointsToDistanceVolumeByPartsCallback
Definition MRCudaAccessor.h:33
static MRVIEWER_API size_t fastWindingNumberMeshMemory(const Mesh &mesh)
static MRVIEWER_API void setCudaPointsProjectorConstructor(CudaPointsProjectorConstructor ppCtor)
static MRVIEWER_API size_t fromVectorMemory(const Mesh &mesh, size_t inputSize)
returns amount of required GPU memory for CudaFastWindingNumber::calcFromVector operation
static MRVIEWER_API CudaPointsToDistanceVolumeByPartsCallback getCudaPointsToDistanceVolumeByPartsCallback()
static MRVIEWER_API size_t pointsToDistanceVolumeMemory(const PointCloud &pointCloud, const Vector3i &dims, const VertNormals *ptNormals)
returns amount of required GPU memory for Cuda::pointsToDistanceVolume
static MRVIEWER_API std::unique_ptr< IFastWindingNumber > getCudaFastWindingNumber(const Mesh &mesh)
static MRVIEWER_API CudaPointsToDistanceVolumeCallback getCudaPointsToDistanceVolumeCallback()
std::function< std::unique_ptr< IPointsProjector >()> CudaPointsProjectorConstructor
Returns specific implementation of IPointsProjector interface projects on GPU.
Definition MRCudaAccessor.h:29
static MRVIEWER_API void setCudaPointsToDistanceVolumeCallback(CudaPointsToDistanceVolumeCallback callback)
static MRVIEWER_API void setCudaPointsToDistanceVolumeByPartsCallback(CudaPointsToDistanceVolumeByPartsCallback callback)
static MRVIEWER_API std::unique_ptr< IPointsProjector > getCudaPointsProjector()
static MRVIEWER_API void setCudaFreeMemoryFunc(CudaFreeMemoryFunc freeMemFunc)
Definition MRCameraOrientationPlugin.h:8
tl::expected< T, E > Expected
Definition MRExpected.h:25
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRPointCloud.h:17
Definition MRPointsToDistanceVolume.h:13