Page MenuHomePhabricator

[OpenMP][libomptarget] Change device vector elements to unique_ptr type
ClosedPublic

Authored by ye-luo on Sep 4 2021, 11:41 AM.

Details

Summary

Using std::vector<DeviceTy> requires implementing copy constructor and copied assign operator for DeviceTy.
Indeed DeviceTy should never be copied. After changing to std::vector<std::unique_ptr<DeviceTy>>,
All the unsafe copy constructor and copy assign operator implementations can be removed.
Compilers mark them deleted due to mutex or underlying objects and this is the desired behavior.

Diff Detail

Event Timeline

ye-luo created this revision.Sep 4 2021, 11:41 AM
ye-luo requested review of this revision.Sep 4 2021, 11:41 AM
Herald added a project: Restricted Project. · View Herald Transcript
ye-luo edited the summary of this revision. (Show Details)Sep 4 2021, 11:46 AM
ye-luo added a reviewer: tianshilei1992.
tianshilei1992 added inline comments.Sep 4 2021, 11:58 AM
openmp/libomptarget/src/rtl.cpp
325

what about emplace_back?

ye-luo added inline comments.Sep 4 2021, 12:03 PM
openmp/libomptarget/src/rtl.cpp
325

Both push_back and emplace_back do the same thing of invoking the move constructor of unique_ptr. However, emplace_back is less verbose in readability. So push_back is preferred here.

tianshilei1992 added inline comments.Sep 4 2021, 12:05 PM
openmp/libomptarget/src/device.h
279

Mark them as delete if you expect it should not be copied at all.

ye-luo updated this revision to Diff 370753.Sep 4 2021, 12:14 PM

Address review

ye-luo added inline comments.Sep 4 2021, 12:15 PM
openmp/libomptarget/src/device.h
279

Added. It makes the non-copyable nature explicitly expressed.

This revision is now accepted and ready to land.Sep 5 2021, 1:16 PM