Program Listing for File Distance.h
↰ Return to documentation for file (include/gwmodelpp/spatialweight/Distance.h
)
#ifndef DISTANCE_H
#define DISTANCE_H
#ifdef ENABLE_CUDA
#include <cuda_runtime.h>
#include "gwmodelpp/spatialweight/cuda/ISpatialCudaEnabled.h"
#endif // ENABLE_CUDA
#include <memory>
#include <string>
#include <unordered_map>
#include "armadillo_config.h"
#include <variant>
namespace gwm
{
typedef std::variant<arma::mat, arma::vec, arma::uword> DistParamVariant;
class Distance
#ifdef ENABLE_CUDA
: public ISpatialCudaEnabled
#endif
{
public:
struct Parameter
{
arma::uword total;
Parameter(): total(0) {}
};
enum DistanceType
{
CRSDistance,
MinkwoskiDistance,
DMatDistance,
OneDimDistance,
CRSSTDistance,
};
static std::unordered_map<DistanceType, std::string> TypeNameMapper;
public:
virtual ~Distance() {};
virtual Distance* clone() const = 0;
virtual DistanceType type() = 0;
virtual Parameter* parameter() const = delete;
public:
virtual void makeParameter(std::initializer_list<DistParamVariant> plist) = 0;
virtual arma::vec distance(arma::uword focus) = 0;
#ifdef ENABLE_CUDA
virtual bool useCuda() override { return mUseCuda; }
virtual void setUseCuda(bool isUseCuda) override { mUseCuda = isUseCuda; }
virtual cudaError_t prepareCuda(size_t gpuId) override;
virtual cudaError_t distance(arma::uword focus, double* d_dists, size_t* elems)
{
throw std::logic_error("Function not yet implemented");
}
#endif // ENABLE_CUDA
virtual double maxDistance() = 0;
virtual double minDistance() = 0;
#ifdef ENABLE_CUDA
protected:
bool mUseCuda = false; //<! \~english Whether to use CUDA \~chinese 是否使用 CUDA
int mGpuID = 0; //<! \~english The ID of selected GPU \~chinese 选择的 GPU 的索引
bool mCudaPrepared = false; //<! \~english Whether CUDA has been prepared \~chinese CUDA 环境是否已经准备
size_t mCudaThreads = 0; //<! \~english Number of GPU threads \~chinese GPU 线程数
#endif // ENABLE_CUDA
};
}
#endif // DISTANCE_H