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
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 using CudaPointsToDistanceVolumeByPartsCallback = std::function<Expected<void>( const PointCloud& cloud, const PointsToDistanceVolumeParams& params, std::function<Expected<void> ( const SimpleVolumeMinMax& volume, int zOffset )> addPart, int layerOverlap )>;
31#endif
32
33 // setup functions
34 MRVIEWER_API static void setCudaAvailable( bool val, int maxDriverVersion, int runtimeVersion, int computeMajor, int computeMinor );
35 MRVIEWER_API static void setCudaFreeMemoryFunc( CudaFreeMemoryFunc freeMemFunc );
36 MRVIEWER_API static void setCudaFastWindingNumberConstructor( CudaFwnConstructor fwnCtor );
38
39#ifndef MRVIEWER_NO_VOXELS
42#endif
43
44 // Returns true if CUDA is available on this computer
45 [[nodiscard]] MRVIEWER_API static bool isCudaAvailable();
46
47 // Returns maximum supported by driver version
48 [[nodiscard]] MRVIEWER_API static int getCudaMaxDriverSupportedVersion();
49
50 // Returns version of current runtime
51 [[nodiscard]] MRVIEWER_API static int getCudaRuntimeVersion();
52
53 // Returns Compute Capability major version of current device
54 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMajor();
55
56 // Returns Compute Capability minor version of current device
57 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMinor();
58
59 // Returns number of free bytes on cuda
60 [[nodiscard]] MRVIEWER_API static size_t getCudaFreeMemory();
61
62 // Returns cuda implementation of IFastWindingNumber
63 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IFastWindingNumber> getCudaFastWindingNumber( const Mesh& mesh );
64
65 // Returns cuda implementation of IPointsToMeshProjector
66 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IPointsToMeshProjector> getCudaPointsToMeshProjector();
67
68#ifndef MRVIEWER_NO_VOXELS
69 // Returns cuda implementation of PointsToDistanceVolumeCallback
71
72 // Returns cuda implementation of PointsToDistanceVolumeByPartsCallback
74#endif
75
78 [[nodiscard]] MRVIEWER_API static size_t fastWindingNumberMeshMemory( const Mesh& mesh );
79
82 [[nodiscard]] MRVIEWER_API static size_t fromGridMemory( const Mesh& mesh, const Vector3i& dims );
83
88 [[nodiscard]] MRVIEWER_API static size_t fromVectorMemory( const Mesh& mesh, size_t inputSize );
89
94 [[nodiscard]] MRVIEWER_API static size_t selfIntersectionsMemory( const Mesh& mesh );
95
100 [[nodiscard]] MRVIEWER_API static size_t pointsToDistanceVolumeMemory( const PointCloud& pointCloud, const Vector3i& dims, const VertNormals* ptNormals );
101
102private:
103 CudaAccessor() = default;
104 ~CudaAccessor() = default;
105
106 static CudaAccessor& instance_();
107
108 bool isCudaAvailable_ = false;
109 int maxDriverVersion_ = 0;
110 int runtimeVersion_ = 0;
111 int computeMajor_ = 0;
112 int computeMinor_ = 0;
113 CudaFreeMemoryFunc freeMemFunc_;
114 CudaFwnConstructor fwnCtor_;
116#ifndef MRVIEWER_NO_VOXELS
117 CudaPointsToDistanceVolumeCallback pointsToDistanceVolumeCallback_;
118 CudaPointsToDistanceVolumeByPartsCallback pointsToDistanceVolumeByPartsCallback_;
119#endif
120};
121
122} //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
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:30
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 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()
static MRVIEWER_API void setCudaPointsToDistanceVolumeCallback(CudaPointsToDistanceVolumeCallback callback)
static MRVIEWER_API void setCudaPointsToDistanceVolumeByPartsCallback(CudaPointsToDistanceVolumeByPartsCallback callback)
static MRVIEWER_API void setCudaFreeMemoryFunc(CudaFreeMemoryFunc freeMemFunc)
tl::expected< T, E > Expected
Definition MRExpected.h:59
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRPointCloud.h:16
Definition MRPointsToDistanceVolume.h:13