Skip to content

Commit

Permalink
add clang-format-precommit (#59)
Browse files Browse the repository at this point in the history
* clang-format-precommit

* update
  • Loading branch information
Yancey1989 authored Jan 5, 2022
1 parent a8632ed commit 5586ea8
Show file tree
Hide file tree
Showing 82 changed files with 515 additions and 444 deletions.
4 changes: 4 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Run manually to reformat a file:
# clang-format -i --style=file <file>
BasedOnStyle: Google
DerivePointerAlignment: false
8 changes: 7 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@ repos:
name: copyright_checker
entry: python ./scripts/pre-commit/copyright.py
language: system
files: \.(cc|cpp|h|py|sh)$
files: \.(cc|cpp|h|py|sh)$
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v10.0.1
hooks:
- id: clang-format
name: clang-format

1 change: 0 additions & 1 deletion mhlo_builder/mlir/mhlo/builder/mlir_shape_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include "mlir/mhlo/builder/mlir_shape_builder.h"

#include "mlir-hlo/Dialect/mhlo/IR/hlo_ops.h"
Expand Down
1 change: 0 additions & 1 deletion mhlo_builder/mlir/mhlo/builder/mlir_type_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include "mlir/mhlo/builder/mlir_type_utils.h"

#include "mlir-hlo/Dialect/mhlo/IR/hlo_ops.h"
Expand Down
1 change: 0 additions & 1 deletion mhlo_builder/mlir/mhlo/builder/slice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include "mlir-hlo/Dialect/mhlo/IR/hlo_ops.h"
#include "mlir/Dialect/StandardOps/IR/Ops.h"
#include "mlir/mhlo/builder/mlir_shape_builder.h"
Expand Down
1 change: 0 additions & 1 deletion mhlo_builder/mlir/mhlo/builder/standard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include "mlir/mhlo/builder/standard.h"

#include "mlir-hlo/Dialect/mhlo/IR/hlo_ops.h"
Expand Down
3 changes: 1 addition & 2 deletions pytorch_blade/src/common_utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

#include "c10/util/Logging.h"

#define DLOG(...) \
#define DLOG(...) \
if (std::getenv("TORCH_BLADE_DEBUG_LOG") != nullptr) \
LOG(__VA_ARGS__)

#define LOG_ASSERT(condition) FATAL_IF(condition)

19 changes: 9 additions & 10 deletions pytorch_blade/src/common_utils/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
void operator=(const TypeName&) = delete;

#define TorchBladeDeclNewFlag(T, Name) \
T Set##Name(T); \
T Set##Name(T); \
T& Get##Name();

#define TorchBladeDefNewFlag(T, Name) \
T& Get##Name() { \
thread_local T flag; \
return flag; \
} \
T Set##Name(T flag) { \
T old_flag = Get##Name(); \
Get##Name() = flag; \
return old_flag; \
T& Get##Name() { \
thread_local T flag; \
return flag; \
} \
T Set##Name(T flag) { \
T old_flag = Get##Name(); \
Get##Name() = flag; \
return old_flag; \
}

1 change: 0 additions & 1 deletion pytorch_blade/src/compiler/jit/torch/alias_analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include "alias_analysis.h"

namespace torch {
Expand Down
1 change: 0 additions & 1 deletion pytorch_blade/src/compiler/jit/torch/alias_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ bool isMutableType(const torch::jit::TypePtr& type);
bool isMutableType(const torch::jit::Value* v);
} // namespace blade
} // namespace torch

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include <mlir-hlo/Dialect/mhlo/IR/hlo_ops.h> // from tf repo
#include <mlir/Dialect/StandardOps/IR/Ops.h> // from tf repo
#include <mlir/mhlo/builder/broadcast.h>
Expand Down
1 change: 0 additions & 1 deletion pytorch_blade/src/compiler/mlir/converters/impl/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include "compiler/mlir/converters/impl/utils.h"

#include "common_utils/logging.h"
Expand Down
1 change: 0 additions & 1 deletion pytorch_blade/src/compiler/mlir/runtime/ral_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,3 @@ class RalContext {

} // namespace blade
} // namespace torch

1 change: 0 additions & 1 deletion pytorch_blade/src/pybind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.


#include "pybind.h"

#include <mutex>
Expand Down
3 changes: 1 addition & 2 deletions tao/tao_bridge/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
#ifndef TAO_TAO_BRIDGE_ERRORS_H_
#define TAO_TAO_BRIDGE_ERRORS_H_

#include "tensorflow/core/lib/core/status.h"
#include "tensorflow/core/platform/default/logging.h"
#include "tensorflow/stream_executor/lib/statusor.h"
#include "tensorflow/core/lib/core/status.h"


