Skip to content

Commit

Permalink
NPUW Deref: fix clang format in the code which will make it to merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dmatveev committed Nov 27, 2024
1 parent 970fb64 commit ab8d1b9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/plugins/intel_npu/src/plugin/npuw/compiled_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ void ov::npuw::CompiledModel::detach_memory() {
auto& comp_model_desc = m_compiled_submodels[idx];
auto& proto_comp_model_desc = m_compiled_submodels[comp_model_desc.replaced_by.value_or(idx)];
if (!proto_comp_model_desc.model || !proto_comp_model_desc.compiled_model) {
continue; // optimized-out OR already cleared - skip
continue; // optimized-out OR already cleared - skip
}
if (proto_comp_model_desc.device_it + 1 == m_dev_list.end()) {
LOG_INFO("No fallback expected - clear the OV model for Subgraph[" << idx << "]");
Expand Down
28 changes: 17 additions & 11 deletions src/plugins/intel_npu/src/plugin/npuw/lazy_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ struct Const {
std::shared_ptr<ov::op::v0::Constant> m_node;
ov::element::Type m_cached_type;
ov::Shape m_cached_shape;
const void *m_cached_ptr = nullptr;
const void* m_cached_ptr = nullptr;

explicit Const(std::shared_ptr<ov::op::v0::Constant> n)
: m_node(n) {
explicit Const(std::shared_ptr<ov::op::v0::Constant> n) : m_node(n) {
m_cached_type = m_node->get_element_type();
m_cached_shape = m_node->get_shape();
m_cached_ptr = m_node->get_data_ptr();
Expand All @@ -39,8 +38,7 @@ struct Const {
return seed;
}
bool operator==(const Const& other) const {
return (m_cached_type == other.m_cached_type &&
m_cached_shape == other.m_cached_shape &&
return (m_cached_type == other.m_cached_type && m_cached_shape == other.m_cached_shape &&
m_cached_ptr == other.m_cached_ptr);
}
ov::Tensor eval() const {
Expand Down Expand Up @@ -73,7 +71,7 @@ struct Concat {
return ov::npuw::util::concat(to_concat, axis);
}
void detach() {
for (auto &&lt : tensors) {
for (auto&& lt : tensors) {
lt.detach();
}
}
Expand Down Expand Up @@ -196,9 +194,11 @@ template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

LazyTensorImpl::LazyTensorImpl(Transform&& t)
: m_transform(std::move(t))
, m_hash(std::visit(overloaded{[](const auto& op) { return op.hash(); }}, m_transform)) {
}
: m_transform(std::move(t)),
m_hash(std::visit(overloaded{[](const auto& op) {
return op.hash();
}},
m_transform)) {}

bool LazyTensorImpl::operator==(const LazyTensorImpl& other) const {
return m_hash == other.m_hash && m_transform == other.m_transform;
Expand All @@ -214,15 +214,21 @@ ov::Tensor LazyTensorImpl::eval() const {
some kind of indicator that the only difference is concat and we should look for an existing ov::Tensor.
Perhaps it should be done after model compilation and not handled here.
*/
return std::visit(overloaded{[](const auto& op) { return op.eval(); }}, m_transform);
return std::visit(overloaded{[](const auto& op) {
return op.eval();
}},
m_transform);
}

std::size_t LazyTensorImpl::get_hash() const {
return m_hash;
}

void LazyTensorImpl::detach() {
std::visit(overloaded{[](auto& op) { op.detach(); }}, m_transform);
std::visit(overloaded{[](auto& op) {
op.detach();
}},
m_transform);
}

LazyTensor::LazyTensor(const std::shared_ptr<ov::op::v0::Constant>& const_ptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ Group::Group(size_t gid,
: m_nh(std::move(nh)),
m_id(gid),
m_graph(g),
m_snapshot(snapshot) {
}
m_snapshot(snapshot) {}

// Include Parameters, Outputs, Converts, etc to content's layers for proper linking at the plugin level
void Group::includeExtraLayers(detail::OVNodeSet& input_layers,
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/intel_npu/src/plugin/npuw/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ Impl<M> _(std::shared_ptr<M> pM) {
} // namespace at

// Written here to be a drop-in replacement for ov::parallel_for for the debug purposes
template<typename F>
void non_parallel_for(std::size_t count, F &&f) {
template <typename F>
void non_parallel_for(std::size_t count, F&& f) {
for (std::size_t idx = 0u; idx < count; idx++) {
f(idx);
}
Expand Down
6 changes: 4 additions & 2 deletions src/plugins/intel_npu/src/plugin/npuw/weights_bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ void Bank::evaluate_and_allocate() {
}
}

ov::Tensor Bank::eval_and_alloc(const LazyTensor& tensor, Bank::DeviceBank &dbank, const std::string& device_for_alloc) {
ov::Tensor Bank::eval_and_alloc(const LazyTensor& tensor,
Bank::DeviceBank& dbank,
const std::string& device_for_alloc) {
// Evaluate concurrently (see evaluate_and_allocate), lock the device
// mutex only to update the device bank (& allocate on-device memory, if needed)
const auto& transformed_tensor = tensor.eval();
Expand All @@ -116,7 +118,7 @@ ov::Tensor Bank::eval_and_alloc(const LazyTensor& tensor, Bank::DeviceBank &dban
remote_ctx->create_host_tensor(transformed_tensor.get_element_type(), transformed_tensor.get_shape());
allocated_tensor = ov::make_tensor(remote_tensor);
dbank.storage[tensor] = allocated_tensor;
guard.unlock(); // Unlock the guard, map update is done - copy can continue in parallel
guard.unlock(); // Unlock the guard, map update is done - copy can continue in parallel

transformed_tensor.copy_to(allocated_tensor);
return allocated_tensor;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/intel_npu/src/plugin/npuw/weights_bank.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Bank {
};
std::unordered_map<std::string, DeviceBank> m_device_banks;

ov::Tensor eval_and_alloc(const LazyTensor& tensor, DeviceBank &dbank, const std::string& device);
ov::Tensor eval_and_alloc(const LazyTensor& tensor, DeviceBank& dbank, const std::string& device);

std::mutex m_mutex;
std::shared_ptr<const ov::ICore> m_core = nullptr;
Expand Down

0 comments on commit ab8d1b9

Please sign in to comment.