Skip to content

Commit

Permalink
[cker/ruy] Introduce EXPERIMENTAL_RUY_FEATURE build option (Samsung#3446
Browse files Browse the repository at this point in the history
)

Introduce EXPERIMENTAL_RUY_FEATURE build option. For now, deallocating
prepack cached const backend tensors has not been matured. (Samsung#3225)
Because of the internal issue, however, the feature is needed on some
target. To do it, enable it when EXPERIMENTAL_RUY_FEATURE is set.

ONE-DCO-1.0-Signed-off-by: Yongseop Kim <[email protected]>
  • Loading branch information
YongseopKim authored Jul 27, 2020
1 parent 6ad24e9 commit f69a113
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 3 additions & 0 deletions compute/cker/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ target_link_libraries(nnfw_lib_cker INTERFACE gemmlowp)
target_link_libraries(nnfw_lib_cker INTERFACE ruy)
target_link_libraries(nnfw_lib_cker INTERFACE ruy_instrumentation)
target_compile_definitions(nnfw_lib_cker INTERFACE USE_RUY_GEMV)
if(EXPERIMENTAL_RUY_FEATURE)
target_compile_definitions(nnfw_lib_cker INTERFACE EXPERIMENTAL_RUY_FEATURE)
endif(EXPERIMENTAL_RUY_FEATURE)
if(PROFILE_RUY)
target_link_libraries(nnfw_lib_cker INTERFACE ruy_profiler)
endif(PROFILE_RUY)
Expand Down
25 changes: 22 additions & 3 deletions runtime/onert/backend/cpu/ops/FullyConnectedLayer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -113,23 +113,40 @@ void FullyConnectedLayer::fullyConnectedHybrid()
getTensorShape(_bias), reinterpret_cast<const float *>(_bias ? _bias->buffer() : nullptr),
getTensorShape(_output), reinterpret_cast<float *>(_output->buffer()), temp_arena);

// TODO Enable calling decrease_ref
#if 0
// TODO Remove this ifdef
#ifdef EXPERIMENTAL_RUY_FEATURE
if (_cached_weights == nullptr || _is_weights_freed)
return;

// '_cached_weights is not nullptr and _is_weights_freed is false' means
// this weight shape is satisfied with the ruy kernel's prepack cache's condition.
// After entering here, it will not enter again except below the case - input is zero-vector

// if input's elements are filled with zero, it by-passes(does not enter ruy-kernel path)
// so that handle this case
const int input_size = getTensorShape(_input).FlatSize();
if (nnfw::cker::IsZeroVector(reinterpret_cast<float *>(_input->buffer()), input_size))
return;

// This weight tensor could be other ops' const tensor.
// Therefore, below reference should be checked like following
auto weight_tensor = dynamic_cast<const Tensor *>(_weights);
if (weight_tensor)
{
auto tensor = const_cast<Tensor *>(weight_tensor);
if (tensor->buffer() == nullptr) // ref is already 0?
{
_is_weights_freed = true;
return;
}

tensor->decrease_ref();
if (tensor->buffer() == nullptr) // ref == 0?
{
_is_weights_freed = true;
}
}
#endif // if 0
#endif
#endif
}

Expand Down Expand Up @@ -178,6 +195,7 @@ void FullyConnectedLayer::prepare()
}

#ifdef USE_RUY_GEMV
#ifdef EXPERIMENTAL_RUY_FEATURE
// TODO This is workaround
// The only fc hybrid will use ruy kernel
if (_input->data_type() != OperandType::FLOAT32 ||
Expand Down Expand Up @@ -209,6 +227,7 @@ void FullyConnectedLayer::prepare()
}
}
#endif
#endif
}

} // namespace ops
Expand Down
1 change: 1 addition & 0 deletions runtime/onert/backend/cpu/ops/FullyConnectedLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class FullyConnectedLayer : public ::onert::exec::IFunction

#ifdef USE_RUY_GEMV
uint8_t *_cached_weights = nullptr; // weights to be cached and a key
bool _is_weights_freed = false; // is weights freed?
#endif
};

Expand Down

0 comments on commit f69a113

Please sign in to comment.