Skip to content

Commit

Permalink
replace fixed_vector with small_vector and make Shape inherit from it (
Browse files Browse the repository at this point in the history
…#8365)

* Replace fixed_vector with llvm::SmallVector

Signed-off-by: daquexian <daquexian566@gmail.com>

* Shape inherited from llvm::SmallVector

Signed-off-by: daquexian <daquexian566@gmail.com>

* refine cmake

Signed-off-by: daquexian <daquexian566@gmail.com>

* rename fixed_vector to small_vector

Signed-off-by: daquexian <daquexian566@gmail.com>

* fix reviews

Signed-off-by: daquexian <daquexian566@gmail.com>

* auto format by CI

* update Shape constructor

Signed-off-by: daquexian <daquexian566@gmail.com>

* add 'PUBLIC' keyword to all target_link_libraries

Signed-off-by: daquexian <daquexian566@gmail.com>

* auto format by CI

* update cmake

Signed-off-by: daquexian <daquexian566@gmail.com>

* auto format by CI

* update cmake

Signed-off-by: daquexian <daquexian566@gmail.com>

* update cmake

Signed-off-by: daquexian <daquexian566@gmail.com>

* auto format by CI

* set is_initialized_ default to true

Signed-off-by: daquexian <daquexian566@gmail.com>

* override some methods to set is_initialized_

Signed-off-by: daquexian <daquexian566@gmail.com>

* auto format by CI

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Co-authored-by: oneflow-ci-bot <ci-bot@oneflow.org>
  • Loading branch information
3 people authored Jun 10, 2022
1 parent b3be1da commit 5686581
Show file tree
Hide file tree
Showing 33 changed files with 181 additions and 805 deletions.
20 changes: 18 additions & 2 deletions cmake/oneflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ generate_functional_api_and_pybind11_cpp(FUNCTIONAL_GENERATED_SRCS FUNCTIONAL_GE
FUNCTIONAL_PYBIND11_SRCS ${PROJECT_SOURCE_DIR})
oneflow_add_library(of_functional_obj STATIC ${FUNCTIONAL_GENERATED_SRCS}
${FUNCTIONAL_GENERATED_HRCS})
target_link_libraries(of_functional_obj glog::glog)
target_link_libraries(of_functional_obj LLVMSupportWithHeader glog::glog)
add_dependencies(of_functional_obj prepare_oneflow_third_party)

if(BUILD_PYTHON)
Expand All @@ -214,7 +214,7 @@ if(BUILD_PYTHON)
of_functional_tensor_obj STATIC ${FUNCTIONAL_TENSOR_GENERATED_SRCS}
${FUNCTIONAL_TENSOR_GENERATED_HRCS} ${FUNCTIONAL_OPS_GENERATED_SRCS}
${FUNCTIONAL_OPS_GENERATED_HRCS})
target_link_libraries(of_functional_tensor_obj glog::glog)
target_link_libraries(of_functional_tensor_obj LLVMSupportWithHeader glog::glog)
add_dependencies(of_functional_tensor_obj prepare_oneflow_third_party)
target_include_directories(of_functional_tensor_obj PRIVATE ${Python_INCLUDE_DIRS}
${Python_NumPy_INCLUDE_DIRS})
Expand Down Expand Up @@ -274,6 +274,22 @@ if(WITH_MLIR)
set(ONEFLOW_MLIR_LIBS -Wl,--no-as-needed MLIROneFlowExtension -Wl,--as-needed)
endif()

if("${LLVM_PROVIDER}" STREQUAL "install")
get_property(LLVM_INSTALL_DIR GLOBAL PROPERTY LLVM_INSTALL_DIR)
check_variable_defined(LLVM_INSTALL_DIR)
find_library(LLVMSupportLib LLVMSupport PATHS ${LLVM_INSTALL_DIR}/lib REQUIRED)
add_library(LLVMSupportWithHeader UNKNOWN IMPORTED)
set_property(TARGET LLVMSupportWithHeader PROPERTY IMPORTED_LOCATION ${LLVMSupportLib})
else()
add_library(LLVMSupportWithHeader INTERFACE IMPORTED)
target_link_libraries(LLVMSupportWithHeader INTERFACE LLVMSupport)
endif()
check_variable_defined(LLVM_INCLUDE_DIRS)
set_property(TARGET LLVMSupportWithHeader PROPERTY INTERFACE_INCLUDE_DIRECTORIES
${LLVM_INCLUDE_DIRS})

list(APPEND oneflow_third_party_libs LLVMSupportWithHeader)

include(op_schema)

get_property(EXTERNAL_INCLUDE_DIRS GLOBAL PROPERTY EXTERNAL_INCLUDE_DIRS)
Expand Down
2 changes: 1 addition & 1 deletion cmake/op_schema.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,5 @@ set_source_files_properties(${GENERATED_OP_SCHEMA_H} ${GENERATED_OP_SCHEMA_CPP}
TRUE)

oneflow_add_library(of_op_schema OBJECT ${GENERATED_OP_SCHEMA_H} ${GENERATED_OP_SCHEMA_CPP})
target_link_libraries(of_op_schema glog::glog)
target_link_libraries(of_op_schema LLVMSupportWithHeader glog::glog)
add_dependencies(of_op_schema prepare_oneflow_third_party)
6 changes: 6 additions & 0 deletions cmake/util.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,12 @@ function(set_compile_options_to_oneflow_target target)
endif()
endfunction()

function(check_variable_defined variable)
if(NOT DEFINED ${variable})
message(FATAL_ERROR "Variable ${variable} is not defined")
endif()
endfunction()

function(checkDirAndAppendSlash)
set(singleValues DIR;OUTPUT)
set(prefix ARG)
Expand Down
7 changes: 3 additions & 4 deletions oneflow/core/autograd/gradient_funcs/normalization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,14 @@ class NormalizationGrad : public OpExprGradFunction<NormalizationGradCaptureStat
return Maybe<void>::Ok();
}

DimVector dim_vec;
Shape shape;
for (int i = 0; i < x->shape()->NumAxes(); ++i) {
if (i != ctx->axis) {
dim_vec.emplace_back(1);
shape.emplace_back(1);
} else {
dim_vec.emplace_back(x->shape()->At(ctx->axis));
shape.emplace_back(x->shape()->At(ctx->axis));
}
}
Shape shape(dim_vec);
const auto& reshaped_gamma = JUST(functional::Reshape(gamma, shape));
const auto& reshaped_inv_variance = JUST(functional::Reshape(inv_variance, shape));

Expand Down
277 changes: 0 additions & 277 deletions oneflow/core/common/fixed_vector.h

This file was deleted.

Loading

0 comments on commit 5686581

Please sign in to comment.