Project import generated by Copybara.

GitOrigin-RevId: 4419aaa472eeb91123d1f8576188166ee0e5ea69
This commit is contained in:
MediaPipe Team
2020-03-10 18:14:25 -07:00
committed by jqtang
parent 252a5713c7
commit 3b6d3c4058
104 changed files with 7441 additions and 88 deletions
+15 -5
View File
@@ -105,17 +105,27 @@ GpuBuffer GpuBufferMultiPool::GetBuffer(int width, int height,
BufferSpec key(width, height, format);
auto pool_it = pools_.find(key);
if (pool_it == pools_.end()) {
// Discard the oldest pool in order of creation.
// TODO: implement a better policy.
// Discard the least recently used pool in LRU cache.
if (pools_.size() >= kMaxPoolCount) {
auto old_spec = buffer_specs_.front();
buffer_specs_.pop();
auto old_spec = buffer_specs_.front(); // Front has LRU.
buffer_specs_.pop_front();
pools_.erase(old_spec);
}
buffer_specs_.push(key);
buffer_specs_.push_back(key); // Push new spec to back.
std::tie(pool_it, std::ignore) =
pools_.emplace(std::piecewise_construct, std::forward_as_tuple(key),
std::forward_as_tuple(MakeSimplePool(key)));
} else {
// Find and move current 'key' spec to back, keeping others in same order.
auto specs_it = buffer_specs_.begin();
while (specs_it != buffer_specs_.end()) {
if (*specs_it == key) {
buffer_specs_.erase(specs_it);
break;
}
++specs_it;
}
buffer_specs_.push_back(key);
}
return GetBufferFromSimplePool(pool_it->first, pool_it->second);
}
+2 -2
View File
@@ -22,8 +22,8 @@
#ifndef MEDIAPIPE_GPU_GPU_BUFFER_MULTI_POOL_H_
#define MEDIAPIPE_GPU_GPU_BUFFER_MULTI_POOL_H_
#include <deque>
#include <limits>
#include <queue>
#include <unordered_map>
#include "absl/synchronization/mutex.h"
@@ -110,7 +110,7 @@ class GpuBufferMultiPool {
ABSL_GUARDED_BY(mutex_);
// A queue of BufferSpecs to keep track of the age of each BufferSpec added to
// the pool.
std::queue<BufferSpec> buffer_specs_;
std::deque<BufferSpec> buffer_specs_;
#ifdef __APPLE__
// Texture caches used with this pool.
+19 -6
View File
@@ -73,13 +73,15 @@ def _metal_compiler_args(ctx, src, obj, minimum_os_version, copts, diagnostics,
def _metal_compiler_inputs(srcs, hdrs, deps = []):
"""Determines the list of inputs required for a compile action."""
objc_providers = [x.objc for x in deps if hasattr(x, "objc")]
objc_files = depset()
for objc in objc_providers:
objc_files += objc.header
cc_infos = [dep[CcInfo] for dep in deps if CcInfo in dep]
return srcs + hdrs + objc_files.to_list()
dep_headers = depset(transitive = [
cc_info.compilation_context.headers
for cc_info in cc_infos
])
return depset(srcs + hdrs, transitive = [dep_headers])
def _metal_library_impl(ctx):
"""Implementation for metal_library Skylark rule."""
@@ -144,11 +146,22 @@ def _metal_library_impl(ctx):
**additional_params
)
cc_infos = [dep[CcInfo] for dep in ctx.attr.deps if CcInfo in dep]
if ctx.files.hdrs:
cc_infos.append(
CcInfo(
compilation_context = cc_common.create_compilation_context(
headers = depset([f for f in ctx.files.hdrs]),
),
),
)
return [
DefaultInfo(
files = depset([output_lib]),
),
objc_provider,
cc_common.merge_cc_infos(cc_infos = cc_infos),
# Return the provider for the new bundling logic of rules_apple.
resources.bucketize_typed([output_lib], "unprocessed"),
]
@@ -156,7 +169,7 @@ def _metal_library_impl(ctx):
METAL_LIBRARY_ATTRS = dicts.add(apple_support.action_required_attrs(), {
"srcs": attr.label_list(allow_files = [".metal"], allow_empty = False),
"hdrs": attr.label_list(allow_files = [".h"]),
"deps": attr.label_list(providers = [["objc"]]),
"deps": attr.label_list(providers = [["objc", CcInfo]]),
"copts": attr.string_list(),
"minimum_os_version": attr.string(),
})