| 711 | } |
| 712 | |
| 713 | template <typename T> std::string Engine<T>::serializeEngineOptions(const Options &options, const std::string &onnxModelPath) { |
| 714 | const auto filenamePos = onnxModelPath.find_last_of('/') + 1; |
| 715 | std::string engineName = onnxModelPath.substr(filenamePos, onnxModelPath.find_last_of('.') - filenamePos) + ".engine"; |
| 716 | |
| 717 | // Add the GPU device name to the file to ensure that the model is only used |
| 718 | // on devices with the exact same GPU |
| 719 | std::vector<std::string> deviceNames; |
| 720 | getDeviceNames(deviceNames); |
| 721 | |
| 722 | if (static_cast<size_t>(options.deviceIndex) >= deviceNames.size()) { |
| 723 | throw std::runtime_error("Error, provided device index is out of range!"); |
| 724 | } |
| 725 | |
| 726 | auto deviceName = deviceNames[options.deviceIndex]; |
| 727 | // Remove spaces from the device name |
| 728 | deviceName.erase(std::remove_if(deviceName.begin(), deviceName.end(), ::isspace), deviceName.end()); |
| 729 | |
| 730 | engineName += "." + deviceName; |
| 731 | |
| 732 | // Serialize the specified options into the filename |
| 733 | if (options.precision == Precision::FP16) { |
| 734 | engineName += ".fp16"; |
| 735 | } else if (options.precision == Precision::FP32) { |
| 736 | engineName += ".fp32"; |
| 737 | } else { |
| 738 | engineName += ".int8"; |
| 739 | } |
| 740 | |
| 741 | engineName += "." + std::to_string(options.maxBatchSize); |
| 742 | engineName += "." + std::to_string(options.optBatchSize); |
| 743 | |
| 744 | return engineName; |
| 745 | } |
| 746 | |
| 747 | template <typename T> void Engine<T>::getDeviceNames(std::vector<std::string> &deviceNames) { |
| 748 | int numGPUs; |
nothing calls this directly
no outgoing calls
no test coverage detected