From 23b449a9e7f72411fdee26f6bd16eb61a02fab2b Mon Sep 17 00:00:00 2001 From: Hyeongseok Oh Date: Thu, 19 Dec 2024 10:22:25 +0900 Subject: [PATCH] [onert] Remove libs/profiling (#14469) This commit removes libs/profiling. It is not used anymore. ONE-DCO-1.0-Signed-off-by: Hyeongseok Oh --- runtime/libs/profiling/CMakeLists.txt | 6 - .../include/profiling/profile_buffer.h | 170 --------------- .../profiling/include/profiling/profiler.h | 203 ------------------ .../profiling/include/profiling/profiling.h | 57 ----- .../libs/profiling/include/profiling/time.h | 37 ---- runtime/libs/profiling/src/profiling/time.cpp | 57 ----- 6 files changed, 530 deletions(-) delete mode 100644 runtime/libs/profiling/CMakeLists.txt delete mode 100644 runtime/libs/profiling/include/profiling/profile_buffer.h delete mode 100644 runtime/libs/profiling/include/profiling/profiler.h delete mode 100644 runtime/libs/profiling/include/profiling/profiling.h delete mode 100644 runtime/libs/profiling/include/profiling/time.h delete mode 100644 runtime/libs/profiling/src/profiling/time.cpp diff --git a/runtime/libs/profiling/CMakeLists.txt b/runtime/libs/profiling/CMakeLists.txt deleted file mode 100644 index b115cc1c655..00000000000 --- a/runtime/libs/profiling/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -file(GLOB_RECURSE SOURCES "src/*.cpp") - -add_library(nnfw_lib_profiling STATIC ${SOURCES}) -set_property(TARGET nnfw_lib_profiling PROPERTY POSITION_INDEPENDENT_CODE ON) -target_include_directories(nnfw_lib_profiling PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_link_libraries(nnfw_lib_profiling PRIVATE nnfw_common) diff --git a/runtime/libs/profiling/include/profiling/profile_buffer.h b/runtime/libs/profiling/include/profiling/profile_buffer.h deleted file mode 100644 index bc8d75e7cef..00000000000 --- a/runtime/libs/profiling/include/profiling/profile_buffer.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -// NOTE To minimize diff with upstream tensorflow, disable clang-format -// clang-format off - -// NOTE This header is derived from the following file (in TensorFlow v1.12) -// 'externals/tensorflow/tensorflow/lite/profiling/profile_buffer.h -#ifndef TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILE_BUFFER_H_ -#define TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILE_BUFFER_H_ - -#include -#include - -#include "profiling/time.h" - -namespace tflite { -namespace profiling { - -// A profiling event. -struct ProfileEvent { - // Describes the type of event. - // The event_metadata field may contain additional data for interpreting - // the event. - enum class EventType { - // Default event type, the metadata field has no special significance. - DEFAULT = 0, - // The event is an operator invocation and the event_metadata field is the - // index of operator node. - OPERATOR_INVOKE_EVENT = 1 - }; - - // Label of the event. This usually describes the event. - const char* tag; - // Timestamp in microseconds when the event began. - uint64_t begin_timestamp_us; - // Timestamp in microseconds when the event ended. - uint64_t end_timestamp_us; - // The field containing the type of event. This must be one of the event types - // in EventType. - EventType event_type; - // Extra data describing the details of the event. - uint32_t event_metadata; -}; -} // namespace profiling -} // namespace tflite - -#ifdef TFLITE_PROFILING_ENABLED - -#include -#include - -namespace tflite { -namespace profiling { -constexpr uint32_t kInvalidEventHandle = static_cast(~0) - 1; - -// A ring buffer of profile events. -// This class is not thread safe. -class ProfileBuffer { - public: - ProfileBuffer(uint32_t max_num_entries, bool enabled) - : enabled_(enabled), current_index_(0), event_buffer_(max_num_entries) {} - - // Adds an event to the buffer with begin timestamp set to the current - // timestamp. Returns a handle to event that can be used to call EndEvent. If - // buffer is disabled this has no affect. - // The tag of the event should remain valid till the buffer is valid. - uint32_t BeginEvent(const char* tag, ProfileEvent::EventType event_type, - uint32_t event_metadata) { - if (!enabled_) { - return kInvalidEventHandle; - } - uint64_t timestamp = time::NowMicros(); - int index = current_index_ % event_buffer_.size(); - event_buffer_[index].tag = tag; - event_buffer_[index].event_type = event_type; - event_buffer_[index].event_metadata = event_metadata; - event_buffer_[index].begin_timestamp_us = timestamp; - event_buffer_[index].end_timestamp_us = 0; - current_index_++; - return index; - } - - // Sets the enabled state of buffer to |enabled| - void SetEnabled(bool enabled) { enabled_ = enabled; } - - // Sets the end timestamp for event for the handle to current time. - // If the buffer is disabled or previous event has been overwritten this - // operation has not effect. - void EndEvent(uint32_t event_handle) { - if (!enabled_ || event_handle == kInvalidEventHandle || - event_handle > current_index_) { - return; - } - const uint32_t max_size = event_buffer_.size(); - if (current_index_ > (max_size + event_handle)) { - // Ignore, buffer has already overflowed. - return; - } - - int event_index = event_handle % max_size; - event_buffer_[event_index].end_timestamp_us = time::NowMicros(); - } - - // Returns the size of the buffer. - size_t Size() const { - return (current_index_ >= event_buffer_.size()) ? event_buffer_.size() - : current_index_; - } - - // Resets the buffer. - void Reset() { - enabled_ = false; - current_index_ = 0; - } - - // Returns the profile event at the given index. If the index is invalid a - // nullptr is returned. The return event may get overwritten if more events - // are added to buffer. - const struct ProfileEvent* const At(int index) const { - size_t size = Size(); - if (index >= size) { - return nullptr; - } - const uint32_t max_size = event_buffer_.size(); - uint32_t start = - (current_index_ > max_size) ? current_index_ % max_size : max_size; - index = (index + start) % max_size; - return &event_buffer_[index]; - } - - private: - bool enabled_; - uint32_t current_index_; - std::vector event_buffer_; -}; -} // namespace profiling -} // namespace tflite -#endif // TFLITE_PROFILING_ENABLED -#endif // TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILE_BUFFER_H_ - -// clang-format on diff --git a/runtime/libs/profiling/include/profiling/profiler.h b/runtime/libs/profiling/include/profiling/profiler.h deleted file mode 100644 index ed36881401a..00000000000 --- a/runtime/libs/profiling/include/profiling/profiler.h +++ /dev/null @@ -1,203 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -==============================================================================*/ - -// NOTE To minimize diff with upstream tensorflow, disable clang-format -// clang-format off - -// NOTE This header is derived from the following file (in TensorFlow v1.12) -// 'externals/tensorflow/tensorflow/lite/profiling/profiler.h -#ifndef TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILER_H_ -#define TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILER_H_ - -#include - -#include "profiling/profile_buffer.h" - -#ifdef TFLITE_PROFILING_ENABLED - -namespace tflite { -namespace profiling { -class ScopedProfile; -class ScopedOperatorProfile; - -// Controls whether profiling is enabled or disabled and collects profiles. -// TFLite is used on platforms that don't have posix threads, so the profiler is -// kept as simple as possible. It is designed to be used only on a single -// thread. -// -// Profiles are collected using Scoped*Profile objects that begin and end a -// profile event. -// An example usage is shown in the example below: -// -// Say Worker class has a DoWork method and we are interested in profiling -// the overall execution time for DoWork and time spent in Task1 and Task2 -// functions. -// -// class Worker { -// public: -// void DoWork() { -// ScopedProfile(&controller, "DoWork"); -// Task1(); -// Task2(); -// ..... -// } -// -// void Task1() { -// ScopedProfile(&controller, "Task1"); -// .... -// } -// -// void Task2() { -// ScopedProfile(&controller, "Task2"); -// } -// -// Profiler profiler; -// } -// -// We instrument the functions that need to be profiled. -// -// Profile can be collected by enable profiling and then getting profile -// events. -// -// void ProfileWorker() { -// Worker worker; -// worker.profiler.EnableProfiling(); -// worker.DoWork(); -// worker.profiler.DisableProfiling(); -// // Profiling is complete, extract profiles. -// auto profile_events = worker.profiler.GetProfiles(); -// } -// -// -class Profiler { - public: - Profiler() : buffer_(1024, false) {} - - void StartProfiling() { buffer_.SetEnabled(true); } - void StopProfiling() { buffer_.SetEnabled(false); } - void Reset() { buffer_.Reset(); } - std::vector GetProfileEvents() { - std::vector profile_events; - profile_events.reserve(buffer_.Size()); - for (size_t i = 0; i < buffer_.Size(); i++) { - profile_events.push_back(buffer_.At(i)); - } - return profile_events; - } - - private: - friend class ScopedProfile; - friend class ScopedOperatorProfile; - ProfileBuffer* GetProfileBuffer() { return &buffer_; } - ProfileBuffer buffer_; -}; - -class ScopedProfile { - public: - // Adds a profile event to profile that begins with the construction - // of object and ends when the object goes out of scope. - // The lifetime of tag should be at least the lifetime of profiler. - - ScopedProfile(Profiler* profiler, const char* tag) - : buffer_(nullptr), event_handle_(0) { - if (profiler) { - buffer_ = profiler->GetProfileBuffer(); - event_handle_ = - buffer_->BeginEvent(tag, ProfileEvent::EventType::DEFAULT, 0); - } - } - ~ScopedProfile() { - if (buffer_) { - buffer_->EndEvent(event_handle_); - } - } - - private: - ProfileBuffer* buffer_; - int32_t event_handle_; -}; - -class ScopedOperatorProfile { - public: - // Adds a profile event to profile that begins with the construction - // of object and ends when the object goes out of scope. - // The lifetime of tag should be at least the lifetime of profiler. - ScopedOperatorProfile(Profiler* profiler, const char* tag, int node_index) - : buffer_(nullptr), event_handle_(0) { - if (profiler) { - buffer_ = profiler->GetProfileBuffer(); - event_handle_ = buffer_->BeginEvent( - tag, ProfileEvent::EventType::OPERATOR_INVOKE_EVENT, node_index); - } - } - - ~ScopedOperatorProfile() { - if (buffer_) { - buffer_->EndEvent(event_handle_); - } - } - - private: - ProfileBuffer* buffer_; - int32_t event_handle_; -}; - -} // namespace profiling -} // namespace tflite - -#define VARNAME_UNIQ(name, ctr) name##ctr - -#define SCOPED_OPERATOR_PROFILE(profiler, node_index) \ - tflite::profiling::ScopedOperatorProfile VARNAME_UNIQ( \ - _profile_, __COUNTER__)((profiler), "OpInvoke", (node_index)) -#else - -namespace tflite { -namespace profiling { -// A noop version of profiler when profiling is disabled. -class Profiler { - public: - Profiler() {} - void StartProfiling() {} - void StopProfiling() {} - void Reset() {} - std::vector GetProfileEvents() { return {}; } -}; -} // namespace profiling -} // namespace tflite - -#define SCOPED_OPERATOR_PROFILE(profiler, node_index) - -#endif // TFLITE_PROFILING_ENABLED - -#endif // TENSORFLOW_CONTRIB_LITE_PROFILING_PROFILER_H_ - -// clang-format on diff --git a/runtime/libs/profiling/include/profiling/profiling.h b/runtime/libs/profiling/include/profiling/profiling.h deleted file mode 100644 index 79ad060c584..00000000000 --- a/runtime/libs/profiling/include/profiling/profiling.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __NNFW_MISC_PROFILING_H__ -#define __NNFW_MISC_PROFILING_H__ - -#include - -namespace tflite -{ -namespace profiling -{ -class Profiler; // forward declaration -} -} // namespace tflite - -namespace profiling -{ - -class Context -{ -public: - Context() : _sync(false), _profiler(nullptr) {} - -public: - const bool &sync(void) const { return _sync; } - tflite::profiling::Profiler *getProfiler() { return _profiler; } - void setProfiler(tflite::profiling::Profiler *p) { _profiler = p; } - void setSync(void) { _sync = true; } - -private: - bool _sync; - tflite::profiling::Profiler *_profiler; - -public: - static Context &get(void) - { - static Context ctx{}; - return ctx; - } -}; - -} // namespace profiling -#endif // __NNFW_MISC_PROFILING_H__ diff --git a/runtime/libs/profiling/include/profiling/time.h b/runtime/libs/profiling/include/profiling/time.h deleted file mode 100644 index 03d18ddc8e0..00000000000 --- a/runtime/libs/profiling/include/profiling/time.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * Copyright 2018 The TensorFlow Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// NOTE To minimize diff with upstream tensorflow, disable clang-format -// clang-format off - -// NOTE This header is derived from the following file (in TensorFlow v1.12) -// 'externals/tensorflow/tensorflow/lite/profiling/time.h -#ifndef TENSORFLOW_CONTRIB_LITE_PROFILING_TIME_H_ -#define TENSORFLOW_CONTRIB_LITE_PROFILING_TIME_H_ - -#include - -namespace tflite { -namespace profiling { -namespace time { -uint64_t NowMicros(); -} // namespace time -} // namespace profiling -} // namespace tflite -#endif // TENSORFLOW_CONTRIB_LITE_PROFILING_TIME_H_ - -// clang-format on diff --git a/runtime/libs/profiling/src/profiling/time.cpp b/runtime/libs/profiling/src/profiling/time.cpp deleted file mode 100644 index 5f6f6657e25..00000000000 --- a/runtime/libs/profiling/src/profiling/time.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved - * Copyright 2018 The TensorFlow Authors. All Rights Reserved. - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// NOTE To minimize diff with upstream tensorflow, disable clang-format -// clang-format off - -// NOTE This header is derived from the following file (in TensorFlow v1.12) -// 'externals/tensorflow/tensorflow/lite/profiling/time.cpp -#include "profiling/time.h" - -#if defined(_MSC_VER) -#include // NOLINT(build/c++11) -#else -#include -#endif - -namespace tflite { -namespace profiling { -namespace time { - -#if defined(_MSC_VER) - -uint64_t NowMicros() { - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) - .count(); -} - -#else - -uint64_t NowMicros() { - struct timespec ts; - clock_gettime(CLOCK_MONOTONIC, &ts); - return static_cast(ts.tv_nsec) / 1e3 + static_cast(ts.tv_sec) * 1e6; -} - -#endif // defined(_MSC_VER) - -} // namespace time -} // namespace profiling -} // namespace tflite - -// clang-format on