namespace tensorflow {
namespace tao {
Expand Down
89 changes: 36 additions & 53 deletions tao/tao_bridge/executable.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,9 @@ struct OutputDescription {

OutputType type = kDefault;

bool is_constant() {
return type == kConstant;
}
bool is_resource() {
return type == kResource;
}
bool is_default() {
return type == kDefault;
}
bool is_constant() { return type == kConstant; }
bool is_resource() { return type == kResource; }
bool is_default() { return type == kDefault; }

tensorflow::TensorShape shape;
tensorflow::Tensor constant_value;
Expand All @@ -90,9 +84,7 @@ struct ConstantDescription {
// Manage all buffers used during computation
struct BufferAllocations {
using Index = BufferAllocation::Index;
Index num_allocations() const {
return allocations.size();
}
Index num_allocations() const { return allocations.size(); }
Index num_parameters() const {
return allocation_id_to_parameter_index.size();
}
Expand Down Expand Up @@ -136,8 +128,9 @@ struct BufferAllocations {
}

se::DeviceMemoryBase GetDeviceAddress(const BufferSlice& slice) const {
return se::DeviceMemoryBase(static_cast<char*>(
allocations.at(slice.id).ptr) + slice.offset, slice.size);
return se::DeviceMemoryBase(
static_cast<char*>(allocations.at(slice.id).ptr) + slice.offset,
slice.size);
}

void clear_buffers() {
Expand All @@ -164,9 +157,7 @@ struct BufferAllocations {
struct ProfileState {
int64 execution_time_in_us = -1;

bool is_valid() {
return execution_time_in_us > 0;
}
bool is_valid() { return execution_time_in_us > 0; }
};

class ExecutableRunOptions {
Expand All @@ -175,26 +166,19 @@ class ExecutableRunOptions {
ctx_ = ctx;
return *this;
}
OpKernelContext* ctx() const {
return ctx_;
}
OpKernelContext* ctx() const { return ctx_; }

ExecutableRunOptions& set_num_constant_args(int num) {
num_constant_args_ = num;
return *this;
}
int num_constant_args() const {
return num_constant_args_;
}
int num_constant_args() const { return num_constant_args_; }

ExecutableRunOptions& set_variables(
std::map<int, OptionalTensor> variables) {
ExecutableRunOptions& set_variables(std::map<int, OptionalTensor> variables) {
variables_ = std::move(variables);
return *this;
}
const std::map<int, OptionalTensor>& variables() const {
return variables_;
}
const std::map<int, OptionalTensor>& variables() const { return variables_; }

ExecutableRunOptions& set_profile_state(ProfileState* state) {
profile_state_ = state;
Expand All @@ -220,9 +204,7 @@ class Executable {
// 2, Parse TaoCompilerResult and prepare to run
virtual Status Init();

std::string compiled_result_file() const {
return compiled_result_file_;
}
std::string compiled_result_file() const { return compiled_result_file_; }

virtual void DumpToFile(const std::string& filename) const;

Expand All @@ -243,8 +225,12 @@ class Executable {
BufferAllocations& allocations,
std::vector<Tensor>& output_tensors);

virtual Status StartProfiler(const ExecutableRunOptions& options) { return Status::OK(); }
virtual Status StopProfiler(const ExecutableRunOptions& options) { return Status::OK(); }
virtual Status StartProfiler(const ExecutableRunOptions& options) {
return Status::OK();
}
virtual Status StopProfiler(const ExecutableRunOptions& options) {
return Status::OK();
}

const TaoCompilerResult& tao_compiler_result() const {
CHECK(compiled_result_.get() != nullptr);
Expand All @@ -256,18 +242,14 @@ class Executable {
return *compiled_result_;
}

RalTfContext* ral_context() {
return ral_ctx_.get();
}
RalTfContext* ral_context() { return ral_ctx_.get(); }

std::unique_ptr<RalTfContext>& mutable_ral_context() { return ral_ctx_; }

BufferAllocations& buffers() { return buffers_; }
const BufferAllocations& buffers() const { return buffers_; }

std::vector<Tensor>& output_tensors() {
return output_tensors_;
}
std::vector<Tensor>& output_tensors() { return output_tensors_; }
std::unique_ptr<TaoCompilerResult> compiled_result_;

private:
Expand All @@ -286,36 +268,37 @@ class ExecutableFactory {
public:
using ExecutableConstructor =
std::function<std::unique_ptr<Executable>(const std::string&)>;
std::unique_ptr<Executable> NewExecutable(
const std::string& device_type, const std::string& proto_file);
std::unique_ptr<Executable> NewExecutable(const std::string& device_type,
const std::string& proto_file);
static ExecutableFactory& Global();
bool RegisterExecutable(
const std::string& device_type, ExecutableConstructor);
bool RegisterExecutable(const std::string& device_type,
ExecutableConstructor);

private:
ExecutableFactory() = default;
std::unordered_map<std::string, ExecutableConstructor> constructors_;
};

struct Executableregistrar {
using ExecutableConstructor = ExecutableFactory::ExecutableConstructor;
Executableregistrar(
const std::string& device_type, ExecutableConstructor ctor) {
ExecutableFactory::Global().RegisterExecutable(
device_type, ctor);
Executableregistrar(const std::string& device_type,
ExecutableConstructor ctor) {
ExecutableFactory::Global().RegisterExecutable(device_type, ctor);
}
};

#define TAO_REGISTER_EXECUTABLE(device, ctor) \
TAO_REGISTER_EXECUTABLE_IMPL(device, ctor, __COUNTER__)
TAO_REGISTER_EXECUTABLE_IMPL(device, ctor, __COUNTER__)

#define TAO_REGISTER_EXECUTABLE_IMPL(device, ctor, ctr) \
Executableregistrar INTERNAL_REGISTER_TAO_EXECUBALE_NAME(ctr) TF_ATTRIBUTE_UNUSED (device, ctor)
#define TAO_REGISTER_EXECUTABLE_IMPL(device, ctor, ctr) \
Executableregistrar INTERNAL_REGISTER_TAO_EXECUBALE_NAME(ctr) \
TF_ATTRIBUTE_UNUSED(device, ctor)

// __COUNTER__ must go through another macro to be properly expanded
#define INTERNAL_REGISTER_TAO_EXECUBALE_NAME(ctr) ___##ctr##__object_

} // namespace tao
} // namespace tao

} // namespace tensorflow
} // namespace tensorflow

#endif // TAO_TAO_BRIDGE_EXECUTABLE_H_
#endif // TAO_TAO_BRIDGE_EXECUTABLE_H_
1 change: 1 addition & 0 deletions tao/tao_bridge/kernels/tao_profiling_guided_compilation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "tao_bridge/kernels/tao_profiling_guided_compilation.h"

#include <sys/time.h>

#include "tensorflow/core/util/env_var.h"

namespace tensorflow {
Expand Down
2 changes: 1 addition & 1 deletion tao/tao_bridge/ops/tao_ops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ REGISTER_OP("DiscLaunch")
DiscLaunchOp using DISC as the backend.)");
#endif

} // namespace tensorflow
} // namespace tensorflow
1 change: 1 addition & 0 deletions tao/tao_bridge/passes/defunctionalize_control_flow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// limitations under the License.

#include "tao_bridge/passes/defunctionalize_control_flow.h"

#include "tao_bridge/tf/lower_if_op.h"
#include "tao_bridge/tf/lower_while_op.h"
#include "tensorflow/core/framework/function.h"
Expand Down
1 change: 1 addition & 0 deletions tao/tao_bridge/passes/functionalize_cond.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
#define TAO_TAO_BRIDGE_PASSES_FUNCTIONALIZE_COND_H_

#include <deque>

#include "tao_bridge/common.h"
#include "tao_bridge/tf/statusor.h"
#include "tensorflow/core/framework/function.h"
Expand Down
2 changes: 1 addition & 1 deletion tao/tao_bridge/passes/tao_bace_reformat_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Status TaoBaCEReformatPass::Run(const GraphOptimizationPassOptions& options) {
AttrValue new_value;
auto* new_tensor_proto = new_value.mutable_tensor();
new_tensor_proto->set_version_number(tensor_proto.version_number());
if(!tensor_proto.tensor_content().empty()) {
if (!tensor_proto.tensor_content().empty()) {
new_const.AsProtoTensorContent(new_tensor_proto);
} else {
new_const.AsProtoField(new_tensor_proto);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
#define TENSORFLOW_COMPILER_JIT_CLONE_CONSTANTS_FOR_BETTER_CLUSTERING_H_

#include <unordered_set>

#include "tao_bridge/passes/tao_optimization_pass.h"
#include "tensorflow/core/common_runtime/optimization_registry.h"
#include "tensorflow/core/lib/core/status.h"
Expand Down
12 changes: 6 additions & 6 deletions tao/tao_bridge/passes/tao_encapsulate_subgraphs_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2381,12 +2381,12 @@ Status Encapsulator::MakePrunedGraphCopyAndInline(
std::unique_ptr<FunctionBody> fbody;
#endif

TF_RETURN_IF_ERROR(
FunctionDefToBodyHelper(*fdef, node->attrs(), library,
[library](const string& op, const OpDef** sig) {
return library->LookUpOpDef(op, sig);
},
&fbody));
TF_RETURN_IF_ERROR(FunctionDefToBodyHelper(
*fdef, node->attrs(), library,
[library](const string& op, const OpDef** sig) {
return library->LookUpOpDef(op, sig);
},
&fbody));

#if defined TF_1_12
InlineFunctionBody(*library, pruned_graph->get(), node, fbody, {});
Expand Down
Loading

0 comments on commit 5586ea8

Please sign in to comment.