Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

[Windows] Bug fixes for MSVC #1042

Closed
wants to merge 11 commits into from
Closed

Conversation

willyd
Copy link
Contributor

@willyd willyd commented Aug 7, 2017

  • file_store_handler.cc: mkdir only accepts one argument and requires inclusion of <direct.h>
  • math.h: macro workaround does not work for integerIsPowerOf2 when prefixed with math namespace.
  • GpuBitonicSort.cuh: use std::integral_constant since nvcc ignores constexpr with MSVC (fixes Compile Error on Windows #997)
  • pool_op_cudnn.cu: undefine IN and OUT macros defined in minwindef.h
  • logging.cc: Prefix glog logging levels with name since MSVC cannot use the abbreviated macros

@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes

@Yangqing
Copy link
Contributor

Yangqing commented Aug 8, 2017

Thanks! We had some glitches in the pull request import process, and it's solved now. Will merge.

@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes

@facebook-github-bot
Copy link
Contributor

@Yangqing has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@@ -6,6 +6,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
#if defined(_MSC_VER)
#include <direct.h>
Copy link

Choose a reason for hiding this comment

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

This is already being included further down on line 19.

Copy link
Contributor

Choose a reason for hiding this comment

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

Kindly rebase and remove this?

@@ -39,9 +39,11 @@ __device__ inline void bitonicSort(K* keys,
// Assume the sort is taking place in shared memory
// static_assert(Power2SortSize * (sizeof(K) + sizeof(V)) < 32768,
// "sort data too large (>32768 bytes)");
static_assert(math::integerIsPowerOf2(Power2SortSize),
static_assert(math::integerIsPowerOf2(
std::integral_constant<int, Power2SortSize>()),
Copy link

Choose a reason for hiding this comment

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

Shouldn't this be std::integral_constant<int, Power2SortSize>()::value?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, this seems to be needed, otherwise build errors.

"sort size must be power of 2");
static_assert(math::integerIsPowerOf2(ThreadsPerBlock),
static_assert(math::integerIsPowerOf2(
std::integral_constant<int, ThreadsPerBlock>()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Here as well

@@ -107,7 +109,8 @@ __device__ inline void warpBitonicSort(K* keys,
// Smaller sorts should use a warp shuffle sort
static_assert(Power2SortSize > kWarpSize,
"sort not large enough");
static_assert(math::integerIsPowerOf2(Power2SortSize),
static_assert(math::integerIsPowerOf2(
std::integral_constant<int, Power2SortSize>()),
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

@Yangqing Yangqing left a comment

Choose a reason for hiding this comment

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

(kindly see comments above)

@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes - changes since last import

@willyd
Copy link
Contributor Author

willyd commented Aug 9, 2017

@Yangqing Thanks for the review. I rebased and removed the requested #include. Plus I fixed a few other issues. One that you might want to look into is the missing CMakeLists.txt file in contrib/opengl.

@Yangqing
Copy link
Contributor

Yangqing commented Aug 9, 2017

Thanks @willyd - yeah, we traced the issue back to our sync script ignoring the CMakeLists.txt files during syncing, and we are fixing it. Let me pull the PR and land it if all checks out.

@facebook-github-bot
Copy link
Contributor

@Yangqing has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes - changes since last import

@Yangqing
Copy link
Contributor

@willyd do you mind rebase to master, and also address the std::integral_constant<int, Power2SortSize>()::value comment?

- file_store_handler.cc: mkdir only accepts one argument and requires inclusion of <direct.h>
- math.h: macro workaround does not work for integerIsPowerOf2 when prefixed with `math` namespace.
- GpuBitonicSort.cuh: use std::integral_constant since nvcc ignores constexpr with MSVC
- pool_op_cudnn.cu: undefine IN and OUT macros defined in minwindef.h
- logging.cc: Prefix glog logging levels with name since MSVC cannot use the abbreviated macros
@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes - changes since last import

@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes - changes since last import

@willyd
Copy link
Contributor Author

willyd commented Aug 10, 2017

@Yangqing Rebase done. Also addressed the ::value comment.

@facebook-github-bot
Copy link
Contributor

@Yangqing has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@harouwu
Copy link
Contributor

harouwu commented Aug 17, 2017

@Yangqing @willyd what is the update on this PR? If it looks good, @willyd would you rebase and we are ready to go?

@willyd
Copy link
Contributor Author

willyd commented Aug 18, 2017

@harouwu I rebased on master last time @Yangqing asked. Since then 69 new commits have been pushed to master, but none of them have conflicting changes as per github. I don't see the need for another rebase, can you please elaborate on why I would need to rebase again?

I am basically waiting for his feedback or for him to merge the PR.

@Callum17
Copy link

Callum17 commented Aug 28, 2017

Did a fresh build from latest master commit @ 799d7cc. Merged with this pull request @ 6784956. Successful compilation with the following change:

Minor issue where MSVC complains about type narrowing conversions in {base}\caffe2\caffe2\layer_norm_op.cu at lines 264 and 294.

264: gscratch_.Resize(std::vector<size_t>{left, right});
should be
264: gscratch_.Resize(std::vector<size_t>{static_cast<size_t>(left), static_cast<size_t>(right)});

294: dstdev_.Resize(vector<size_t>{left, 1});
should be
294: dstdev_.Resize(vector<size_t>{static_cast<size_t>(left), 1});

Looks promising after successful convnet_benchmark runs for AlexNet, OverFeat, Inception.

VGGA model crashes. MLP returns with error:

Traceback (most recent call last):
File "D:\python27\Lib\runpy.py", line 174, in _run_module_as_main
"main", fname, loader, pkg_name)
File "D:\python27\Lib\runpy.py", line 72, in _run_code
exec code in run_globals
File "C:\Users\Callum\Documents\GitHub\caffe2\build\caffe2\experiments\python\convnet_benchmarks.py", line 685, in
Benchmark(model_map[args.model], args)
File "C:\Users\Callum\Documents\GitHub\caffe2\build\caffe2\experiments\python\convnet_benchmarks.py", line 573, in Benchmark
AddParameterUpdate(model)
File "C:\Users\Callum\Documents\GitHub\caffe2\build\caffe2\experiments\python\convnet_benchmarks.py", line 534, in AddParameterUpdate
param_grad = model.param_to_grad[param]
KeyError: BlobReference("fc_1_0_w")

- Narrowing conversions in image_input_op.h, batch_matmul_op.cc and layer_norm_op.cu
- Removed ThreadPool.cc from Windows build since it requires pthread
@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes - changes since last import

@willyd
Copy link
Contributor Author

willyd commented Aug 31, 2017

Gentle reminder for @Yangqing.

I just updated the PR to latest master and fixed the issues mentioned by @Callum17 and some others. Should I squash the commits into a single one?

@pengfei666
Copy link

@willyd This PR is very useful, I have compiled successfully, thanks. Hope it could be merged soon.

@facebook-github-bot
Copy link
Contributor

@willyd updated the pull request - view changes - changes since last import

@willyd
Copy link
Contributor Author

willyd commented Sep 12, 2017

I just added a few more commits to support building with a dynamic runtime library and to support building with vcpkg. I also submitted a PR to vcpkg. If anyone is interested in testing it, it would be much appreciated.

Commit a7ece7c should fix #403.

@willyd
Copy link
Contributor Author

willyd commented Sep 20, 2017

caffe2 (CPU and C++ only) is now available on windows via vcpkg. Installing should be as simple as: vcpkg install caffe2 --triplet x64-windows or vcpkg install caffe2 --triplet x64-windows-static.

@hughsando
Copy link

Not sure if this is the best place to mention this - and it might be covered by the PRs here - some of the other issues I had were.
In caffe2/perfkernels/embedding_lookup_avx2.cc, the CAFFE2_ALIGNED(64) macro should come before the variable declarations, and _mm_prefetch needs a type-cast for the point arg in msvc. This is auto-generated so the fixes will be elsewhere.

@@ -56,6 +56,14 @@ option(USE_ROCKSDB "Use RocksDB" ON)
option(USE_SNPE "Use Qualcomm's SNPE library" OFF)
option(USE_THREADS "Use Threads" ON)
option(USE_ZMQ "Use ZMQ" OFF)
if(MSVC)
if(BUILD_BUILD_SHARED_LIBS)
Copy link

Choose a reason for hiding this comment

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

Shouldn't the variable be 'BUILD_SHARED_LIBS'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aralph You are right! Thanks for pointing out. I must'nt have had enough coffee when I wrote this. When I get back to caffe2 on Windows I will update the PR.

@jimmyoic
Copy link

Hi,
Did anyone else get the problems about link error?
I follow the post (https://research.wmz.ninja/articles/2017/05/build-caffe2-on-windows-10-gpu.html), but I kept getting the error message ( undefined external symbol...)

I tried add the dependencies of cuda library in VS 2015, but it didn't work.

@orionr
Copy link
Contributor

orionr commented Sep 27, 2018

Thank you for your contribution! PyTorch and Caffe2 are now officially merged with the PyTorch 1.0 preview release. Please submit on https://github.com/pytorch/pytorch if this is still an issue over there.

@orionr orionr closed this Sep 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile Error on Windows