Skip to content

Commit

Permalink
Avoids the creation of two "default" GpuExecutor instances
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 703430623
  • Loading branch information
MediaPipe Team authored and copybara-github committed Dec 6, 2024
1 parent 29e87ad commit 5fbb13d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
23 changes: 19 additions & 4 deletions mediapipe/gpu/gpu_shared_data_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@

namespace mediapipe {

namespace {

inline constexpr char kGpuExecutorName[] = "__gpu";

// Returns the executor name from a context key .
std::string GetExecutorNameFromContextKey(const std::string& context_key) {
return absl::StrCat(kGpuExecutorName, "_", context_key);
}

} // namespace

#if __APPLE__
static constexpr bool kGlContextUseDedicatedThread = false;
#elif defined(__EMSCRIPTEN__)
Expand Down Expand Up @@ -130,7 +141,9 @@ GpuResources::GpuResources(std::shared_ptr<GlContext> gl_context,
#endif // MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
{
gl_key_context_->insert({SharedContextKey(), gl_context});
named_executors_[kGpuExecutorName] =
const std::string executor_name =
GetExecutorNameFromContextKey(SharedContextKey());
named_executors_[executor_name] =
std::make_shared<GlContextExecutor>(gl_context.get());
#if __APPLE__
#if MEDIAPIPE_GPU_BUFFER_USE_CV_PIXEL_BUFFER
Expand All @@ -144,7 +157,9 @@ GpuResources::GpuResources(std::shared_ptr<GlContext> gl_context,

absl::StatusOr<std::shared_ptr<Executor>> GpuResources::GetDefaultGpuExecutor()
const {
const auto it = named_executors_.find(kGpuExecutorName);
const std::string executor_name =
GetExecutorNameFromContextKey(SharedContextKey());
const auto it = named_executors_.find(executor_name);
RET_CHECK(it != named_executors_.end()) << "Can't find default gpu executor.";
return it->second;
}
Expand Down Expand Up @@ -209,8 +224,8 @@ absl::Status GpuResources::PrepareGpuNode(CalculatorNode* node) {
GetOrCreateGlContext(context_key));

if (kGlContextUseDedicatedThread) {
std::string executor_name =
absl::StrCat(kGpuExecutorName, "_", context_key);
const std::string executor_name =
GetExecutorNameFromContextKey(context_key);
node->SetExecutor(executor_name);
if (!ContainsKey(named_executors_, executor_name)) {
named_executors_.emplace(
Expand Down
1 change: 0 additions & 1 deletion mediapipe/gpu/graph_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace mediapipe {

inline constexpr char kGpuSharedTagName[] = "GPU_SHARED";
inline constexpr char kGpuSharedSidePacketName[] = "gpu_shared";
inline constexpr char kGpuExecutorName[] = "__gpu";

} // namespace mediapipe

Expand Down

0 comments on commit 5fbb13d

Please sign in to comment.