Skip to content

Commit

Permalink
refactor(*): adopt clang-format target
Browse files Browse the repository at this point in the history
  • Loading branch information
lzx1413 committed Sep 16, 2023
1 parent cf59fd3 commit ec8f741
Show file tree
Hide file tree
Showing 26 changed files with 114 additions and 77 deletions.
5 changes: 1 addition & 4 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
---
BasedOnStyle: Google
---
Language: Cpp
Cpp11BracedListStyle: true
Standard: Cpp11
Expand Down Expand Up @@ -32,5 +30,4 @@ IncludeCategories:
Priority: 7
# The rest
- Regex: '.*'
Priority: 5
---
Priority: 5
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ add_definitions(-D_USE_MATH_DEFINES)
add_definitions(-DNOMINMAX)
set(CMAKE_CXX_STANDARD 20)
endif()
include(${PROJECT_SOURCE_DIR}/cmake/clang_format.cmake)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS " C++ flags (Release):" ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE})
Expand Down
9 changes: 9 additions & 0 deletions cmake/clang_format.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function(add_clang_format_target target_name)
find_program(${PROJECT_NAME}_CLANG_FORMAT_BINARY clang-format)
get_target_property(TARGET_SOURCES ${target_name} SOURCES)
add_custom_target(clang-format
COMMAND ${${PROJECT_NAME}_CLANG_FORMAT_BINARY}
-i ${TARGET_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR})
message(STATUS "Format the project using the `clang-format` target (i.e: cmake --build build --target clang-format).\n")
endfunction()
3 changes: 3 additions & 0 deletions mediapipe/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ add_library(framework )
add_subdirectory(formats)
add_subdirectory(tool)
target_link_libraries(framework PUBLIC graph stb::stb opencv::opencv_core_alias opencv::opencv_highgui_alias opencv::opencv_imgproc_alias opencv::opencv_videoio_alias gpu util)
add_clang_format_target(framework)
else()
add_clang_format_target(graph)
endif()
install(
TARGETS
Expand Down
3 changes: 2 additions & 1 deletion mediapipe/framework/calculator_contract.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/port/status_builder.h"
#include "mediapipe/framework/port/status_macros.h"
#include "mediapipe/framework/tool/packet_generator_wrapper_calculator.pb.h"
#include "mediapipe/framework/tool/tag_map.h"

#include "mediapipe/framework/tool/packet_generator_wrapper_calculator.pb.h"

namespace mediapipe {

namespace {
Expand Down
13 changes: 7 additions & 6 deletions mediapipe/framework/calculator_graph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "absl/synchronization/mutex.h"
#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/calculator_base.h"
#include "mediapipe/framework/counter_factory.h"
#include "mediapipe/framework/delegating_executor.h"
#include "mediapipe/framework/graph_service_manager.h"
#include "mediapipe/framework/input_stream_manager.h"
#include "mediapipe/framework/mediapipe_profiling.h"
#include "mediapipe/framework/packet_generator.h"
#include "mediapipe/framework/packet_generator.pb.h"
#include "mediapipe/framework/packet_set.h"
#include "mediapipe/framework/packet_type.h"
#include "mediapipe/framework/port.h"
Expand All @@ -53,9 +51,7 @@
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/port/status_builder.h"
#include "mediapipe/framework/status_handler.h"
#include "mediapipe/framework/status_handler.pb.h"
#include "mediapipe/framework/thread_pool_executor.h"
#include "mediapipe/framework/thread_pool_executor.pb.h"
#include "mediapipe/framework/tool/fill_packet_set.h"
#include "mediapipe/framework/tool/status_util.h"
#include "mediapipe/framework/tool/tag_map.h"
Expand All @@ -64,6 +60,11 @@
#include "mediapipe/framework/validated_graph_config.h"
#include "mediapipe/gpu/graph_support.h"
#include "mediapipe/util/cpu_util.h"

#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/packet_generator.pb.h"
#include "mediapipe/framework/status_handler.pb.h"
#include "mediapipe/framework/thread_pool_executor.pb.h"
#if !MEDIAPIPE_DISABLE_GPU
#include "mediapipe/gpu/gpu_shared_data_internal.h"
#endif // !MEDIAPIPE_DISABLE_GPU
Expand Down Expand Up @@ -1233,12 +1234,12 @@ bool CalculatorGraph::UnthrottleSources() {
}
int new_size = stream->QueueSize() + 1;
stream->SetMaxQueueSize(new_size);
#if !defined(_MSC_VER)
#if !defined(_MSC_VER)
LOG_EVERY_N(WARNING, 100)
<< "Resolved a deadlock by increasing max_queue_size of input stream: "
<< stream->Name() << " to: " << new_size
<< ". Consider increasing max_queue_size for better performance.";
#endif
#endif
}
return !full_streams.empty();
}
Expand Down
3 changes: 2 additions & 1 deletion mediapipe/framework/calculator_node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "absl/strings/string_view.h"
#include "absl/strings/substitute.h"
#include "absl/synchronization/mutex.h"
#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/calculator_base.h"
#include "mediapipe/framework/counter_factory.h"
#include "mediapipe/framework/input_stream_manager.h"
Expand All @@ -47,6 +46,8 @@
#include "mediapipe/framework/tool/tag_map.h"
#include "mediapipe/framework/tool/validate_name.h"

#include "mediapipe/framework/calculator.pb.h"

namespace mediapipe {

namespace {
Expand Down
3 changes: 2 additions & 1 deletion mediapipe/framework/formats/image_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@
#include <utility>

#include "absl/strings/str_cat.h"
#include "mediapipe/framework/formats/image_format.pb.h"
#include "mediapipe/framework/port/aligned_malloc_and_free.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/proto_ns.h"

#include "mediapipe/framework/formats/image_format.pb.h"

namespace mediapipe {

namespace {
Expand Down
3 changes: 2 additions & 1 deletion mediapipe/framework/formats/image_opencv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

#include "mediapipe/framework/formats/image_opencv.h"

#include "mediapipe/framework/formats/image_format.pb.h"
#include "mediapipe/framework/port/logging.h"

#include "mediapipe/framework/formats/image_format.pb.h"

namespace {
// Maps Image format to OpenCV Mat type.
// See mediapipe...image_format.proto and cv...opencv2/core/hal/interface.h
Expand Down
5 changes: 3 additions & 2 deletions mediapipe/framework/formats/location.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

#include "absl/memory/memory.h"
#include "absl/strings/substitute.h"
#include "mediapipe/framework/formats/annotation/locus.pb.h"
#include "mediapipe/framework/formats/annotation/rasterization.pb.h"
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/integral_types.h"
#include "mediapipe/framework/port/logging.h"
Expand All @@ -32,6 +30,9 @@
#include "mediapipe/framework/tool/status_util.h"
#include "mediapipe/framework/type_map.h"

#include "mediapipe/framework/formats/annotation/locus.pb.h"
#include "mediapipe/framework/formats/annotation/rasterization.pb.h"

namespace mediapipe {

namespace {
Expand Down
3 changes: 2 additions & 1 deletion mediapipe/framework/formats/location_opencv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@

#include "absl/memory/memory.h"
#include "absl/strings/substitute.h"
#include "mediapipe/framework/formats/annotation/rasterization.pb.h"
#include "mediapipe/framework/formats/location.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/opencv_imgproc_inc.h"
#include "mediapipe/framework/port/statusor.h"

#include "mediapipe/framework/formats/annotation/rasterization.pb.h"

namespace mediapipe {

namespace {
Expand Down
60 changes: 30 additions & 30 deletions mediapipe/framework/formats/tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -552,36 +552,36 @@ Tensor::CpuReadView Tensor::GetCpuReadView() const {
} else
#endif // MEDIAPIPE_OPENGL_ES_VERSION >= MEDIAPIPE_OPENGL_ES_31

// Transfer data from texture if not transferred from SSBO/MTLBuffer
// yet.
if (valid_ & kValidOpenGlTexture2d) {
gl_context_->Run([this]() {
const int padded_size =
texture_height_ * texture_width_ * 4 * element_size();
auto temp_buffer = absl::make_unique<uint8_t[]>(padded_size);
uint8_t* buffer = temp_buffer.get();

glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer_);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, opengl_texture2d_, 0);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
glReadPixels(0, 0, texture_width_, texture_height_, GL_RGBA, GL_FLOAT,
buffer);
uint8_t* dest_buffer = reinterpret_cast<uint8_t*>(cpu_buffer_);
const int actual_depth_size =
BhwcDepthFromShape(shape_) * element_size();
const int num_slices = (BhwcDepthFromShape(shape_) + 3) / 4;
const int padded_depth_size = num_slices * 4 * element_size();
const int num_elements = BhwcWidthFromShape(shape_) *
BhwcHeightFromShape(shape_) *
BhwcBatchFromShape(shape_);
for (int e = 0; e < num_elements; e++) {
std::memcpy(dest_buffer, buffer, actual_depth_size);
dest_buffer += actual_depth_size;
buffer += padded_depth_size;
}
});
}
// Transfer data from texture if not transferred from SSBO/MTLBuffer
// yet.
if (valid_ & kValidOpenGlTexture2d) {
gl_context_->Run([this]() {
const int padded_size =
texture_height_ * texture_width_ * 4 * element_size();
auto temp_buffer = absl::make_unique<uint8_t[]>(padded_size);
uint8_t* buffer = temp_buffer.get();

glBindFramebuffer(GL_FRAMEBUFFER, frame_buffer_);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D, opengl_texture2d_, 0);
glPixelStorei(GL_PACK_ALIGNMENT, 4);
glReadPixels(0, 0, texture_width_, texture_height_, GL_RGBA, GL_FLOAT,
buffer);
uint8_t* dest_buffer = reinterpret_cast<uint8_t*>(cpu_buffer_);
const int actual_depth_size =
BhwcDepthFromShape(shape_) * element_size();
const int num_slices = (BhwcDepthFromShape(shape_) + 3) / 4;
const int padded_depth_size = num_slices * 4 * element_size();
const int num_elements = BhwcWidthFromShape(shape_) *
BhwcHeightFromShape(shape_) *
BhwcBatchFromShape(shape_);
for (int e = 0; e < num_elements; e++) {
std::memcpy(dest_buffer, buffer, actual_depth_size);
dest_buffer += actual_depth_size;
buffer += padded_depth_size;
}
});
}
#endif // MEDIAPIPE_OPENGL_ES_VERSION >= MEDIAPIPE_OPENGL_ES_30
valid_ |= kValidCpu;
}
Expand Down
3 changes: 2 additions & 1 deletion mediapipe/framework/thread_pool_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/status_builder.h"
#include "mediapipe/framework/thread_pool_executor.pb.h"
#include "mediapipe/util/cpu_util.h"

#include "mediapipe/framework/thread_pool_executor.pb.h"

namespace mediapipe {

// static
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "mediapipe/framework/calculator_registry.h"
#include "mediapipe/framework/output_side_packet.h"
#include "mediapipe/framework/packet_generator.h"

#include "mediapipe/framework/tool/packet_generator_wrapper_calculator.pb.h"

namespace mediapipe {
Expand Down
3 changes: 2 additions & 1 deletion mediapipe/framework/tool/proto_util_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/tool/field_data.pb.h"
#include "mediapipe/framework/type_map.h"

#include "mediapipe/framework/tool/field_data.pb.h"

#define RET_CHECK_NO_LOG(cond) RET_CHECK(cond).SetNoLogging()

namespace mediapipe {
Expand Down
1 change: 1 addition & 0 deletions mediapipe/framework/tool/source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "mediapipe/framework/calculator_framework.h"
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/status.h"

#include "mediapipe/framework/tool/source.pb.h"

namespace mediapipe {
Expand Down
5 changes: 3 additions & 2 deletions mediapipe/framework/tool/subgraph_expansion.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,20 @@
#include "absl/memory/memory.h"
#include "absl/strings/str_cat.h"
#include "mediapipe/framework/graph_service_manager.h"
#include "mediapipe/framework/packet_generator.pb.h"
#include "mediapipe/framework/port.h"
#include "mediapipe/framework/port/core_proto_inc.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/map_util.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/status_builder.h"
#include "mediapipe/framework/port/status_macros.h"
#include "mediapipe/framework/status_handler.pb.h"
#include "mediapipe/framework/subgraph.h"
#include "mediapipe/framework/tool/name_util.h"
#include "mediapipe/framework/tool/tag_map.h"

#include "mediapipe/framework/packet_generator.pb.h"
#include "mediapipe/framework/status_handler.pb.h"

namespace mediapipe {

namespace tool {
Expand Down
5 changes: 3 additions & 2 deletions mediapipe/framework/tool/switch_container.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@
#include <vector>

#include "absl/strings/str_cat.h"
#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/calculator_framework.h"
#include "mediapipe/framework/calculator_options.pb.h"
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/tool/container_util.h"
#include "mediapipe/framework/tool/name_util.h"
#include "mediapipe/framework/tool/subgraph_expansion.h"

#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/calculator_options.pb.h"
#include "mediapipe/framework/tool/switch_container.pb.h"

namespace mediapipe {
Expand Down
1 change: 1 addition & 0 deletions mediapipe/framework/tool/switch_demux_calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/port/status_macros.h"
#include "mediapipe/framework/tool/container_util.h"

#include "mediapipe/framework/tool/switch_container.pb.h"

namespace mediapipe {
Expand Down
1 change: 1 addition & 0 deletions mediapipe/framework/tool/switch_mux_calculator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/port/status_macros.h"
#include "mediapipe/framework/tool/container_util.h"

#include "mediapipe/framework/tool/switch_container.pb.h"

namespace mediapipe {
Expand Down
5 changes: 3 additions & 2 deletions mediapipe/framework/tool/template_expander.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
#include "absl/strings/numbers.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/numbers.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/tool/calculator_graph_template.pb.h"
#include "mediapipe/framework/tool/proto_util_lite.h"

#include "mediapipe/framework/calculator.pb.h"
#include "mediapipe/framework/tool/calculator_graph_template.pb.h"

namespace mediapipe {

namespace tool {
Expand Down
5 changes: 3 additions & 2 deletions mediapipe/framework/tool/template_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_join.h"
#include "absl/strings/str_split.h"
#include "mediapipe/framework/deps/proto_descriptor.pb.h"
#include "mediapipe/framework/port/canonical_errors.h"
#include "mediapipe/framework/port/integral_types.h"
#include "mediapipe/framework/port/logging.h"
#include "mediapipe/framework/port/map_util.h"
#include "mediapipe/framework/port/ret_check.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/tool/calculator_graph_template.pb.h"
#include "mediapipe/framework/tool/proto_util_lite.h"

#include "mediapipe/framework/deps/proto_descriptor.pb.h"
#include "mediapipe/framework/tool/calculator_graph_template.pb.h"

using mediapipe::proto_ns::Descriptor;
using mediapipe::proto_ns::DynamicMessageFactory;
using mediapipe::proto_ns::EnumDescriptor;
Expand Down
Loading

0 comments on commit ec8f741

Please sign in to comment.