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

Stream compute on pinned memory #8486

Merged
merged 38 commits into from
Jun 28, 2022
Merged

Conversation

Flowingsun007
Copy link
Contributor

@Flowingsun007 Flowingsun007 commented Jun 24, 2022

  • 新增StreamRole::kPinMemory类型
  • 新增Visitor类型:IsStreamPinned
  • 新增StreamType类型:PinnedEpStreamType
  • 移除之前OpExprInterpContext、EagerBlobObject、eager interpreter里pin_memory相关的设计和特判,改用StreamRole进行实现
  • 修改pin_memory相关的empty、cast、copy op实现,增加InferDeviceAndStream推导逻辑
  • 删除了oneflow/oneflow/core/device/cpu_device_context.h,因为没有地方使用到了

@github-actions
Copy link
Contributor

Code got formatted by CI. Please request CI again if you still want to have this PR merged. If the PR is from a forked repo, please download the patch files from the GitHub Actions web page and apply them locally.

@github-actions
Copy link
Contributor

Code got formatted by CI. Please request CI again if you still want to have this PR merged. If the PR is from a forked repo, please download the patch files from the GitHub Actions web page and apply them locally.

@Flowingsun007 Flowingsun007 requested review from oneflow-ci-bot and removed request for oneflow-ci-bot June 24, 2022 14:10
@Flowingsun007 Flowingsun007 removed the request for review from oneflow-ci-bot June 24, 2022 14:26
oneflow/core/common/stream_role.h Outdated Show resolved Hide resolved
oneflow/core/eager/blob_instruction_type.h Outdated Show resolved Hide resolved
oneflow/core/framework/tensor_impl.cpp Outdated Show resolved Hide resolved
oneflow/core/vm/ep_stream_type.cpp Outdated Show resolved Hide resolved
if (pin_memory) {
CHECK_OR_RETURN(out_device->type() == "cpu")
<< "empty op only support pin_memory in cpu device but got " << out_device->type();
auto pin_device = JUST(Device::New("cuda"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

写TODO注释

if (pin_memory) {
CHECK_OR_RETURN(in_device->type() == "cpu")
<< "cast op only support pin_memory in cpu device but got " << in_device->type();
auto pin_device = JUST(Device::New("cuda"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO注释

} else if (in_device->type() == "cpu" && out_device->type() != "cpu") {
const auto device = JUST(Device::New(out_device->type(), out_device->device_id()));
return Stream::New(device, StreamRole::kHost2Device);
} else if (in_device->type() == "cpu" && out_device->type() == "cpu" && pin_memory) {
auto pin_device = JUST(Device::New("cuda"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO注释

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已加

@Flowingsun007 Flowingsun007 requested review from oneflow-ci-bot and removed request for oneflow-ci-bot June 27, 2022 09:21
@Flowingsun007 Flowingsun007 added the need-highest-priority Only add this when you really need it!!! Will block all other PRs. label Jun 27, 2022
@BBuf BBuf removed the need-highest-priority Only add this when you really need it!!! Will block all other PRs. label Jun 27, 2022
@lixinqi lixinqi removed the request for review from oneflow-ci-bot June 27, 2022 17:27
@lixinqi lixinqi requested a review from oneflow-ci-bot June 27, 2022 17:36
@github-actions
Copy link
Contributor

CI failed when running job: Build cu102. PR label automerge has been removed

@Flowingsun007 Flowingsun007 added the need-highest-priority Only add this when you really need it!!! Will block all other PRs. label Jun 28, 2022
@Flowingsun007 Flowingsun007 requested review from oneflow-ci-bot and removed request for oneflow-ci-bot June 28, 2022 01:14
@github-actions
Copy link
Contributor

View latest API docs preview at: https://staging.oneflow.info/docs/Oneflow-Inc/oneflow/pr/8486/

@github-actions
Copy link
Contributor

Speed stats:
GPU Name: NVIDIA GeForce GTX 1080 

❌ OneFlow resnet50 time: 129.6ms (= 12957.2ms / 100, input_shape=[16, 3, 224, 224])
PyTorch resnet50 time: 143.5ms (= 14345.7ms / 100, input_shape=[16, 3, 224, 224])
✔️ Relative speed: 1.11 (= 143.5ms / 129.6ms)

OneFlow resnet50 time: 75.5ms (= 7551.3ms / 100, input_shape=[8, 3, 224, 224])
PyTorch resnet50 time: 85.8ms (= 8577.8ms / 100, input_shape=[8, 3, 224, 224])
✔️ Relative speed: 1.14 (= 85.8ms / 75.5ms)

OneFlow resnet50 time: 49.3ms (= 9855.9ms / 200, input_shape=[4, 3, 224, 224])
PyTorch resnet50 time: 60.3ms (= 12059.4ms / 200, input_shape=[4, 3, 224, 224])
✔️ Relative speed: 1.22 (= 60.3ms / 49.3ms)

OneFlow resnet50 time: 39.2ms (= 7844.0ms / 200, input_shape=[2, 3, 224, 224])
PyTorch resnet50 time: 44.5ms (= 8900.1ms / 200, input_shape=[2, 3, 224, 224])
✔️ Relative speed: 1.13 (= 44.5ms / 39.2ms)

OneFlow resnet50 time: 36.8ms (= 7370.0ms / 200, input_shape=[1, 3, 224, 224])
PyTorch resnet50 time: 38.6ms (= 7710.9ms / 200, input_shape=[1, 3, 224, 224])
✔️ Relative speed: 1.05 (= 38.6ms / 36.8ms)

OneFlow swin dataloader time: 0.264s (= 52.738s / 200, num_workers=1)
PyTorch swin dataloader time: 0.151s (= 30.150s / 200, num_workers=1)
Relative speed: 0.572 (= 0.151s / 0.264s)

OneFlow swin dataloader time: 0.074s (= 14.863s / 200, num_workers=4)
PyTorch swin dataloader time: 0.042s (= 8.442s / 200, num_workers=4)
Relative speed: 0.568 (= 0.042s / 0.074s)

OneFlow swin dataloader time: 0.040s (= 8.034s / 200, num_workers=8)
PyTorch swin dataloader time: 0.022s (= 4.419s / 200, num_workers=8)
Relative speed: 0.550 (= 0.022s / 0.040s)

❌ OneFlow resnet50 time: 145.5ms (= 14550.2ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 170.7ms (= 17067.4ms / 100, input_shape=[16, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.17 (= 170.7ms / 145.5ms)

OneFlow resnet50 time: 93.6ms (= 9357.3ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 112.6ms (= 11261.1ms / 100, input_shape=[8, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.20 (= 112.6ms / 93.6ms)

OneFlow resnet50 time: 70.4ms (= 14083.2ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 85.7ms (= 17138.2ms / 200, input_shape=[4, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.22 (= 85.7ms / 70.4ms)

OneFlow resnet50 time: 57.5ms (= 11508.0ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 82.4ms (= 16470.5ms / 200, input_shape=[2, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.43 (= 82.4ms / 57.5ms)

OneFlow resnet50 time: 52.4ms (= 10482.6ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
PyTorch resnet50 time: 71.4ms (= 14277.3ms / 200, input_shape=[1, 3, 224, 224], ddp, world size=2)
✔️ Relative speed: 1.36 (= 71.4ms / 52.4ms)

@Flowingsun007 Flowingsun007 merged commit 41fc1ad into master Jun 28, 2022
@Flowingsun007 Flowingsun007 deleted the stream_compute_on_pinned_memory branch June 28, 2022 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
eager enhancement need-highest-priority Only add this when you really need it!!! Will block all other PRs. op refactor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants