-
Notifications
You must be signed in to change notification settings - Fork 796
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
Feat support host memory #9928
Merged
Merged
Feat support host memory #9928
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
7674b43
feat_support_host_memory_in_lazy_mode
clackhan 28b91fa
refine
clackhan aae225d
Merge branch 'master' into feat_support_host_memory_in_lazy_mode
clackhan 3c2d286
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow into …
clackhan c48f40d
compatible_eager_and_lazy
clackhan 24b9bcb
del useless code
clackhan 5cdc9fa
Merge branch 'feat_support_host_memory_in_lazy_mode' of https://githu…
clackhan 89609a9
optimize code
clackhan cff151f
refine
clackhan aeae1e4
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow into …
clackhan 54b097e
refine
clackhan 1bf742f
refine
clackhan 7e254ac
Merge branch 'master' into feat_support_host_memory_in_lazy_mode
clackhan dd69263
fix static check error
clackhan e2887b4
Merge branch 'feat_support_host_memory_in_lazy_mode' of https://githu…
clackhan 4bb813e
Merge branch 'master' into feat_support_host_memory_in_lazy_mode
clackhan 84373c4
deal comments
clackhan 163cb22
reslove comments
clackhan 94cd8a8
Merge branch 'master' into feat_support_host_memory_in_lazy_mode
clackhan 585a920
reslove comments
clackhan 977682d
Merge branch 'master' of https://github.com/Oneflow-Inc/oneflow into …
clackhan eab40e3
Merge branch 'master' into feat_support_host_memory_in_lazy_mode
clackhan 32d650d
Merge branch 'master' into feat_support_host_memory_in_lazy_mode
mergify[bot] 330ab9e
Merge branch 'master' into feat_support_host_memory_in_lazy_mode
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,15 +53,18 @@ Maybe<Symbol<Device>> RawGetDefaultCpuDevice() { return Device::New("cpu"); } | |
|
||
constexpr auto* GetDefaultCpuDevice = DECORATE(&RawGetDefaultCpuDevice, ThreadLocal); | ||
|
||
Maybe<Symbol<Device>> GetDefaultDevice(const TensorTuple& inputs, const OpExprInterpContext& ctx) { | ||
if (inputs.empty()) { | ||
if (ctx.device.has_value()) { | ||
return JUST(ctx.device); | ||
} else { | ||
return GetDefaultCpuDevice(); | ||
Maybe<Symbol<Device>> GetDefaultDevice(const TensorTuple& inputs, const OpExprInterpContext& ctx, | ||
const UserOpExpr& user_op_expr) { | ||
if (!inputs.empty()) { | ||
for (int32_t i = 0; i < inputs.size(); ++i) { | ||
if (!user_op_expr.IsHostMemoryInput(i)) { return JUST(inputs.at(i)->device()); } | ||
} | ||
} | ||
return JUST(inputs.at(0)->device()); | ||
if (ctx.device.has_value()) { | ||
return JUST(ctx.device); | ||
} else { | ||
return GetDefaultCpuDevice(); | ||
} | ||
} | ||
|
||
Maybe<EagerLocalTensorImpl*> TensorImpl4Tensor(const std::shared_ptr<Tensor>& tensor) { | ||
|
@@ -75,7 +78,7 @@ Maybe<void> NaiveInterpret(const UserOpExpr& user_op_expr, const TensorTuple& in | |
TensorTuple* outputs, const OpExprInterpContext& ctx) { | ||
OF_PROFILER_RANGE_GUARD("NaiveInterpret"); | ||
CHECK_EQ_OR_RETURN(outputs->size(), user_op_expr.output_size()); // NOLINT | ||
Symbol<Device> default_device = JUST(GetDefaultDevice(inputs, ctx)); | ||
Symbol<Device> default_device = JUST(GetDefaultDevice(inputs, ctx, user_op_expr)); | ||
const std::shared_ptr<const LocalTensorInferResult> result = | ||
JUST([&]() -> Maybe<const LocalTensorInferResult> { | ||
LocalTensorMetaInferArgs infer_args; | ||
|
@@ -84,8 +87,17 @@ Maybe<void> NaiveInterpret(const UserOpExpr& user_op_expr, const TensorTuple& in | |
}()); | ||
|
||
vm::EagerBlobObjectList input_eager_blob_objects(inputs.size()); | ||
// expand lifetime of host_inputs to the end of this function | ||
TensorTuple host_inputs; | ||
for (int i = 0; i < inputs.size(); i++) { | ||
input_eager_blob_objects.at(i) = JUST(inputs.at(i)->eager_blob_object()); | ||
if (user_op_expr.IsHostMemoryInput(i)) { | ||
const auto& host_input = JUST(functional::To( | ||
inputs.at(i), Optional<Symbol<Device>>(JUST(GetDefaultCpuDevice())), NullOpt, false)); | ||
input_eager_blob_objects.at(i) = JUST(host_input->eager_blob_object()); | ||
host_inputs.emplace_back(host_input); | ||
Comment on lines
+94
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 延长host_input的生命周期,防止其被过析构 |
||
} else { | ||
input_eager_blob_objects.at(i) = JUST(inputs.at(i)->eager_blob_object()); | ||
} | ||
} | ||
|
||
const auto& output_tensor_metas = result->output_tensor_metas(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当op的输入为HostMemory类型时,boxing_out_ parallel_desc的类型设置为cpu