Commit Graph

26 Commits

Author SHA1 Message Date
Nikita Shulga
c4d1ff02f8 [Lint] Update clang-format to 19.1.4 (#153889)
All changes other than the one to `tools/linter/adapters/s3_init_config.json` are generated by newer clang-format
Pull Request resolved: https://github.com/pytorch/pytorch/pull/153889
Approved by: https://github.com/cyyever, https://github.com/atalman
2025-05-20 14:12:46 +00:00
Dylan Maloy
a35e73b91f [c10] add #pragma once to leftright (#151710)
Summary: i am getting duplicate defn's when including in my binary that already includes the dispatcher.

Test Plan: CI

Differential Revision: D73237748

Pull Request resolved: https://github.com/pytorch/pytorch/pull/151710
Approved by: https://github.com/georgiaphillips
2025-04-21 23:18:49 +00:00
cyy
dca443835e Enable more readability-redundant checks (#143963)
They are helpful to simplifying code.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/143963
Approved by: https://github.com/albanD
2024-12-30 14:49:33 +00:00
cyy
d558c1a047 Enable cppcoreguidelines-special-member-functions (#139132)
Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/139132
Approved by: https://github.com/sraikund16
2024-11-06 13:42:20 +00:00
PyTorch MergeBot
10d7729333 Revert "Enable cppcoreguidelines-special-member-functions (#139132)"
This reverts commit a9b4989c72.

Reverted https://github.com/pytorch/pytorch/pull/139132 on behalf of https://github.com/ZainRizvi due to Sorry but this fails on trunk. See inductor/test_mkldnn_pattern_matcher.py::TestPatternMatcher::test_smooth_quant_with_int_mm [GH job link](https://github.com/pytorch/pytorch/actions/runs/11699366379/job/32591132460) [HUD commit link](22e89ea2aa) ([comment](https://github.com/pytorch/pytorch/pull/139132#issuecomment-2459743145))
2024-11-06 13:27:42 +00:00
cyy
a9b4989c72 Enable cppcoreguidelines-special-member-functions (#139132)
Fixes #ISSUE_NUMBER

Pull Request resolved: https://github.com/pytorch/pytorch/pull/139132
Approved by: https://github.com/sraikund16
2024-11-06 07:59:09 +00:00
cyy
9a0c217a0a [9/N] Fixes clang-tidy warnings in c10/util/*.h (#116185)
Continued work to clean headers in c10/util.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/116185
Approved by: https://github.com/Skylion007
2023-12-22 09:35:44 +00:00
Benson Ma
66a2600b6a [T153220354] Fix header inclusions in c10 (#1541) (#101846)
Summary:
This is a re-attempt to land the iwyu header changes, by taking the diff from [PR 100304](https://github.com/pytorch/pytorch/pull/100304), and adding the bare minimal changes to make the diff build corectly in the internal builds.

X-link: https://github.com/facebookresearch/pytorch3d/pull/1541

X-link: https://github.com/fairinternal/pytorch3d/pull/44

- Re-work D45769819 to fix header inclusions in c10

Test Plan:
```
buck2 build --no-remote-cache mode/dev-nosan //caffe2/c10/...

buck2 build --no-remote-cache mode/dev-nosan //deeplearning/fbgemm/fbgemm_gpu/...

buck2 build mode/dev-nosan //vision/fair/pytorch3d/pytorch3d:_C
```

Reviewed By: malfet

Differential Revision: D45920611

Pull Request resolved: https://github.com/pytorch/pytorch/pull/101846
Approved by: https://github.com/malfet, https://github.com/Skylion007
2023-05-20 19:35:14 +00:00
PyTorch MergeBot
4eaaa08623 Revert "Fix header inclusions in c10 by iwyu (#100304)"
This reverts commit 6037ee8cc9.

Reverted https://github.com/pytorch/pytorch/pull/100304 on behalf of https://github.com/jeanschmidt due to Breaking meta internal builds and fbgemm builds ([comment](https://github.com/pytorch/pytorch/pull/100304#issuecomment-1543919257))
2023-05-11 12:37:35 +00:00
cyy
6037ee8cc9 Fix header inclusions in c10 by iwyu (#100304)
This work introduces include-what-you-use  support for c10 by a CMake option defaulting to off. We also remove some unused header inclusions and  fix a trivial inclusion error.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/100304
Approved by: https://github.com/ezyang
2023-05-11 05:19:42 +00:00
PyTorch MergeBot
3271413e74 Revert "Fix header inclusions in c10 by iwyu (#100304)"
This reverts commit 39ec5fa722.

Reverted https://github.com/pytorch/pytorch/pull/100304 on behalf of https://github.com/huydhn due to Sorry for reverting your PR, it is almost there but fails on Windows 39ec5fa722, which is in unstable mode after https://github.com/pytorch/pytorch/pull/100548 ([comment](https://github.com/pytorch/pytorch/pull/100304#issuecomment-1542975714))
2023-05-11 00:37:32 +00:00
cyy
39ec5fa722 Fix header inclusions in c10 by iwyu (#100304)
This work introduces include-what-you-use  support for c10 by a CMake option defaulting to off. We also remove some unused header inclusions and  fix a trivial inclusion error.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/100304
Approved by: https://github.com/ezyang
2023-05-10 15:42:43 +00:00
Lukas N Wirz
5af48581b5 In order to make pytorch headers consumable from cpp20 code bases, … (#79985)
… all instances of std::result_of and std:result_of_t are conditionally replaced by std::invoke_result and std::invoke_result_t if __cpp_lib_is_invocable >= 201703L.  std::invoke_result was only introduced in c++17, so it should probably not be required yet.

Fixes #71657  and a small part of #69290

Tested on Centos 7 / gcc11 + a private project that requires cpp20.

I think the main questions to check by a maintainer are,
- whether my choices of preprocessor blocks are appropriate
- whether there are any very subtle differences between std::result_of and std::invoke_result that I have missed
- whether in any of the replacements  the 'new' side can/should be simplified further

Pull Request resolved: https://github.com/pytorch/pytorch/pull/79985
Approved by: https://github.com/ezyang
2022-07-04 20:14:36 +00:00
Dhruv Matani
977cc480a9 [PyTorch] Use c10::Synchronized<T> in RWSafeLeftRightWrapper (#74109)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74109

As the title says - to prevent unintentional usage of the `data_` member without the lock held.
ghstack-source-id: 151471742

Test Plan:
Build using:

```
buck build -c pt.disable_per_op_profiling=0 -c pt.enable_record_kernel_dtype=1 --show-output xplat/caffe2/fb/model_tracer:model_tracer
```

Reviewed By: malfet

Differential Revision: D34822913

fbshipit-source-id: 956fbe78956cf556fd6c8481b910acf557fbe608
(cherry picked from commit 9e4e3115f8e92bc4834179902d7ca79b3f97d985)
2022-03-16 16:18:36 +00:00
Michael Suo
b65adf84f3 Revert D34645508: [PyTorch] Use c10::Synchronized<T> in RWSafeLeftRightWrapper
Test Plan: revert-hammer

Differential Revision:
D34645508 (62ff23db6b)

Original commit changeset: effa8064f925

Original Phabricator Diff: D34645508 (62ff23db6b)

fbshipit-source-id: 4f9bfc79c06a626fccc5cad9faeaa33e00f4f718
(cherry picked from commit ed51c6cd07edb641d2b5712f4ea3a291a772a2b7)
2022-03-11 15:38:11 +00:00
Dhruv Matani
62ff23db6b [PyTorch] Use c10::Synchronized<T> in RWSafeLeftRightWrapper (#74061)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/74061

As the title says - to prevent unintentional usage of the `data_` member without the lock held.
ghstack-source-id: 150555298

Test Plan:
Build using:

```
buck build -c pt.disable_per_op_profiling=0 -c pt.enable_record_kernel_dtype=1 --show-output xplat/caffe2/fb/model_tracer:model_tracer
```

Reviewed By: JacobSzwejbka

Differential Revision: D34645508

fbshipit-source-id: effa8064f92550cb4fdd078fd85887751d8f849d
(cherry picked from commit 377f85907c14c0f2f0bd19068ee23cf48df9e17b)
2022-03-11 07:59:50 +00:00
Dhruv Matani
cb2a41e508 [PyTorch Edge] Don't use LeftRight in mobile (#66064)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/66064

The only place this is used seems to be in the dispatcher for `operatorLookupTable_`. Disarming `LeftRight` disarms it for this one use case.

This should make .so loading faster, and also reduce memory consumption since `LeftRight<T>` does 2 writes for every write. I'd like to get a thorough review from reviewers for this diff since I want to make sure that initialization of stuff that writes into the dispatcher isn't going to happen on multiple threads for on-device use.

Created a new class named `LeftRightNoOpWrapper<T>` for use in mobile builds.

### Why is LeftRight<T> slow?

It maintains 2 copies of each data structure `T` to be able to keep reads quick. Every write goes to both data structures, which means that writes that 2x and memory overhead is also 2x

### Why is this safe for mobile builds?

1. .so loading never happens concurrently with model execution
2. Custom ops are loaded during .so load - initializers are all run serially
3. I don't see any threads being spawned from the global schema and kernel initializers

After discussing with dreiss, it seems like there could be rare cases in OSS apps or internal Android/iOS apps where a `.so` or `dylib` is loaded after the PT runtime is loaded, and this load happens concurrently with an in-progress inference run, which is looking up the operator table in the dispatcher.

To avoid crashes there, it seems reasonable to use the RW lock, since I don't expect any contention 99.9% of the time.

When registering operators, everything is serial so only one thread will ever hold the lock. The next time it needs the lock, it will have already released it.
During inference runs, only one thread will ask for the shared lock unless multiple concurrent inferences are in progress. Even in that case, they will all be able to simultaneously get the Read lock.

Test Plan: Build and generate a local build of the iOS app to test.

Reviewed By: swolchok

Differential Revision: D31352346

fbshipit-source-id: c3f12454de3dbd7b421a6057d561e9373ef5bf98
2021-11-09 21:49:45 -08:00
Scott Wolchok
44cc873fba [PyTorch] Autoformat c10 (#56830)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/56830

Opt into formatting on GitHub and format everything. This is a trial run before turning on formatting for more and eventually all of the codebase.

Test Plan: CI

Reviewed By: zertosh

Differential Revision: D27979080

fbshipit-source-id: a80f0c48691c08ae8ca0af06377b87e6a2351151
2021-04-30 21:23:28 -07:00
Edward Yang
36ebd0f65d Improve LeftRight documentation (#57164)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/57164

Give some more indications about its performance characteristics
and when it is appropriate to use.

Signed-off-by: Edward Z. Yang <ezyang@fb.com>

Test Plan: Imported from OSS

Reviewed By: zou3519

Differential Revision: D28064685

Pulled By: ezyang

fbshipit-source-id: dbf5e041088d7921db2111d287feb9079466f1b5
2021-04-29 08:44:27 -07:00
Sebastian Messmer
2a294aace6 Remove memory ordering from LeftRight (#31026)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/31026

This is error prone and probably wrong. Since we don't use LeftRight on the hot path anymore, let's remove this.
ghstack-source-id: 96369644

Test Plan: none

Differential Revision: D18902165

fbshipit-source-id: 7b9478cd7cc071f403d75da20c7c889c27248b5c
2020-01-08 08:59:30 -08:00
Sebastian Messmer
3990e9d1ca Improve performance of LeftRight::read() (#30282)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/30282

The atomic increment/decrements in LeftRight::read() were measurable in perf benchmarks. Let's improve their perf.
ghstack-source-id: 94443230

Test Plan: unit tests, perf benchmarks

Differential Revision: D18650228

fbshipit-source-id: d184ce8288510ab178e7c7da73562609d1ca3c9f
2019-11-23 15:25:13 -08:00
Sebastian Messmer
a4fa167878 Optimize LeftRight and either (#25133)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/25133

This is driven by benchmarks I did for moving ATen ops to the c10 operator library.
Improvements:
 - tell the compiler that the error cases are unlikely so it can optimize code better
 - optimize cache layout of LeftRight.
ghstack-source-id: 88907294

Test Plan: unit tests

Differential Revision: D16998010

fbshipit-source-id: 0e3cbff0a4983133a4447ec093444f5d85dd61d6
2019-08-27 18:33:29 -07:00
Sebastian Messmer
ba84ad0d97 LeftRight works for classes without default constructors (#19775)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/19775

-

Reviewed By: dzhulgakov

Differential Revision: D15090319

fbshipit-source-id: e80865975970400c3db24bba4af4327105f3b9b2
2019-04-30 16:34:15 -07:00
Sebastian Messmer
e97da36cbb Explicitly disable copy&move on LeftRight (#19774)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/19774

see in-source comment

Reviewed By: dzhulgakov

Differential Revision: D15090320

fbshipit-source-id: ae9ba5b5df7115c2b1c275e384030063dbbf8f1a
2019-04-30 16:34:12 -07:00
Sebastian Messmer
4c16ea93d1 Improve LeftRight (#16524)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16524

- Make it exception safe. When an exception happens during write, the old state is recovered.
- Use RAII instead of try/catch to increment counters in readers. This is more readable, and it also makes it work with reader closures that return void, which previously didn't work because the reader return value was stored on the stack.
- Assert there's no reads or writes happening when it's destructed to avoid destruction race conditions
- Explain the algorithm in detail in comments
- Add test cases

Reviewed By: ezyang

Differential Revision: D13866609

fbshipit-source-id: 01306a282a3f555569caa13d8041486f960d00e2
2019-02-02 16:33:27 -08:00
Sebastian Messmer
b7c9575c93 Move LeftRight to c10/util
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/13526

Reviewed By: ezyang

Differential Revision: D12912241

fbshipit-source-id: 70525a9b20daa8aae623d0cb4002acecc34b1932
2018-11-05 17:39:16 -08:00