File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -373,9 +373,15 @@ InferRequest::GetResponseSender()
373373std::shared_ptr<InferResponse>
374374InferRequest::Exec (const bool is_decoupled)
375375{
376+ // BLS should not be used in "initialize" or "finalize" function.
377+ std::unique_ptr<Stub>& stub = Stub::GetOrCreateInstance ();
378+ if (!stub->IsInitialized () || stub->IsFinalizing ()) {
379+ throw PythonBackendException (
380+ " BLS is only supported during the 'execute' function." );
381+ }
382+
376383 ResponseBatch* response_batch = nullptr ;
377384 bool responses_is_set = false ;
378- std::unique_ptr<Stub>& stub = Stub::GetOrCreateInstance ();
379385 std::unique_ptr<SharedMemoryManager>& shm_pool = stub->SharedMemory ();
380386 bi::managed_external_buffer::handle_t * response_handle = nullptr ;
381387
@@ -529,8 +535,7 @@ InferRequest::Exec(const bool is_decoupled)
529535
530536 for (auto & output_tensor : error_response->OutputTensors ()) {
531537 if (!output_tensor->IsCPU ()) {
532- uint64_t memory_release_id =
533- output_tensor->Memory ()->MemoryReleaseId ();
538+ uint64_t memory_release_id = output_tensor->Memory ()->MemoryReleaseId ();
534539 output_tensor->Memory ()->SetMemoryReleaseCallback (
535540 [&memory_manager_message_queue, memory_release_id]() {
536541 memory_manager_message_queue->Push (memory_release_id);
Original file line number Diff line number Diff line change @@ -84,6 +84,7 @@ Stub::Instantiate(
8484 name_ = name;
8585 health_mutex_ = nullptr ;
8686 initialized_ = false ;
87+ finalizing_ = false ;
8788 stub_to_parent_thread_ = false ;
8889 parent_to_stub_thread_ = false ;
8990
@@ -799,6 +800,7 @@ Stub::UpdateHealth()
799800void
800801Stub::Finalize ()
801802{
803+ finalizing_ = true ;
802804 // Call finalize if exists.
803805 if (initialized_ && py::hasattr (model_instance_, " finalize" )) {
804806 try {
@@ -1120,6 +1122,18 @@ Stub::SaveResponseIterator(std::shared_ptr<ResponseIterator> response_iterator)
11201122 response_iterator->Id (), response_iterator));
11211123}
11221124
1125+ bool
1126+ Stub::IsInitialized ()
1127+ {
1128+ return initialized_;
1129+ }
1130+
1131+ bool
1132+ Stub::IsFinalizing ()
1133+ {
1134+ return finalizing_;
1135+ }
1136+
11231137std::unique_ptr<Logger> Logger::log_instance_;
11241138
11251139std::unique_ptr<Logger>&
Original file line number Diff line number Diff line change @@ -256,6 +256,12 @@ class Stub {
256256 // / Add cleanup id to queue
257257 void EnqueueCleanupId (void * id);
258258
259+ // / Is the stub initialized
260+ bool IsInitialized ();
261+
262+ // / Is the stub in the finalize stage
263+ bool IsFinalizing ();
264+
259265
260266 private:
261267 bi::interprocess_mutex* stub_mutex_;
@@ -282,6 +288,7 @@ class Stub {
282288 parent_to_stub_mq_;
283289 std::unique_ptr<MessageQueue<uint64_t >> memory_manager_message_queue_;
284290 bool initialized_;
291+ bool finalizing_;
285292 static std::unique_ptr<Stub> stub_instance_;
286293 std::vector<std::shared_ptr<PbTensor>> gpu_tensors_;
287294 std::queue<std::unique_ptr<PbLog>> log_request_buffer_;
You can’t perform that action at this time.
0 commit comments