Program Listing for File Weight.h

Return to documentation for file (include/gwmodelpp/spatialweight/Weight.h)

#ifndef WEIGHT_H
#define WEIGHT_H

#ifdef ENABLE_CUDA
#include <cuda_runtime.h>
#include "gwmodelpp/spatialweight/cuda/ISpatialCudaEnabled.h"
#endif // ENABLE_CUDA

#include <unordered_map>
#include <string>
#include "armadillo_config.h"


namespace gwm
{

class Weight
#ifdef ENABLE_CUDA
    : public ISpatialCudaEnabled
#endif
{
public:

    enum WeightType
    {
        BandwidthWeight
    };

    static std::unordered_map<WeightType, std::string> TypeNameMapper;

public:

    Weight() {}

    virtual ~Weight() {}

    virtual Weight* clone() const = 0;

public:

    virtual arma::vec weight(arma::vec dist) = 0;

#ifdef ENABLE_CUDA
    bool useCuda() { return mUseCuda; }

    void setUseCuda(bool isUseCuda) { mUseCuda = isUseCuda; }

    virtual cudaError_t prepareCuda(size_t gpuId) override;

    virtual cudaError_t weight(double* d_dists, double* d_weights, size_t elems)
    {
        throw std::logic_error("Function not yet implemented");
    }
#endif

#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 // WEIGHT_H