-
Notifications
You must be signed in to change notification settings - Fork 762
Add ONNX Runtime backend support (OpenVINO / DirectML / TensorRT / CPU, Windows & Linux) #1222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
ff3c105
30a01b8
46d1842
4f86efa
815378d
cac464b
3e71064
2e2d772
f6767d5
c2e5552
8883c4e
9f1d598
ce8c146
e77c88d
c2cedbc
1bdb258
3a8ddf2
0909331
7b91582
895b266
22960c0
e99d4d3
f7c383b
2346f94
166a435
db0a622
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,7 +66,8 @@ NNEvaluator::NNEvaluator( | |
| bool doRandomize, | ||
| int defaultSymmetry, | ||
| bool disableWarmup_, | ||
| ConfigParser& cfg | ||
| ConfigParser& cfg, | ||
| const vector<int>& maxBatchSizeByServerThr | ||
| ) | ||
| :modelName(mName), | ||
| modelFileName(mFileName), | ||
|
|
@@ -78,6 +79,9 @@ NNEvaluator::NNEvaluator( | |
| usingFP16Mode(useFP16Mode), | ||
| numThreads(numThr), | ||
| gpuIdxByServerThread(gpuIdxByServerThr), | ||
| maxBatchSizeByServerThread( | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we're going to do per-server-thread batch sizes, please verify that this is threaded everywhere needed? For example, maybeWarmupComputeHandle uses batch sizes too and may need to be run with the same batch size as post-warmup if a backend relies on it. |
||
| maxBatchSizeByServerThr.empty() ? vector<int>(numThr, maxBatchSz) : maxBatchSizeByServerThr | ||
| ), | ||
| randSeed(rSeed), | ||
| debugSkipNeuralNet(skipNeuralNet), | ||
| disableWarmup(disableWarmup_), | ||
|
|
@@ -117,6 +121,12 @@ NNEvaluator::NNEvaluator( | |
| throw StringError("maxBatchSize is negative: " + Global::intToString(maxBatchSize)); | ||
| if(gpuIdxByServerThread.size() != numThreads) | ||
| throw StringError("gpuIdxByServerThread.size() != numThreads"); | ||
| if(maxBatchSizeByServerThread.size() != numThreads) | ||
| throw StringError("maxBatchSizeByServerThread.size() != numThreads"); | ||
| for(int threadMaxBatchSize : maxBatchSizeByServerThread) { | ||
| if(threadMaxBatchSize <= 0 || threadMaxBatchSize > maxBatchSize) | ||
| throw StringError("Invalid per-server-thread max batch size: " + Global::intToString(threadMaxBatchSize)); | ||
| } | ||
|
|
||
| if(logger != NULL) { | ||
| logger->write( | ||
|
|
@@ -382,6 +392,7 @@ void NNEvaluator::setNumThreads(const vector<int>& gpuIdxByServerThr) { | |
| throw StringError("NNEvaluator::setNumThreads called when threads were already running!"); | ||
| numThreads = (int)gpuIdxByServerThr.size(); | ||
| gpuIdxByServerThread = gpuIdxByServerThr; | ||
| maxBatchSizeByServerThread.assign(numThreads, maxBatchSize); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it a bit weird that setting the number of threads also resets all batch sizes, even for the server threads that were configured to demand a particular batch size? Might deserve at least a comment or some documentation? |
||
| } | ||
|
|
||
| void NNEvaluator::spawnServerThreads() { | ||
|
|
@@ -566,14 +577,16 @@ void NNEvaluator::serve( | |
| ) { | ||
| int64_t numBatchesHandledThisThread = 0; | ||
| int64_t numRowsHandledThisThread = 0; | ||
| testAssert(serverThreadIdx >= 0 && serverThreadIdx < (int)maxBatchSizeByServerThread.size()); | ||
| const int maxBatchSizeForThisThread = maxBatchSizeByServerThread[serverThreadIdx]; | ||
|
|
||
| ComputeHandle* gpuHandle = NULL; | ||
| if(loadedModel != NULL) { | ||
| gpuHandle = NeuralNet::createComputeHandle( | ||
| computeContext, | ||
| loadedModel, | ||
| logger, | ||
| maxBatchSize, | ||
| maxBatchSizeForThisThread, | ||
| requireExactNNLen, | ||
| inputsUseNHWC, | ||
| gpuIdxForThisThread, | ||
|
|
@@ -594,14 +607,14 @@ void NNEvaluator::serve( | |
| } | ||
|
|
||
| vector<NNResultBuf*> resultBufs; | ||
| resultBufs.reserve(maxBatchSize); | ||
| resultBufs.reserve(maxBatchSizeForThisThread); | ||
|
|
||
| vector<NNOutput*> outputBuf; | ||
|
|
||
| unique_lock<std::mutex> lock(bufferMutex,std::defer_lock); | ||
| while(true) { | ||
| resultBufs.clear(); | ||
| int desiredBatchSize = std::min(maxBatchSize, currentBatchSize.load(std::memory_order_acquire)); | ||
| int desiredBatchSize = std::min(maxBatchSizeForThisThread, currentBatchSize.load(std::memory_order_acquire)); | ||
| bool gotAnything = queryQueue.waitPopUpToN(resultBufs,desiredBatchSize); | ||
| // Queue being closed is a signal that we're done. | ||
| if(!gotAnything) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double check whether protobuf is linked in a portable way here? See TensorRT's protobuf linking for a case that required a fix for windows.