Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[serving] dev graph run #7008

Merged
merged 81 commits into from
Dec 26, 2021
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
a17fa00
add cmake changes for liboneflow_cpp.so
daquexian Dec 10, 2021
8cedfaf
add separate target for cpp api test
daquexian Dec 10, 2021
9911af2
Merge branch 'master' into liboneflow_cpp
daquexian Dec 11, 2021
9f9378b
add cpp api test in ci
daquexian Dec 11, 2021
c4db1ad
graph run
zzk0 Dec 11, 2021
788a774
Merge branch 'master' into liboneflow_cpp
daquexian Dec 11, 2021
9f4da59
Merge branch 'master' into liboneflow_cpp
oneflow-ci-bot Dec 11, 2021
4298d3b
reverse the order of cudnn and cuda library
daquexian Dec 11, 2021
9dce5ce
update logic of BUILD_MONOLITHIC_LIBONEFLOW
daquexian Dec 11, 2021
56152a2
rename BUILD_MONOLITHIC_LIBONEFLOW to BUILD_MONOLITHIC_LIBONEFLOW_CPP_SO
daquexian Dec 11, 2021
bf1c340
refine
zzk0 Dec 12, 2021
91ebd5f
[draft] implement graph parameter load and save (#7010)
daquexian Dec 12, 2021
86004c6
pimpl
zzk0 Dec 12, 2021
8c9b663
Merge branch 'master' into liboneflow_cpp
daquexian Dec 13, 2021
0d12c3e
Merge branch 'master' into liboneflow_cpp
oneflow-ci-bot Dec 13, 2021
63d5f72
batching
zzk0 Dec 14, 2021
c6d27d5
share lib directory in test container
daquexian Dec 14, 2021
5089f4c
Merge branch 'liboneflow_cpp' of github.com:Oneflow-Inc/oneflow into …
daquexian Dec 14, 2021
89e8952
fix typo;
zzk0 Dec 14, 2021
2d611f1
merge master
zzk0 Dec 14, 2021
7d9aef6
add github actions debug
daquexian Dec 15, 2021
18b9057
Merge branch 'master' into liboneflow_cpp
daquexian Dec 15, 2021
5c118a8
Revert "add github actions debug"
daquexian Dec 15, 2021
be2a540
Merge branch 'liboneflow_cpp' of github.com:Oneflow-Inc/oneflow into …
daquexian Dec 15, 2021
a0227da
add upterm debug after exe test
daquexian Dec 15, 2021
c6e27bc
Merge branch 'master' into liboneflow_cpp
daquexian Dec 15, 2021
375fe97
sleep after fail
daquexian Dec 15, 2021
2e18280
Merge branch 'liboneflow_cpp' of github.com:Oneflow-Inc/oneflow into …
daquexian Dec 15, 2021
31629d7
set LD_LIBRARY_PATH in yml for cpp api test exe
daquexian Dec 15, 2021
1ad7793
Merge remote-tracking branch 'origin/master' into liboneflow_cpp
daquexian Dec 15, 2021
f8e05da
refine
zzk0 Dec 15, 2021
914dbf0
Merge branch 'master' into dev_graph_api_new
zzk0 Dec 15, 2021
187e47f
add test file && input order
zzk0 Dec 15, 2021
ebd7bca
sleep
daquexian Dec 16, 2021
55706b6
Merge remote-tracking branch 'origin/master' into liboneflow_cpp
daquexian Dec 16, 2021
504241a
upload liboneflow_cpp.so
daquexian Dec 16, 2021
7883995
modify cmake to trigger compilation
daquexian Dec 16, 2021
c2034db
Merge branch 'liboneflow_cpp' of https://github.com/Oneflow-Inc/onefl…
zzk0 Dec 16, 2021
525fbb2
load job from ir && clean && add mlir model
zzk0 Dec 16, 2021
2d91e01
[remove useless python code]save to .pb
zzk0 Dec 16, 2021
68dc409
add target of_common_obj to remove duplicate REGISTER_PASS && run of…
zzk0 Dec 16, 2021
5eb7cbb
Merge branch 'master' into dev_graph_api_new
zzk0 Dec 16, 2021
84d980a
remove openvino
zzk0 Dec 17, 2021
e297aeb
remove openvino test
zzk0 Dec 17, 2021
0895d7f
refine
zzk0 Dec 17, 2021
032b672
IValue
zzk0 Dec 17, 2021
b086f7c
Update oneflow/api/cpp/framework/graph.h
zzk0 Dec 17, 2021
e3df599
refine
zzk0 Dec 17, 2021
09f776c
Merge branch 'dev_graph_api_new' of https://github.com/Oneflow-Inc/on…
zzk0 Dec 17, 2021
03c98df
refine
zzk0 Dec 17, 2021
a789d1c
refine
zzk0 Dec 17, 2021
60193e0
refine
zzk0 Dec 17, 2021
8f83592
refine
zzk0 Dec 17, 2021
a61c521
refine
zzk0 Dec 17, 2021
25d7f18
rename in oneflow.cmake
zzk0 Dec 18, 2021
0a65215
refine oneflow.cmake
zzk0 Dec 20, 2021
fb14d66
Merge branch 'master' into dev_graph_api_new
oneflow-ci-bot Dec 20, 2021
04adb1c
make of_api_common object library
zzk0 Dec 20, 2021
03f1344
Merge branch 'dev_graph_api_new' of https://github.com/Oneflow-Inc/on…
zzk0 Dec 20, 2021
968d98d
Merge branch 'master' into dev_graph_api_new
oneflow-ci-bot Dec 20, 2021
b50aa7c
move device util function in api to core
zzk0 Dec 20, 2021
28d7385
Merge branch 'master' into dev_graph_api_new
oneflow-ci-bot Dec 20, 2021
9ba25f4
remove device check in New and ThreadLocalGetOrNew
zzk0 Dec 20, 2021
d246370
Merge branch 'dev_graph_api_new' of https://github.com/Oneflow-Inc/on…
zzk0 Dec 20, 2021
0a31670
Merge remote-tracking branch 'upstream/master' into dev_graph_api_new
mosout Dec 23, 2021
809e578
refine
mosout Dec 23, 2021
946d462
Merge remote-tracking branch 'upstream/master' into dev_graph_api_new
mosout Dec 23, 2021
770b1de
fix device test
mosout Dec 23, 2021
059a7c0
refine graph test
mosout Dec 24, 2021
a4eb3cb
Merge remote-tracking branch 'upstream/master' into dev_graph_api_new
mosout Dec 24, 2021
85d9608
refine GetExeDir()
mosout Dec 24, 2021
c1bae17
refine GetExeDir() again
mosout Dec 24, 2021
a40c08a
Merge remote-tracking branch 'upstream/master' into dev_graph_api_new
mosout Dec 24, 2021
7e69110
fix
mosout Dec 24, 2021
422b1e2
Merge remote-tracking branch 'upstream/master' into dev_graph_api_new
mosout Dec 24, 2021
ca56a17
refine
mosout Dec 24, 2021
ae2f7ac
fix
mosout Dec 25, 2021
567442d
Merge branch 'master' into dev_graph_api_new
mosout Dec 25, 2021
03f5fad
Merge remote-tracking branch 'upstream/dev_graph_api_new' into dev_gr…
mosout Dec 25, 2021
cbf506c
add WITH_CUDA guard
daquexian Dec 26, 2021
0e982a9
Merge branch 'master' into dev_graph_api_new
daquexian Dec 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions cmake/oneflow.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ foreach(oneflow_single_file ${oneflow_all_src})
endif()

if("${oneflow_single_file}" MATCHES "^${PROJECT_SOURCE_DIR}/oneflow/api/common/.*\\.(h|cpp)$")
list(APPEND of_all_obj_cc ${oneflow_single_file})
set(group_this ON)
endif()
list(APPEND of_common_obj_cc ${oneflow_single_file})
zzk0 marked this conversation as resolved.
Show resolved Hide resolved
set(group_this ON)
endif()

if(BUILD_PYTHON)

Expand Down Expand Up @@ -284,6 +284,14 @@ if (BUILD_CUDA)
target_link_libraries(oneflow-gen-ods CUDA::cudart_static)
endif()

# oneflow api common
oneflow_add_library(of_common_obj ${of_common_obj_cc})
set(of_common_libs -Wl,--whole-archive of_common_obj -Wl,--no-whole-archive)
target_link_libraries(of_common_obj oneflow)
if (WITH_MLIR)
target_link_libraries(of_common_obj ${ONEFLOW_MLIR_LIBS})
endif()

if(BUILD_PYTHON)

# py ext lib
Expand All @@ -304,7 +312,7 @@ if(BUILD_PYTHON)
target_link_libraries(oneflow_internal PRIVATE
${of_libs}
of_functional_tensor_obj
${ONEFLOW_MLIR_LIBS}
${of_common_libs}
${oneflow_third_party_libs}
of_pyext_obj
${oneflow_exe_third_party_libs})
Expand Down Expand Up @@ -346,7 +354,7 @@ if (BUILD_CPP_API)
oneflow_add_library(oneflow_cpp ${of_cpp_api_files})
endif()
set_target_properties(oneflow_cpp PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${LIBONEFLOW_LIBRARY_DIR}" LIBRARY_OUTPUT_DIRECTORY "${LIBONEFLOW_LIBRARY_DIR}")
target_link_libraries(oneflow_cpp PRIVATE ${of_libs} ${ONEFLOW_MLIR_LIBS} ${oneflow_third_party_libs})
target_link_libraries(oneflow_cpp PRIVATE ${of_libs} ${of_common_libs} ${oneflow_third_party_libs})
endif()

file(RELATIVE_PATH PROJECT_BINARY_DIR_RELATIVE ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR})
Expand Down
8 changes: 4 additions & 4 deletions cmake/third_party/absl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ SET(ABSL_LIBRARY_DIR ${THIRD_PARTY_DIR}/absl/${CMAKE_INSTALL_LIBDIR} CACHE PATH

if(WIN32)
set(ABSL_BUILD_LIBRARY_DIR ${ABSL_INSTALL}/${CMAKE_INSTALL_LIBDIR})
set(ABSL_LIBRARY_NAMES absl_base.lib absl_spinlock_wait.lib absl_dynamic_annotations.lib
set(ABSL_LIBRARY_NAMES absl_spinlock_wait.lib absl_dynamic_annotations.lib
absl_malloc_internal.lib absl_throw_delegate.lib absl_int128.lib absl_strings.lib absl_str_format_internal.lib
absl_time.lib absl_bad_optional_access.lib)
absl_time.lib absl_bad_optional_access.lib absl_base.lib)
else()
set(ABSL_BUILD_LIBRARY_DIR ${ABSL_INSTALL}/${CMAKE_INSTALL_LIBDIR})
set(ABSL_LIBRARY_NAMES libabsl_base.a libabsl_spinlock_wait.a libabsl_dynamic_annotations.a
set(ABSL_LIBRARY_NAMES libabsl_spinlock_wait.a libabsl_dynamic_annotations.a
libabsl_malloc_internal.a libabsl_throw_delegate.a libabsl_int128.a libabsl_strings.a libabsl_str_format_internal.a
libabsl_time.a libabsl_bad_optional_access.a)
libabsl_time.a libabsl_bad_optional_access.a libabsl_base.a)
endif()

foreach(LIBRARY_NAME ${ABSL_LIBRARY_NAMES})
Expand Down
30 changes: 30 additions & 0 deletions oneflow/api/common/ir_pass.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
Copyright 2020 The OneFlow 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.
*/

#ifdef WITH_MLIR

#include "oneflow/ir/include/OneFlow/Extension.h"
#include "oneflow/ir/oneflow-extension/include/OneFlow/OneFlowRoundTrip.h"
#include <glog/logging.h>

namespace oneflow {

REGISTER_JOB_PASS("IRRoundTripBeforeAD", IRRoundTrip<kBeforeAD>);
REGISTER_JOB_PASS("IRRoundTrip", IRRoundTrip<kAfterAD>);

} // namespace oneflow

#endif // WITH_MLIR
36 changes: 36 additions & 0 deletions oneflow/api/common/job_build_and_infer_ctx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2020 The OneFlow 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.
*/

#ifndef ONEFLOW_API_COMMON_JOB_BUILD_AND_INFER_CTX_H_
#define ONEFLOW_API_COMMON_JOB_BUILD_AND_INFER_CTX_H_

#include "oneflow/core/job/job.pb.h"
#include "oneflow/core/job/job_build_and_infer_ctx_mgr.h"

namespace oneflow {

inline Maybe<Job> GetCurrentJob() {
auto* job_ctx_mgr = Global<LazyJobBuildAndInferCtxMgr>::Get();
CHECK_NOTNULL_OR_RETURN(job_ctx_mgr);
auto* job_ctx =
JUST(job_ctx_mgr->FindJobBuildAndInferCtx(*JUST(job_ctx_mgr->GetCurrentJobName())));
CHECK_NOTNULL_OR_RETURN(job_ctx);
return job_ctx->job();
}

} // namespace oneflow

#endif // ONEFLOW_API_COMMON_JOB_BUILD_AND_INFER_CTX_H_
54 changes: 54 additions & 0 deletions oneflow/api/common/scope.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Copyright 2020 The OneFlow 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.
*/

#ifndef ONEFLOW_API_COMMON_SCOPE_H_
#define ONEFLOW_API_COMMON_SCOPE_H_

#include <memory>
#include <string>
#include "oneflow/core/common/just.h"
#include "oneflow/core/framework/device.h"
#include "oneflow/core/framework/instructions_builder.h"
#include "oneflow/core/framework/session_util.h"
#include "oneflow/core/job/job_conf.cfg.h"
#include "oneflow/core/job/job_conf.pb.h"
#include "oneflow/core/job/scope.h"

namespace oneflow {

inline Maybe<Scope> MakeScope(const JobConfigProto& config_proto, const Device& device) {
std::shared_ptr<Scope> scope;
std::shared_ptr<cfg::JobConfigProto> cfg_config_proto =
std::make_shared<cfg::JobConfigProto>(config_proto);
JUST(LogicalRun([&](InstructionsBuilder* builder) -> Maybe<void> {
int64_t session_id = 0;
std::string device_tag = "cpu";
std::string machine_ids = "0";
std::string device_ids = "0";
if (device.type() == "cuda") {
device_tag = "gpu";
device_ids = std::to_string(device.device_id());
}
scope = JUST(builder->BuildInitialScope(session_id, cfg_config_proto, device_tag,
{machine_ids + ":" + device_ids}, nullptr, false));
return Maybe<void>::Ok();
}));
return scope;
}

} // namespace oneflow

#endif // ONEFLOW_API_COMMON_SCOPE_H_
12 changes: 11 additions & 1 deletion oneflow/api/cpp/env.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ limitations under the License.
#include <random>
#include <type_traits>
#include "oneflow/api/cpp/env.h"
#include "oneflow/core/common/global.h"
#include "oneflow/core/common/just.h"
#include "oneflow/core/common/multi_client.h"
#include "oneflow/core/common/optional.h"
#include "oneflow/core/framework/multi_client_session_context.h"
#include "oneflow/core/framework/shut_down_util.h"
#include "oneflow/core/job/cluster_instruction.h"
#include "oneflow/core/job/env.pb.h"
#include "oneflow/core/job/env_global_objects_scope.h"
#include "oneflow/core/control/ctrl_bootstrap.h"
#include "oneflow/core/job/session.h"
#include "oneflow/core/rpc/include/base.h"
#include "oneflow/core/vm/vm_util.h"
#include "oneflow/core/thread/thread_consistent_id.h"
Expand Down Expand Up @@ -114,6 +117,12 @@ of::Maybe<void> initEnv() {
CompleteEnvProto(env_proto);
of::Global<of::EnvGlobalObjectsScope>::SetAllocated(new of::EnvGlobalObjectsScope());
JUST(of::Global<of::EnvGlobalObjectsScope>::Get()->Init(env_proto));

of::ConfigProto config_proto;
config_proto.mutable_resource()->set_cpu_device_num(1); // useless, will be set in TryInit
config_proto.set_session_id(of::NewSessionId());
of::Global<of::MultiClientSessionContext>::New();
of::Global<of::MultiClientSessionContext>::Get()->TryInit(config_proto).GetOrThrow();
return of::Maybe<void>::Ok();
}

Expand All @@ -129,6 +138,8 @@ void release() {
if (IsEnvInited()) {
// sync multi_client
of::vm::ClusterSync().GetOrThrow();
of::Global<of::MultiClientSessionContext>::Get()->TryClose().GetOrThrow();
of::Global<of::MultiClientSessionContext>::Delete();
zzk0 marked this conversation as resolved.
Show resolved Hide resolved
// destory env
if (of::IsMultiClient().GetOrThrow()) {
OF_ENV_BARRIER();
Expand All @@ -137,7 +148,6 @@ void release() {
}
of::Global<of::EnvGlobalObjectsScope>::Delete();
}
// TODO close session
of::SetShuttingDown();
of::ResetThisThreadUniqueConsistentId().GetOrThrow();
}
Expand Down
1 change: 1 addition & 0 deletions oneflow/api/cpp/framework.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
#include "framework/shape.h"
#include "framework/dtype.h"
#include "framework/tensor.h"
#include "framework/graph.h"
#include "framework/ivalue.h"

#endif // ONEFLOW_API_CPP_FRAMEWORK_H_
1 change: 1 addition & 0 deletions oneflow/api/cpp/framework/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace oneflow_api {

class Device final {
friend class Tensor;
friend class Graph;

public:
explicit Device(const std::string& type_or_type_with_device_id);
Expand Down
Loading