MeshLib
 
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
11#endif
12
13namespace MR
14{
15
16struct PointsToDistanceVolumeParams;
18class MRVIEWER_CLASS CudaAccessor
19{
20public:
22 using CudaFreeMemoryFunc = std::function<size_t()>;
24 using CudaFwnConstructor = std::function<std::unique_ptr<IFastWindingNumber>( const Mesh& )>;
26 using CudaMeshProjectorConstructor = std::function<std::unique_ptr<IPointsToMeshProjector>()>;
27
28#ifndef MRVIEWER_NO_VOXELS
29 using CudaPointsToDistanceVolumeCallback = std::function<Expected<SimpleVolumeMinMax>( const PointCloud& cloud, const PointsToDistanceVolumeParams& params )>;
30#endif
31
32 // setup functions
33 MRVIEWER_API static void setCudaAvailable( bool val, int maxDriverVersion, int runtimeVersion, int computeMajor, int computeMinor );
34 MRVIEWER_API static void setCudaFreeMemoryFunc( CudaFreeMemoryFunc freeMemFunc );
35 MRVIEWER_API static void setCudaFastWindingNumberConstructor( CudaFwnConstructor fwnCtor );
37
38#ifndef MRVIEWER_NO_VOXELS
40#endif
41
42 // Returns true if CUDA is available on this computer
43 [[nodiscard]] MRVIEWER_API static bool isCudaAvailable();
44
45 // Returns maximum supported by driver version
46 [[nodiscard]] MRVIEWER_API static int getCudaMaxDriverSupportedVersion();
47
48 // Returns version of current runtime
49 [[nodiscard]] MRVIEWER_API static int getCudaRuntimeVersion();
50
51 // Returns Compute Capability major version of current device
52 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMajor();
53
54 // Returns Compute Capability minor version of current device
55 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMinor();
56
57 // Returns number of free bytes on cuda
58 [[nodiscard]] MRVIEWER_API static size_t getCudaFreeMemory();
59
60 // Returns cuda implementation of IFastWindingNumber
61 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IFastWindingNumber> getCudaFastWindingNumber( const Mesh& mesh );
62
63 // Returns cuda implementation of IPointsToMeshProjector
64 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IPointsToMeshProjector> getCudaPointsToMeshProjector();
65
66#ifndef MRVIEWER_NO_VOXELS
67 // Returns cuda implementation of PointsToDistanceVolumeCallback
69#endif
70
73 [[nodiscard]] MRVIEWER_API static size_t fastWindingNumberMeshMemory( const Mesh& mesh );
74
77 [[nodiscard]] MRVIEWER_API static size_t fromGridMemory( const Mesh& mesh, const Vector3i& dims );
78
83 [[nodiscard]] MRVIEWER_API static size_t fromVectorMemory( const Mesh& mesh, size_t inputSize );
84
89 [[nodiscard]] MRVIEWER_API static size_t selfIntersectionsMemory( const Mesh& mesh );
90private:
91 CudaAccessor() = default;
92 ~CudaAccessor() = default;
93
94 static CudaAccessor& instance_();
95
96 bool isCudaAvailable_ = false;
97 int maxDriverVersion_ = 0;
98 int runtimeVersion_ = 0;
99 int computeMajor_ = 0;
100 int computeMinor_ = 0;
101 CudaFreeMemoryFunc freeMemFunc_;
102 CudaFwnConstructor fwnCtor_;
104#ifndef MRVIEWER_NO_VOXELS
105 CudaPointsToDistanceVolumeCallback pointsToDistanceVolumeCallback_;
106#endif
107};
108
109} //namespace MR
The purpose of this class is to access CUDA algorithms without explicit dependency on MRCuda.
Definition MRCudaAccessor.h:19
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:24
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:29
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()
std::function< size_t()> CudaFreeMemoryFunc
Returns amount of free memory on GPU.
Definition MRCudaAccessor.h:22
std::function< std::unique_ptr< IPointsToMeshProjector >()> CudaMeshProjectorConstructor
Returns specific implementation of IPointsToMeshProjector interface projects on GPU.
Definition MRCudaAccessor.h:26
static MRVIEWER_API size_t fastWindingNumberMeshMemory(const Mesh &mesh)
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 std::unique_ptr< IFastWindingNumber > getCudaFastWindingNumber(const Mesh &mesh)
static MRVIEWER_API CudaPointsToDistanceVolumeCallback getCudaPointsToDistanceVolumeCallback()
static MRVIEWER_API void setCudaPointsToDistanceVolumeCallback(CudaPointsToDistanceVolumeCallback callback)
static MRVIEWER_API void setCudaFreeMemoryFunc(CudaFreeMemoryFunc freeMemFunc)
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRPointCloud.h:16
Definition MRPointsToDistanceVolume.h:12