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
10#include "MRVoxels/MRVoxelsFwd.h"
12#endif
13
14namespace MR
15{
18
19
20struct PointsToDistanceVolumeParams;
22class MRVIEWER_CLASS CudaAccessor
23{
24public:
26 using CudaFreeMemoryFunc = std::function<size_t()>;
28 using CudaFwnConstructor = std::function<std::unique_ptr<IFastWindingNumber>( const Mesh& )>;
30 using CudaMeshProjectorConstructor = std::function<std::unique_ptr<IPointsToMeshProjector>()>;
32 using CudaPointsProjectorConstructor = std::function<std::unique_ptr<IPointsProjector>()>;
33
34#ifndef MRVIEWER_NO_VOXELS
35 using CudaPointsToDistanceVolumeCallback = std::function<Expected<SimpleVolumeMinMax>( const PointCloud& cloud, const PointsToDistanceVolumeParams& params )>;
36 using CudaPointsToDistanceVolumeByPartsCallback = std::function<Expected<void>( const PointCloud& cloud, const PointsToDistanceVolumeParams& params, std::function<Expected<void> ( const SimpleVolumeMinMax& volume, int zOffset )> addPart, int layerOverlap )>;
38 using CudaComputeToolDistanceConstructor = std::function<std::unique_ptr<IComputeToolDistance>()>;
39#endif
40
42 MRVIEWER_API static void setCudaAvailable( bool val, int maxDriverVersion, int runtimeVersion, int computeMajor, int computeMinor );
43 MRVIEWER_API static void setCudaFreeMemoryFunc( CudaFreeMemoryFunc freeMemFunc );
44 MRVIEWER_API static void setCudaFastWindingNumberConstructor( CudaFwnConstructor fwnCtor );
47
48#ifndef MRVIEWER_NO_VOXELS
52#endif
53
56 [[nodiscard]] MRVIEWER_API static bool isCudaSupportedByPlarform();
57
59 [[nodiscard]] MRVIEWER_API static bool isCudaAvailable();
60
62 [[nodiscard]] MRVIEWER_API static int getCudaMaxDriverSupportedVersion();
63
65 [[nodiscard]] MRVIEWER_API static int getCudaRuntimeVersion();
66
68 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMajor();
69
71 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMinor();
72
74 [[nodiscard]] MRVIEWER_API static size_t getCudaFreeMemory();
75
77 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IFastWindingNumber> getCudaFastWindingNumber( const Mesh& mesh );
78
80 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IPointsToMeshProjector> getCudaPointsToMeshProjector();
81
83 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IPointsProjector> getCudaPointsProjector();
84
85#ifndef MRVIEWER_NO_VOXELS
88
91
93 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IComputeToolDistance> getCudaComputeToolDistance();
94#endif
95
98 [[nodiscard]] MRVIEWER_API static size_t fastWindingNumberMeshMemory( const Mesh& mesh );
99
102 [[nodiscard]] MRVIEWER_API static size_t fromGridMemory( const Mesh& mesh, const Vector3i& dims );
103
108 [[nodiscard]] MRVIEWER_API static size_t fromVectorMemory( const Mesh& mesh, size_t inputSize );
109
114 [[nodiscard]] MRVIEWER_API static size_t selfIntersectionsMemory( const Mesh& mesh );
115
120 [[nodiscard]] MRVIEWER_API static size_t pointsToDistanceVolumeMemory( const PointCloud& pointCloud, const Vector3i& dims, const VertNormals* ptNormals );
121
122private:
123 CudaAccessor() = default;
124 ~CudaAccessor() = default;
125
126 static CudaAccessor& instance_();
127
128 bool isCudaAvailable_ = false;
129 int maxDriverVersion_ = 0;
130 int runtimeVersion_ = 0;
131 int computeMajor_ = 0;
132 int computeMinor_ = 0;
133 CudaFreeMemoryFunc freeMemFunc_;
134 CudaFwnConstructor fwnCtor_;
137#ifndef MRVIEWER_NO_VOXELS
138 CudaPointsToDistanceVolumeCallback pointsToDistanceVolumeCallback_;
139 CudaPointsToDistanceVolumeByPartsCallback pointsToDistanceVolumeByPartsCallback_;
141#endif
142};
143
144}
The purpose of this class is to access CUDA algorithms without explicit dependency on MRCuda.
Definition MRCudaAccessor.h:23
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:38
static MRVIEWER_API size_t getCudaFreeMemory()
Returns number of free bytes on cuda.
static MRVIEWER_API int getCudaRuntimeVersion()
Returns version of current runtime.
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:28
static MRVIEWER_API int getComputeCapabilityMinor()
Returns Compute Capability minor version of current device.
static MRVIEWER_API std::unique_ptr< IPointsToMeshProjector > getCudaPointsToMeshProjector()
Returns cuda implementation of IPointsToMeshProjector.
static MRVIEWER_API bool isCudaSupportedByPlarform()
tl::expected< T, E > Expected
Definition MRExpected.h:31
static MRVIEWER_API int getCudaMaxDriverSupportedVersion()
Returns maximum supported by driver version.
std::function< Expected< SimpleVolumeMinMax >(const PointCloud &cloud, const PointsToDistanceVolumeParams &params)> CudaPointsToDistanceVolumeCallback
Definition MRCudaAccessor.h:35
static MRVIEWER_API void setCudaFastWindingNumberConstructor(CudaFwnConstructor fwnCtor)
static MRVIEWER_API void setCudaAvailable(bool val, int maxDriverVersion, int runtimeVersion, int computeMajor, int computeMinor)
setup functions
static MRVIEWER_API size_t fromGridMemory(const Mesh &mesh, const Vector3i &dims)
static MRVIEWER_API bool isCudaAvailable()
Returns true if CUDA is available on this computer.
static MRVIEWER_API int getComputeCapabilityMajor()
Returns Compute Capability major version of current device.
static MRVIEWER_API void setCudaComputeToolDistanceConstructor(CudaComputeToolDistanceConstructor ctdCtor)
std::function< size_t()> CudaFreeMemoryFunc
Returns amount of free memory on GPU.
Definition MRCudaAccessor.h:26
std::function< std::unique_ptr< IPointsToMeshProjector >()> CudaMeshProjectorConstructor
Returns specific implementation of IPointsToMeshProjector interface projects on GPU.
Definition MRCudaAccessor.h:30
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:36
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()
Returns cuda implementation of PointsToDistanceVolumeByPartsCallback.
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)
Returns cuda implementation of IFastWindingNumber.
static MRVIEWER_API CudaPointsToDistanceVolumeCallback getCudaPointsToDistanceVolumeCallback()
Returns cuda implementation of PointsToDistanceVolumeCallback.
std::function< std::unique_ptr< IPointsProjector >()> CudaPointsProjectorConstructor
Returns specific implementation of IPointsProjector interface projects on GPU.
Definition MRCudaAccessor.h:32
static MRVIEWER_API void setCudaPointsToDistanceVolumeCallback(CudaPointsToDistanceVolumeCallback callback)
static MRVIEWER_API void setCudaPointsToDistanceVolumeByPartsCallback(CudaPointsToDistanceVolumeByPartsCallback callback)
static MRVIEWER_API std::unique_ptr< IPointsProjector > getCudaPointsProjector()
Returns cuda implementation of IPointsProjector.
static MRVIEWER_API void setCudaFreeMemoryFunc(CudaFreeMemoryFunc freeMemFunc)
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh.h:23
Definition MRPointCloud.h:17
Definition MRPointsToDistanceVolume.h:16