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