Skip to content

[ET-VK] Introduce vTensorPtr to prevent reference invalidation and remove get_val() API #2978

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

Closed
wants to merge 5 commits into from

Conversation

SS-JIA
Copy link
Contributor

@SS-JIA SS-JIA commented Apr 10, 2024

Stack from ghstack (oldest at bottom):

Context

Currently when writing operators developers will save a reference to a vTensor retrieved from a ComputeGraph's list of values_ like so:

vTensor& vten = graph.get_val(vref).toTensor();

However, this is dangerous since if any values are added once the reference has been stored, values_ which is a std::vector may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the vTensorPtr class which is a wrapper around a vTensor*. When constructed, it will increment a counter in the ComputeGraph instance, and when destroyed it will decrement the counter. ComputeGraph cannot add any values while the counter is not zero.

Since Value can be converted to other non-trivial types, this changeset also removes the get_val function entirely to guard against unsafe behaviour.

Differential Revision: D55984187

…remove `get_val()` API

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Apr 10, 2024

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/2978

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit b99f1d8 with merge base 62a4dd3 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 10, 2024
SS-JIA added a commit that referenced this pull request Apr 10, 2024
…remove `get_val()` API

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)

ghstack-source-id: 222072108
Pull Request resolved: #2978
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55984187

…dation and remove `get_val()` API"

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)

[ghstack-poisoned]
SS-JIA added a commit that referenced this pull request Apr 10, 2024
…remove `get_val()` API

Pull Request resolved: #2978

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.
ghstack-source-id: 222074671
@exported-using-ghexport

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55984187

…dation and remove `get_val()` API"

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55984187

SS-JIA added a commit that referenced this pull request Apr 11, 2024
…remove `get_val()` API

Pull Request resolved: #2978

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.
ghstack-source-id: 222196863
@exported-using-ghexport

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)
…dation and remove `get_val()` API"

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55984187

SS-JIA added a commit that referenced this pull request Apr 11, 2024
…remove `get_val()` API

Pull Request resolved: #2978

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.
ghstack-source-id: 222197446
@exported-using-ghexport

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)
…dation and remove `get_val()` API"

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)

[ghstack-poisoned]
SS-JIA added a commit that referenced this pull request Apr 11, 2024
…remove `get_val()` API

Pull Request resolved: #2978

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.
ghstack-source-id: 222224052
@exported-using-ghexport

Differential Revision: [D55984187](https://our.internmc.facebook.com/intern/diff/D55984187/)
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D55984187

copyrightly pushed a commit to copyrightly/executorch that referenced this pull request Apr 11, 2024
…get_val()` API (pytorch#2978)

Summary:

## Context

Currently when writing operators developers will save a reference to a `vTensor` retrieved from a `ComputeGraph`'s list of `values_` like so:

```
vTensor& vten = graph.get_val(vref).toTensor();
```

However, this is dangerous since if any values are added once the reference has been stored, `values_` which is a `std::vector` may have been resized and therefore have its contents moved, meaning the reference is now invalid.

To protect against this, this changeset introduces the `vTensorPtr` class which is a wrapper around a `vTensor*`.  When constructed, it will increment a counter in the `ComputeGraph` instance, and when destroyed it will decrement the counter. `ComputeGraph` cannot add any values while the counter is not zero.

Since `Value` can be converted to other non-trivial types, this changeset also removes the `get_val` function entirely to guard against unsafe behaviour.
ghstack-source-id: 222224052
exported-using-ghexport

Reviewed By: jorgep31415

Differential Revision: D55984187
@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 76d8513.

@mergennachin mergennachin mentioned this pull request Apr 26, 2024
@SS-JIA SS-JIA deleted the gh/SS-JIA/32/head branch January 24, 2025 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants