forked from mindspore-Ecosystem/mindspore
new api use gpu
This commit is contained in:
parent
6122ee8202
commit
f545bcd9b0
|
@ -26,8 +26,7 @@
|
|||
namespace mindspore {
|
||||
enum DeviceType {
|
||||
kCPU = 0,
|
||||
kMaliGPU,
|
||||
kNvidiaGPU,
|
||||
kGPU,
|
||||
kKirinNPU,
|
||||
kAscend910,
|
||||
kAscend310,
|
||||
|
@ -103,14 +102,6 @@ class MS_API CPUDeviceInfo : public DeviceInfoContext {
|
|||
bool GetEnableFP16() const;
|
||||
};
|
||||
|
||||
class MS_API MaliGPUDeviceInfo : public DeviceInfoContext {
|
||||
public:
|
||||
enum DeviceType GetDeviceType() const override { return DeviceType::kMaliGPU; };
|
||||
|
||||
void SetEnableFP16(bool is_fp16);
|
||||
bool GetEnableFP16() const;
|
||||
};
|
||||
|
||||
class MS_API KirinNPUDeviceInfo : public DeviceInfoContext {
|
||||
public:
|
||||
enum DeviceType GetDeviceType() const override { return DeviceType::kKirinNPU; };
|
||||
|
@ -119,9 +110,9 @@ class MS_API KirinNPUDeviceInfo : public DeviceInfoContext {
|
|||
int GetFrequency() const;
|
||||
};
|
||||
|
||||
class MS_API NvidiaGPUDeviceInfo : public DeviceInfoContext {
|
||||
class MS_API GPUDeviceInfo : public DeviceInfoContext {
|
||||
public:
|
||||
enum DeviceType GetDeviceType() const override { return DeviceType::kNvidiaGPU; };
|
||||
enum DeviceType GetDeviceType() const override { return DeviceType::kGPU; };
|
||||
|
||||
void SetDeviceID(uint32_t device_id);
|
||||
uint32_t GetDeviceID() const;
|
||||
|
@ -132,15 +123,17 @@ class MS_API NvidiaGPUDeviceInfo : public DeviceInfoContext {
|
|||
inline void SetPrecisionMode(const std::string &precison_mode);
|
||||
inline std::string GetPrecisionMode() const;
|
||||
|
||||
void SetEnableFP16(bool is_fp16);
|
||||
bool GetEnableFP16() const;
|
||||
private:
|
||||
void SetPrecisionMode(const std::vector<char> &precision_mode);
|
||||
std::vector<char> GetPrecisionModeChar() const;
|
||||
};
|
||||
|
||||
void NvidiaGPUDeviceInfo::SetPrecisionMode(const std::string &precision_mode) {
|
||||
void GPUDeviceInfo::SetPrecisionMode(const std::string &precision_mode) {
|
||||
SetPrecisionMode(StringToChar(precision_mode));
|
||||
}
|
||||
std::string NvidiaGPUDeviceInfo::GetPrecisionMode() const { return CharToString(GetPrecisionModeChar()); }
|
||||
std::string GPUDeviceInfo::GetPrecisionMode() const { return CharToString(GetPrecisionModeChar()); }
|
||||
|
||||
class MS_API Ascend910DeviceInfo : public DeviceInfoContext {
|
||||
public:
|
||||
|
|
|
@ -21,12 +21,12 @@
|
|||
#include "utils/log_adapter.h"
|
||||
|
||||
constexpr auto kModelOptionCpuEnableFP16 = "mindspore.option.cpu.enable_fp16";
|
||||
constexpr auto kModelOptionMaliGpuEnableFP16 = "mindspore.option.mali_gpu.enable_fp16";
|
||||
constexpr auto kModelOptionGPUEnableFP16 = "mindspore.option.gpu.enable_fp16";
|
||||
constexpr auto kModelOptionKirinNpuFrequency = "mindspore.option.kirin_npu.frequency";
|
||||
constexpr auto kModelOptionDeviceID = "mindspore.option.device_id";
|
||||
constexpr auto kModelOptionNvidiaGpuDeviceID = kModelOptionDeviceID;
|
||||
constexpr auto kModelOptionNvidiaGpuTrtInferMode = "mindspore.option.nvidia_gpu.trt_infer_mode";
|
||||
constexpr auto kModelOptionNvidiaGpuPrecisionMode = "mindspore.option.nvidia_gpu.precision_mode";
|
||||
constexpr auto kModelOptionGPUDeviceID = kModelOptionDeviceID;
|
||||
constexpr auto kModelOptionGPUTrtInferMode = "mindspore.option.gpu.trt_infer_mode";
|
||||
constexpr auto kModelOptionGPUPrecisionMode = "mindspore.option.gpu.precision_mode";
|
||||
constexpr auto kModelOptionAscend910DeviceID = kModelOptionDeviceID;
|
||||
constexpr auto kModelOptionAscend310DeviceID = kModelOptionDeviceID;
|
||||
constexpr auto kModelOptionAscend310DumpCfgPath = "mindspore.option.ascend310.dump_config_file_path";
|
||||
|
@ -129,13 +129,13 @@ bool CPUDeviceInfo::GetEnableFP16() const {
|
|||
return GetValue<bool>(data_, kModelOptionCpuEnableFP16);
|
||||
}
|
||||
|
||||
void MaliGPUDeviceInfo::SetEnableFP16(bool is_fp16) {
|
||||
void GPUDeviceInfo::SetEnableFP16(bool is_fp16) {
|
||||
MS_EXCEPTION_IF_NULL(data_);
|
||||
data_->params[kModelOptionMaliGpuEnableFP16] = is_fp16;
|
||||
data_->params[kModelOptionGPUEnableFP16] = is_fp16;
|
||||
}
|
||||
bool MaliGPUDeviceInfo::GetEnableFP16() const {
|
||||
bool GPUDeviceInfo::GetEnableFP16() const {
|
||||
MS_EXCEPTION_IF_NULL(data_);
|
||||
return GetValue<bool>(data_, kModelOptionMaliGpuEnableFP16);
|
||||
return GetValue<bool>(data_, kModelOptionGPUEnableFP16);
|
||||
}
|
||||
|
||||
void KirinNPUDeviceInfo::SetFrequency(int frequency) {
|
||||
|
@ -147,31 +147,31 @@ int KirinNPUDeviceInfo::GetFrequency() const {
|
|||
return GetValue<int>(data_, kModelOptionKirinNpuFrequency);
|
||||
}
|
||||
|
||||
void NvidiaGPUDeviceInfo::SetDeviceID(uint32_t device_id) {
|
||||
void GPUDeviceInfo::SetDeviceID(uint32_t device_id) {
|
||||
MS_EXCEPTION_IF_NULL(data_);
|
||||
data_->params[kModelOptionNvidiaGpuDeviceID] = device_id;
|
||||
data_->params[kModelOptionGPUDeviceID] = device_id;
|
||||
}
|
||||
uint32_t NvidiaGPUDeviceInfo::GetDeviceID() const {
|
||||
uint32_t GPUDeviceInfo::GetDeviceID() const {
|
||||
MS_EXCEPTION_IF_NULL(data_);
|
||||
return GetValue<uint32_t>(data_, kModelOptionNvidiaGpuDeviceID);
|
||||
return GetValue<uint32_t>(data_, kModelOptionGPUDeviceID);
|
||||
}
|
||||
|
||||
void NvidiaGPUDeviceInfo::SetGpuTrtInferMode(bool gpu_trt_infer_mode) {
|
||||
void GPUDeviceInfo::SetGpuTrtInferMode(bool gpu_trt_infer_mode) {
|
||||
MS_EXCEPTION_IF_NULL(data_);
|
||||
data_->params[kModelOptionNvidiaGpuTrtInferMode] = gpu_trt_infer_mode;
|
||||
data_->params[kModelOptionGPUTrtInferMode] = gpu_trt_infer_mode;
|
||||
}
|
||||
bool NvidiaGPUDeviceInfo::GetGpuTrtInferMode() const {
|
||||
bool GPUDeviceInfo::GetGpuTrtInferMode() const {
|
||||
MS_EXCEPTION_IF_NULL(data_);
|
||||
return GetValue<bool>(data_, kModelOptionNvidiaGpuTrtInferMode);
|
||||
return GetValue<bool>(data_, kModelOptionGPUTrtInferMode);
|
||||
}
|
||||
|
||||
void NvidiaGPUDeviceInfo::SetPrecisionMode(const std::vector<char> &precision_mode) {
|
||||
void GPUDeviceInfo::SetPrecisionMode(const std::vector<char> &precision_mode) {
|
||||
MS_EXCEPTION_IF_NULL(data_);
|
||||
data_->params[kModelOptionNvidiaGpuPrecisionMode] = CharToString(precision_mode);
|
||||
data_->params[kModelOptionGPUPrecisionMode] = CharToString(precision_mode);
|
||||
}
|
||||
std::vector<char> NvidiaGPUDeviceInfo::GetPrecisionModeChar() const {
|
||||
std::vector<char> GPUDeviceInfo::GetPrecisionModeChar() const {
|
||||
MS_EXCEPTION_IF_NULL(data_);
|
||||
const std::string &ref = GetValue<std::string>(data_, kModelOptionNvidiaGpuPrecisionMode);
|
||||
const std::string &ref = GetValue<std::string>(data_, kModelOptionGPUPrecisionMode);
|
||||
return StringToChar(ref);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ Status GPUGraphImpl::InitEnv() {
|
|||
if (device_infos.size() != 1) {
|
||||
return kMCDeviceError;
|
||||
}
|
||||
auto gpu_info = device_infos[0]->Cast<NvidiaGPUDeviceInfo>();
|
||||
auto gpu_info = device_infos[0]->Cast<GPUDeviceInfo>();
|
||||
if (gpu_info == nullptr) {
|
||||
return kMCDeviceError;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,7 @@ namespace mindspore {
|
|||
namespace {
|
||||
std::string GetDeviceTypeString(enum DeviceType type) {
|
||||
static const std::map<enum DeviceType, std::string> kDeviceTypeStrs = {
|
||||
{kCPU, "CPU"}, {kMaliGPU, "MaliGPU"}, {kNvidiaGPU, "GPU"},
|
||||
{kKirinNPU, "KirinGPU"}, {kAscend910, "Ascend910"}, {kAscend310, "Ascend310"},
|
||||
{kCPU, "CPU"}, {kGPU, "GPU"}, {kKirinNPU, "KirinGPU"}, {kAscend910, "Ascend910"}, {kAscend310, "Ascend310"},
|
||||
};
|
||||
auto iter = kDeviceTypeStrs.find(type);
|
||||
if (iter != kDeviceTypeStrs.end()) {
|
||||
|
|
|
@ -163,7 +163,7 @@ uint32_t MsModel::GetDeviceID() const {
|
|||
return ascend910_info->GetDeviceID();
|
||||
}
|
||||
|
||||
auto gpu_info = device_infos[0]->Cast<NvidiaGPUDeviceInfo>();
|
||||
auto gpu_info = device_infos[0]->Cast<GPUDeviceInfo>();
|
||||
if (gpu_info != nullptr) {
|
||||
return gpu_info->GetDeviceID();
|
||||
}
|
||||
|
|
|
@ -26,8 +26,7 @@
|
|||
namespace mindspore {
|
||||
enum DeviceType {
|
||||
kCPU = 0,
|
||||
kMaliGPU,
|
||||
kNvidiaGPU,
|
||||
kGPU,
|
||||
kKirinNPU,
|
||||
kAscend910,
|
||||
kAscend310,
|
||||
|
@ -91,14 +90,6 @@ class MS_API CPUDeviceInfo : public DeviceInfoContext {
|
|||
bool GetEnableFP16() const;
|
||||
};
|
||||
|
||||
class MS_API MaliGPUDeviceInfo : public DeviceInfoContext {
|
||||
public:
|
||||
enum DeviceType GetDeviceType() const override { return DeviceType::kMaliGPU; };
|
||||
|
||||
void SetEnableFP16(bool is_fp16);
|
||||
bool GetEnableFP16() const;
|
||||
};
|
||||
|
||||
class MS_API KirinNPUDeviceInfo : public DeviceInfoContext {
|
||||
public:
|
||||
enum DeviceType GetDeviceType() const override { return DeviceType::kKirinNPU; };
|
||||
|
@ -107,15 +98,18 @@ class MS_API KirinNPUDeviceInfo : public DeviceInfoContext {
|
|||
int GetFrequency() const;
|
||||
};
|
||||
|
||||
class MS_API NvidiaGPUDeviceInfo : public DeviceInfoContext {
|
||||
class MS_API GPUDeviceInfo : public DeviceInfoContext {
|
||||
public:
|
||||
enum DeviceType GetDeviceType() const override { return DeviceType::kNvidiaGPU; };
|
||||
enum DeviceType GetDeviceType() const override { return DeviceType::kGPU; };
|
||||
|
||||
void SetDeviceID(uint32_t device_id);
|
||||
uint32_t GetDeviceID() const;
|
||||
|
||||
void SetGpuTrtInferMode(bool gpu_trt_infer_mode);
|
||||
bool GetGpuTrtInferMode() const;
|
||||
|
||||
void SetEnableFP16(bool is_fp16);
|
||||
bool GetEnableFP16() const;
|
||||
};
|
||||
|
||||
class MS_API Ascend910DeviceInfo : public DeviceInfoContext {
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
namespace mindspore {
|
||||
constexpr auto kModelOptionCpuEnableFP16 = "mindspore.option.cpu.enable_fp16";
|
||||
constexpr auto kModelOptionMaliGpuEnableFP16 = "mindspore.option.mali_gpu.enable_fp16";
|
||||
constexpr auto kModelOptionGPUEnableFP16 = "mindspore.option.gpu.enable_fp16";
|
||||
constexpr auto kModelOptionKirinNpuFrequency = "mindspore.option.kirin_npu.frequency";
|
||||
constexpr auto kModelOptionProvider = "mindspore.option.provider";
|
||||
constexpr auto kModelOptionProviderDevice = "mindspore.option.provider.device";
|
||||
|
@ -211,19 +211,19 @@ bool CPUDeviceInfo::GetEnableFP16() const {
|
|||
return GetValue<bool>(data_, kModelOptionCpuEnableFP16);
|
||||
}
|
||||
|
||||
void MaliGPUDeviceInfo::SetEnableFP16(bool is_fp16) {
|
||||
void GPUDeviceInfo::SetEnableFP16(bool is_fp16) {
|
||||
if (data_ == nullptr) {
|
||||
MS_LOG(ERROR) << "Invalid context.";
|
||||
return;
|
||||
}
|
||||
data_->params[kModelOptionMaliGpuEnableFP16] = is_fp16;
|
||||
data_->params[kModelOptionGPUEnableFP16] = is_fp16;
|
||||
}
|
||||
bool MaliGPUDeviceInfo::GetEnableFP16() const {
|
||||
bool GPUDeviceInfo::GetEnableFP16() const {
|
||||
if (data_ == nullptr) {
|
||||
MS_LOG(ERROR) << "Invalid context.";
|
||||
return false;
|
||||
}
|
||||
return GetValue<bool>(data_, kModelOptionMaliGpuEnableFP16);
|
||||
return GetValue<bool>(data_, kModelOptionGPUEnableFP16);
|
||||
}
|
||||
|
||||
void KirinNPUDeviceInfo::SetFrequency(int frequency) {
|
||||
|
@ -241,14 +241,14 @@ int KirinNPUDeviceInfo::GetFrequency() const {
|
|||
return GetValue<int>(data_, kModelOptionKirinNpuFrequency);
|
||||
}
|
||||
|
||||
void NvidiaGPUDeviceInfo::SetDeviceID(uint32_t device_id) { MS_LOG(ERROR) << "Unsupported Feature."; }
|
||||
uint32_t NvidiaGPUDeviceInfo::GetDeviceID() const {
|
||||
void GPUDeviceInfo::SetDeviceID(uint32_t device_id) { MS_LOG(ERROR) << "Unsupported Feature."; }
|
||||
uint32_t GPUDeviceInfo::GetDeviceID() const {
|
||||
MS_LOG(ERROR) << "Unsupported Feature.";
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NvidiaGPUDeviceInfo::SetGpuTrtInferMode(bool gpu_trt_infer_mode) { MS_LOG(ERROR) << "Unsupported Feature."; }
|
||||
bool NvidiaGPUDeviceInfo::GetGpuTrtInferMode() const {
|
||||
void GPUDeviceInfo::SetGpuTrtInferMode(bool gpu_trt_infer_mode) { MS_LOG(ERROR) << "Unsupported Feature."; }
|
||||
bool GPUDeviceInfo::GetGpuTrtInferMode() const {
|
||||
MS_LOG(ERROR) << "Unsupported Feature.";
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -68,8 +68,8 @@ Status A2L_ConvertContext(Context *a_context, lite::Context *l_context) {
|
|||
cpu_context->GetProviderDevice(), cpu_context->GetAllocator()});
|
||||
if (device_list.size() == 2) {
|
||||
lite::DeviceInfo device_info = {0};
|
||||
if (device_list[1]->GetDeviceType() == kMaliGPU) {
|
||||
auto gpu_context = device_list[1]->Cast<MaliGPUDeviceInfo>();
|
||||
if (device_list[1]->GetDeviceType() == kGPU) {
|
||||
auto gpu_context = device_list[1]->Cast<GPUDeviceInfo>();
|
||||
device_info.gpu_device_info_ = {gpu_context->GetEnableFP16()};
|
||||
l_context->device_list_.push_back({lite::DT_GPU, device_info, gpu_context->GetProvider(),
|
||||
gpu_context->GetProviderDevice(), gpu_context->GetAllocator()});
|
||||
|
|
|
@ -25,37 +25,32 @@ class TestCxxApiContext : public UT::Common {
|
|||
|
||||
TEST_F(TestCxxApiContext, test_context_device_info_cast_SUCCESS) {
|
||||
std::shared_ptr<DeviceInfoContext> cpu = std::make_shared<CPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> mali_gpu = std::make_shared<MaliGPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> gpu = std::make_shared<GPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> kirin_npu = std::make_shared<KirinNPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> nvidia_gpu = std::make_shared<NvidiaGPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> ascend310 = std::make_shared<Ascend310DeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> ascend910 = std::make_shared<Ascend910DeviceInfo>();
|
||||
|
||||
ASSERT_TRUE(cpu->Cast<CPUDeviceInfo>() != nullptr);
|
||||
ASSERT_TRUE(mali_gpu->Cast<MaliGPUDeviceInfo>() != nullptr);
|
||||
ASSERT_TRUE(gpu->Cast<GPUDeviceInfo>() != nullptr);
|
||||
ASSERT_TRUE(kirin_npu->Cast<KirinNPUDeviceInfo>() != nullptr);
|
||||
ASSERT_TRUE(nvidia_gpu->Cast<NvidiaGPUDeviceInfo>() != nullptr);
|
||||
ASSERT_TRUE(ascend310->Cast<Ascend310DeviceInfo>() != nullptr);
|
||||
ASSERT_TRUE(ascend910->Cast<Ascend910DeviceInfo>() != nullptr);
|
||||
}
|
||||
|
||||
TEST_F(TestCxxApiContext, test_context_device_info_cast_FAILED) {
|
||||
std::shared_ptr<DeviceInfoContext> cpu = std::make_shared<CPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> mali_gpu = std::make_shared<MaliGPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> gpu = std::make_shared<GPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> kirin_npu = std::make_shared<KirinNPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> nvidia_gpu = std::make_shared<NvidiaGPUDeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> ascend310 = std::make_shared<Ascend310DeviceInfo>();
|
||||
std::shared_ptr<DeviceInfoContext> ascend910 = std::make_shared<Ascend910DeviceInfo>();
|
||||
|
||||
ASSERT_TRUE(cpu->Cast<MaliGPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(kirin_npu->Cast<MaliGPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(nvidia_gpu->Cast<MaliGPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(ascend310->Cast<MaliGPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(ascend910->Cast<MaliGPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(cpu->Cast<GPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(kirin_npu->Cast<GPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(ascend310->Cast<GPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(ascend910->Cast<GPUDeviceInfo>() == nullptr);
|
||||
|
||||
ASSERT_TRUE(mali_gpu->Cast<CPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(gpu->Cast<CPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(kirin_npu->Cast<CPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(nvidia_gpu->Cast<CPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(ascend310->Cast<CPUDeviceInfo>() == nullptr);
|
||||
ASSERT_TRUE(ascend910->Cast<CPUDeviceInfo>() == nullptr);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue