MeshLib
 
Loading...
Searching...
No Matches
MRCudaAccessor.h
Go to the documentation of this file.
1#pragma once
2
3#include "exports.h"
4#include "MRMesh/MRMeshFwd.h"
5#include "MRMesh/MRExpected.h"
6#include <functional>
7#include <memory>
8
9namespace MR
10{
11
12struct PointsToDistanceVolumeParams;
14class MRVIEWER_CLASS CudaAccessor
15{
16public:
18 using CudaFreeMemoryFunc = std::function<size_t()>;
20 using CudaFwnConstructor = std::function<std::unique_ptr<IFastWindingNumber>( const Mesh& )>;
22 using CudaMeshProjectorConstructor = std::function<std::unique_ptr<IPointsToMeshProjector>()>;
23
24 using CudaPointsToDistanceVolumeCallback = std::function<Expected<SimpleVolume>( const PointCloud& cloud, const PointsToDistanceVolumeParams& params )>;
25
26 // setup functions
27 MRVIEWER_API static void setCudaAvailable( bool val, int maxDriverVersion, int runtimeVersion, int computeMajor, int computeMinor );
28 MRVIEWER_API static void setCudaFreeMemoryFunc( CudaFreeMemoryFunc freeMemFunc );
29 MRVIEWER_API static void setCudaFastWindingNumberConstructor( CudaFwnConstructor fwnCtor );
32
33 // Returns true if CUDA is available on this computer
34 [[nodiscard]] MRVIEWER_API static bool isCudaAvailable();
35
36 // Returns maximum supported by driver version
37 [[nodiscard]] MRVIEWER_API static int getCudaMaxDriverSupportedVersion();
38
39 // Returns version of current runtime
40 [[nodiscard]] MRVIEWER_API static int getCudaRuntimeVersion();
41
42 // Returns Compute Capability major version of current device
43 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMajor();
44
45 // Returns Compute Capability minor version of current device
46 [[nodiscard]] MRVIEWER_API static int getComputeCapabilityMinor();
47
48 // Returns number of free bytes on cuda
49 [[nodiscard]] MRVIEWER_API static size_t getCudaFreeMemory();
50
51 // Returns cuda implementation of IFastWindingNumber
52 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IFastWindingNumber> getCudaFastWindingNumber( const Mesh& mesh );
53
54 // Returns cuda implementation of IPointsToMeshProjector
55 [[nodiscard]] MRVIEWER_API static std::unique_ptr<IPointsToMeshProjector> getCudaPointsToMeshProjector();
56
57 // Returns cuda implementation of PointsToDistanceVolumeCallback
59
62 [[nodiscard]] MRVIEWER_API static size_t fastWindingNumberMeshMemory( const Mesh& mesh );
63
66 [[nodiscard]] MRVIEWER_API static size_t fromGridMemory( const Mesh& mesh, const Vector3i& dims );
67
72 [[nodiscard]] MRVIEWER_API static size_t fromVectorMemory( const Mesh& mesh, size_t inputSize );
73
78 [[nodiscard]] MRVIEWER_API static size_t selfIntersectionsMemory( const Mesh& mesh );
79private:
80 CudaAccessor() = default;
81 ~CudaAccessor() = default;
82
83 static CudaAccessor& instance_();
84
85 bool isCudaAvailable_ = false;
86 int maxDriverVersion_ = 0;
87 int runtimeVersion_ = 0;
88 int computeMajor_ = 0;
89 int computeMinor_ = 0;
90 CudaFreeMemoryFunc freeMemFunc_;
91 CudaFwnConstructor fwnCtor_;
93 CudaPointsToDistanceVolumeCallback pointsToDistanceVolumeCallback_;
94};
95
96} //namespace MR
The purpose of this class is to access CUDA algorithms without explicit dependency on MRCuda.
Definition MRCudaAccessor.h:15
std::function< Expected< SimpleVolume >(const PointCloud &cloud, const PointsToDistanceVolumeParams &params)> CudaPointsToDistanceVolumeCallback
Definition MRCudaAccessor.h:24
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:20
static MRVIEWER_API int getComputeCapabilityMinor()
static MRVIEWER_API std::unique_ptr< IPointsToMeshProjector > getCudaPointsToMeshProjector()
static MRVIEWER_API int getCudaMaxDriverSupportedVersion()
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:18
std::function< std::unique_ptr< IPointsToMeshProjector >()> CudaMeshProjectorConstructor
Returns specific implementation of IPointsToMeshProjector interface projects on GPU.
Definition MRCudaAccessor.h:22
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:7
Definition MRMesh/MRMesh.h:23
Definition MRMesh/MRPointCloud.h:16
Definition MRPointsToDistanceVolume.h:10