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

Move constructor is added to support dmlc::optional<T> #658

Merged
merged 21 commits into from
Nov 10, 2021

Conversation

mozga-intel
Copy link
Contributor

@mozga-intel mozga-intel commented Aug 23, 2021

Description

The class template std::optional manages an optional contained value, i.e. a value that may or may not be present. In this pull request, a few things were implemented, such as extended series of constructors and a function of value. Mainly, this pull request is a realization of changes that have an impact on constructors, as follows, (upgrade dmlc::optional constructors):

  1. constructor to construct an object that does not contain a value,
  2. constructor to construct an object that contains a nullptr value,
  3. constructs an optional object that contains a value, initialized as if direct-initializing:`
  4. move constructor: If other contains a value, then the stored value is direct-intialized with it.
    optional(optional &&other) noexcept() { }
  5. move constructor: constructs the stored value with value with otherparameter.
    optional(U &&other) noexcept { }

Upgrade: dmlc::optional value
1. T &value() &
2. const T &value() const &
3. T &&value() &
4. const T && value() const &&

doc/Doxyfile Outdated Show resolved Hide resolved
Copy link

@sfraczek sfraczek left a comment

Choose a reason for hiding this comment

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

LGTM. It would be nice to see if there is a performance boost thanks to supporting move here.

@mozga-intel mozga-intel force-pushed the mozga-intel/optional_move_support branch from b5ea461 to fce1d9f Compare September 21, 2021 10:09
@szha szha requested a review from hcho3 September 30, 2021 16:08
@hcho3
Copy link
Contributor

hcho3 commented Oct 14, 2021

@szha @mozga-intel Do you still want my review?

@mozga-intel
Copy link
Contributor Author

@hcho3 If you can review it, I'll be grateful. Thanks!

@mozga-intel
Copy link
Contributor Author

Gentle ping @hcho3, @szha

Copy link
Member

@szha szha left a comment

Choose a reason for hiding this comment

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

LGTM. I will leave it open for a couple more days in case there's any concern before I merge.

Copy link
Contributor

@hcho3 hcho3 left a comment

Choose a reason for hiding this comment

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

No objection from me. Hopefully we can use std::optional in the future.

@mozga-intel
Copy link
Contributor Author

mozga-intel commented Nov 8, 2021

@szha, @hcho3 Thanks! There are a few things to improve: firstly, a constructor that can be declared with a constexpr specifier. Secondly, as @hcho3 mentioned, std::optional might be added to support it ~ it will be required a few changes in the code structure.

@szha
Copy link
Member

szha commented Nov 8, 2021

@mozga-intel sounds good. Do you intend to continue in this PR or as a follow-up?

@mozga-intel
Copy link
Contributor Author

@szha after merge! Because I need to test it before.

@szha szha merged commit 20ec5be into dmlc:main Nov 10, 2021
@areusch
Copy link
Contributor

areusch commented Apr 21, 2022

not quite sure why yet, but it looks like when i apply this patch to TVM, the following command (in tvm repo, at rev c07a46327c86fc541297ebb985cc9c1dcef5a0db, using docker container tlcpack/ci-cpu:v0.84 and config.cmake generated with tests/scripts/task_config_build_cpu.sh) segfaults:

cd rust/tvm/examples/resnet
python3 src/build_resnet.py --build-dir=.

still tracing through to see why, but posting up here in case any of you all have ideas.

cc @tqchen

optional(dmlc::nullopt_t) noexcept : is_none(true) {} // NOLINT(*)
/*! \brief copy constructor, if other contains a value, then stored value is
* direct-intialized with it. */
optional(const optional &other) = default;
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems that reverting the use of the default copy constructor here stops the segfault

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants