Skip to content

Commit c269d67

Browse files
authored
Add parallel model loading (#165)
* Add rate limiter read lock * Remove SharedLibrary global lock on non-Windows * Update copyright year * Add parallel model loading * Cleanup comments * Retry during parallel model load/unload conflict * Revert copyright year on unmodified file * Update on ModelInitFn and ModelInstanceInitFn SharedLibrary Win lock * Separate LockUnlockNodes to LockNodes and UnlockNodes * Group ModelInfoMap functions * Adjust dependency graph naming * Refactor parallel load logic * Add wait on cond var for conflict retry * Adjust cond var naming * Rename LoadUnloadModelsPoll to PollModels * More comment on Writeback vs Assign * Rename ConditionVariable to EventNotifier * Refactor LoadUnloadModels * Refactor conflict notify mechanism * Hide the map var inside model info map * Add log print for load/unload conflict * Init rate limiter ptr to null once declared
1 parent 02ffba6 commit c269d67

File tree

6 files changed

+676
-282
lines changed

6 files changed

+676
-282
lines changed

src/backend_model.cc

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,28 @@ TritonModel::Create(
169169

170170
TritonModel* raw_local_model = local_model.get();
171171

172-
// Model initialization is optional... The TRITONBACKEND_Model
173-
// object is this TritonModel object. We must set set shared library
174-
// path to point to the backend directory in case the backend
175-
// library attempts to load additional shared libaries.
172+
// Model initialization is optional... The TRITONBACKEND_Model object is this
173+
// TritonModel object.
176174
if (backend->ModelInitFn() != nullptr) {
175+
// We must set set shared library path to point to the backend directory in
176+
// case the backend library attempts to load additional shared libaries.
177+
// Currently, the set and reset function is effective only on Windows, so
178+
// there is no need to set path on non-Windows.
179+
// However, parallel model loading will not see any speedup on Windows and
180+
// the global lock inside the SharedLibrary is a WAR.
181+
// [FIXME] Reduce lock WAR on SharedLibrary (DLIS-4300)
182+
#ifdef _WIN32
177183
std::unique_ptr<SharedLibrary> slib;
178184
RETURN_IF_ERROR(SharedLibrary::Acquire(&slib));
179185
RETURN_IF_ERROR(slib->SetLibraryDirectory(backend->Directory()));
186+
#endif
180187

181188
TRITONSERVER_Error* err = backend->ModelInitFn()(
182189
reinterpret_cast<TRITONBACKEND_Model*>(raw_local_model));
183190

191+
#ifdef _WIN32
184192
RETURN_IF_ERROR(slib->ResetLibraryDirectory());
193+
#endif
185194
RETURN_IF_TRITONSERVER_ERROR(err);
186195
}
187196

src/backend_model_instance.cc

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2020-2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
// Copyright 2020-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
//
33
// Redistribution and use in source and binary forms, with or without
44
// modification, are permitted provided that the following conditions
@@ -326,14 +326,25 @@ TritonModelInstance::CreateInstance(
326326
// library path to point to the backend directory in case the
327327
// backend library attempts to load additional shared libaries.
328328
if (model->Backend()->ModelInstanceInitFn() != nullptr) {
329+
// We must set set shared library path to point to the backend directory in
330+
// case the backend library attempts to load additional shared libaries.
331+
// Currently, the set and reset function is effective only on Windows, so
332+
// there is no need to set path on non-Windows.
333+
// However, parallel model loading will not see any speedup on Windows and
334+
// the global lock inside the SharedLibrary is a WAR.
335+
// [FIXME] Reduce lock WAR on SharedLibrary (DLIS-4300)
336+
#ifdef _WIN32
329337
std::unique_ptr<SharedLibrary> slib;
330338
RETURN_IF_ERROR(SharedLibrary::Acquire(&slib));
331339
RETURN_IF_ERROR(slib->SetLibraryDirectory(model->Backend()->Directory()));
340+
#endif
332341

333342
TRITONSERVER_Error* err =
334343
model->Backend()->ModelInstanceInitFn()(triton_instance);
335344

345+
#ifdef _WIN32
336346
RETURN_IF_ERROR(slib->ResetLibraryDirectory());
347+
#endif
337348
RETURN_IF_TRITONSERVER_ERROR(err);
338349
}
339350

src/model.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ struct ModelIdentifier {
3838
{
3939
}
4040

41+
ModelIdentifier(const ModelIdentifier&) = default;
42+
43+
ModelIdentifier& operator=(const ModelIdentifier&) = default;
44+
4145
bool operator<(const ModelIdentifier& rhs) const
4246
{
4347
if (namespace_ == rhs.namespace_) {

0 commit comments

Comments
 (0)