| 49 | } |
| 50 | |
| 51 | Status ModelConfigFactory::Create(const char* model_config, ModelConfig** config) { |
| 52 | if (strlen(model_config) <= 0) { |
| 53 | return Status(error::Code::INVALID_ARGUMENT, |
| 54 | "[TensorFlow] Invalid ModelConfig json."); |
| 55 | } |
| 56 | |
| 57 | // Enable INFERENCE_MODE by default |
| 58 | if (setenv("INFERENCE_MODE", "1", 1) != 0) { |
| 59 | LOG(WARNING) << "Set env INFERENCE_MODE=1 error."; |
| 60 | } |
| 61 | |
| 62 | Json::Reader reader; |
| 63 | Json::Value json_config; |
| 64 | if (!reader.parse(model_config, json_config)) { |
| 65 | return Status(error::Code::INVALID_ARGUMENT, |
| 66 | "[TensorFlow] Parse ModelConfig json failed."); |
| 67 | } |
| 68 | |
| 69 | int64 schedule_threads; |
| 70 | ReadInt64FromEnvVar("SCHEDULABLE_CPUS", DEFAULT_CPUS, &schedule_threads); |
| 71 | |
| 72 | *config = new ModelConfig; |
| 73 | |
| 74 | // User set session group cpuset, |
| 75 | // Usage: "0-10;11-20;21-30" or |
| 76 | // "0,1,2,3;4,5,6,7;8,9,10" |
| 77 | if (!json_config["cpusets"].isNull()) { |
| 78 | (*config)->cpusets = |
| 79 | json_config["cpusets"].asString(); |
| 80 | } |
| 81 | |
| 82 | if (!json_config["session_num"].isNull()) { |
| 83 | (*config)->session_num = |
| 84 | json_config["session_num"].asInt(); |
| 85 | } else { |
| 86 | (*config)->session_num = 1; |
| 87 | } |
| 88 | |
| 89 | if (!json_config["gpu_ids_list"].isNull()) { |
| 90 | std::string gpu_ids_list = |
| 91 | json_config["gpu_ids_list"].asString(); |
| 92 | ParseGPUIds(gpu_ids_list, &((*config)->gpu_ids)); |
| 93 | } |
| 94 | |
| 95 | bool use_multi_stream = false; |
| 96 | if (!json_config["use_multi_stream"].isNull()) { |
| 97 | use_multi_stream = json_config["use_multi_stream"].asBool(); |
| 98 | } |
| 99 | (*config)->use_multi_stream = use_multi_stream; |
| 100 | |
| 101 | (*config)->select_session_policy = "MOD"; |
| 102 | if (!json_config["select_session_policy"].isNull()) { |
| 103 | (*config)->select_session_policy = |
| 104 | json_config["select_session_policy"].asString(); |
| 105 | } |
| 106 | if ((*config)->select_session_policy != "MOD" && |
| 107 | (*config)->select_session_policy != "RR") { |
| 108 | return Status(error::Code::INVALID_ARGUMENT, |
no test coverage detected