genericDeviceInfo.hpp 2.88 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
// Copyright (c) 2012-2017 VideoStitch SAS
// Copyright (c) 2018 stitchEm

#pragma once
#include "config.hpp"
#include <vector>
#include <iostream>
#include <type_traits>

namespace VideoStitch {
namespace Discovery {

enum class Framework { CUDA, OpenCL, Unknown };

enum class FrameworkStatus : int {
  Ok = 0x00,
  OutdatedDriver = 0x01,
  MissingDriver = 0x02,
  NoCompatibleDevice = 0x03,
  GenericError = 0xFF
};

enum class DeviceType { GPU, CPU, other };

enum class Vendor { AMD, NVIDIA, INTEL, UNKNOWN };

struct DeviceProperties {
  /** Name */
  char name[256];

  /** Driver Version */
  char driverVersion[256];

  /** 32 or 64 bit pointers */
  unsigned addressBits;

  /** Size in bytes */
  size_t globalMemSize;

  /** Device type */
  DeviceType type;

  /** Vendor name */
  Vendor vendor;

  /** Can be used to stitch videos? */
  bool compatible;

  Framework supportedFramework;
};

inline std::ostream& operator<<(std::ostream& os, const Discovery::DeviceProperties& prop) {
  os << "GPU device: " << prop.name << " (" << prop.addressBits << " Bit ";

  switch (prop.type) {
    case DeviceType::GPU:
      os << "GPU";
      break;
    case DeviceType::CPU:
      os << "CPU";
      break;
    case DeviceType::other:
      os << "other";
      break;
  }

  os << "), global memory size: " << prop.globalMemSize / 1024 / 1024 << " MB";
  return os;
}

VS_DISCOVERY_EXPORT int getNumberOfDevices();
VS_DISCOVERY_EXPORT int getNumberOfOpenCLDevices();
VS_DISCOVERY_EXPORT int getNumberOfCudaDevices();

VS_DISCOVERY_EXPORT FrameworkStatus getFrameworkStatus(Framework framework);

// returns true and fills the 2nd argument if a device corresponds to the vsDeviceIndex
// Otherwise, it returns false and doesn't fill the 2nd argument
VS_DISCOVERY_EXPORT bool getDeviceProperties(unsigned vsDeviceIndex, struct DeviceProperties& prop);

// returns true and fills the 2nd argument with the corresponding backend index
// if a device corresponds to the vsDeviceIndex.
// Otherwise, it returns false and doesn't fill the 2nd argument
VS_DISCOVERY_EXPORT bool getBackendDeviceIndex(int vsDeviceIndex, int& backendDeviceIndex);

// returns true and fills the 2nd argument with the corresponding videostitch index
// if a device corresponds to the backendIndex of the given famework.
// Otherwise, it returns false and doesn't fill the 2nd argument
VS_DISCOVERY_EXPORT bool getVSDeviceIndex(int backendDeviceIndex, int& vsDeviceIndex, Framework framework);

VS_DISCOVERY_EXPORT std::string getFrameworkName(const Framework& framework);

VS_DISCOVERY_EXPORT bool isFrameworkAvailable(const Framework& framework);

/**
 * @brief Returns framework backend with lower FrameworkStatus.
 *        If all backends have same level, returns prefered one
 * @return best framework
 */
VS_DISCOVERY_EXPORT Framework getBestFramework(const Framework& preferedFramework = Framework::CUDA);

}  // namespace Discovery
}  // namespace VideoStitch