@@ -269,8 +269,7 @@ than Linux, which are worth keeping in mind when fixing these problems.
269
269
3 . If you have a Windows box (we have a few on EC2 which you can request access to) and
270
270
you want to run the build, the easiest way is to just run ` .jenkins/pytorch/win-build.sh ` .
271
271
If you need to rebuild, run ` REBUILD=1 .jenkins/pytorch/win-build.sh ` (this will avoid
272
- blowing away your Conda environment.) I recommend opening ` cmd.exe ` , and then running
273
- ` bash ` to work in a bash shell (which will make various Linux commands available.)
272
+ blowing away your Conda environment.)
274
273
275
274
Even if you don't know anything about MSVC, you can use cmake to build simple programs on
276
275
Windows; this can be helpful if you want to learn more about some peculiar linking behavior
@@ -296,6 +295,53 @@ cmake ..
296
295
cmake --build .
297
296
```
298
297
298
+ ### Known MSVC (and MSVC with NVCC) bugs
299
+
300
+ The PyTorch codebase sometimes likes to use exciting C++ features, and
301
+ these exciting features lead to exciting bugs in Windows compilers.
302
+ To add insult to injury, the error messages will often not tell you
303
+ which line of code actually induced the erroring template instantiation.
304
+
305
+ I've found the most effective way to debug these problems is to
306
+ carefully read over diffs, keeping in mind known bugs in MSVC/NVCC.
307
+ Here are a few well known pitfalls and workarounds:
308
+
309
+ * This is not actually a bug per se, but in general, code generated by MSVC
310
+ is more sensitive to memory errors; you may have written some code
311
+ that does a use-after-free or stack overflows; on Linux the code
312
+ might work, but on Windows your program will crash. ASAN may not
313
+ catch all of these problems: stay vigilant to the possibility that
314
+ your crash is due to a real memory problem.
315
+
316
+ * (NVCC) ` at::optional ` does not work when used from device code. Don't use
317
+ it from kernels. Upstream issue: https://github.com/akrzemi1/Optional/issues/58
318
+ and our local issue #10329 .
319
+
320
+ * ` constexpr ` generally works less well on MSVC.
321
+
322
+ * The idiom ` static_assert(f() == f()) ` to test if ` f ` is constexpr
323
+ does not work; you'll get "error C2131: expression did not evaluate
324
+ to a constant". Don't use these asserts on Windows.
325
+ (Example: ` aten/src/ATen/core/intrusive_ptr.h ` )
326
+
327
+ * (NVCC) Code you access inside a ` static_assert ` will eagerly be
328
+ evaluated as if it were device code, and so you might get an error
329
+ that the code is "not accessible".
330
+
331
+ ```
332
+ class A {
333
+ static A singleton_;
334
+ static constexpr inline A* singleton() {
335
+ return &singleton_;
336
+ }
337
+ };
338
+ static_assert(std::is_same(A*, decltype(A::singelton()))::value, "hmm");
339
+ ```
340
+
341
+ * The compiler will run out of heap if you attempt to compile files that
342
+ are too large. Splitting such files into separate files helps.
343
+ (Example: ` THTensorMath ` , ` THTensorMoreMath ` , ` THTensorEvenMoreMath ` .)
344
+
299
345
## Caffe2 notes
300
346
301
347
In 2018, we merged Caffe2 into the PyTorch source repository. While the
0 commit comments