Skip to content
This repository was archived by the owner on Dec 28, 2023. It is now read-only.

Commit 3cf1416

Browse files
author
Isaac Poulton
authored
Fix Windows build and set up Windows CI (#6)
* Fix some Windows problems and update README.md * Set up Appveyor * Enable tests in Appveyor * Enable tests in Appveyor * Fix libzmq build on Linux * Fix Cppcheck setup * Add libtorch to PATH in Appveyor
1 parent fc918b5 commit 3cf1416

File tree

21 files changed

+115
-57
lines changed

21 files changed

+115
-57
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
build/
22
.vscode/
3+
.vs/
4+
.pytest_cache/
35
*.pyc

.gitmodules

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
path = lib/spdlog
33
url = git@github.com:gabime/spdlog.git
44
[submodule "lib/msgpack-c"]
5-
path = lib/msgpack-c
5+
path = example/lib/msgpack-c
66
url = git@github.com:msgpack/msgpack-c.git
7+
[submodule "example/lib/libzmq"]
8+
path = example/lib/libzmq
9+
url = git@github.com:Omegastick/libzmq.git

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ set(CMAKE_CXX_STANDARD 17)
1212
list(APPEND CPPCHECK_ARGS
1313
--enable=warning
1414
--std=c++14
15-
--verbose
1615
--force
16+
--verbose
1717
--quiet
1818
--inline-suppr
1919
--error-exitcode=1
2020
--language=c++
2121
--config-exclude=${CMAKE_CURRENT_LIST_DIR}/src/third_party
2222
--config-exclude=${CMAKE_CURRENT_LIST_DIR}/lib
23+
-i${CMAKE_CURRENT_LIST_DIR}/example/lib
2324
--suppressions-list=${CMAKE_CURRENT_LIST_DIR}/CppCheckSuppressions.txt
2425
-I ${CMAKE_CURRENT_LIST_DIR}/src
2526
-I ${CMAKE_CURRENT_LIST_DIR}/include
@@ -54,7 +55,7 @@ endif(CPPRL_BUILD_TESTS)
5455

5556
# Enable all warnings
5657
if(MSVC)
57-
target_compile_options(cpprl PRIVATE /W4 /WX)
58+
target_compile_options(cpprl PRIVATE /W0)
5859
else(MSVC)
5960
target_compile_options(cpprl PRIVATE -Wall -Wextra -pedantic)
6061
endif(MSVC)

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,25 @@ Note: The Gym server and client aren't very well optimized, especially when it c
4444
CMake is used for the build system.
4545
Most dependencies are included as submodules (run `git submodule update --init --recursive` to get them).
4646
Libtorch has to be [installed seperately](https://pytorch.org/cppdocs/installing.html).
47-
The OpenAI Gym client also uses [Zmpqpp](https://github.com/zeromq/zmqpp), which can be installed with `sudo apt-get install libzmqpp-dev`.
47+
48+
### Linux
4849
```bash
4950
cd pytorch-cpp-rl
5051
mkdir build && cd build
5152
cmake ..
5253
make -j4
5354
```
5455

55-
Windows build instructions coming soon.
56+
### Windows
57+
```
58+
cd pytorch-cpp-rl
59+
mkdir build && cd build
60+
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH=C:/path/to/libtorch ..
61+
cmake --build . --config Release
62+
```
63+
Before running, make sure to add `libtorch/lib` to your `PATH` environment variable.
64+
65+
Windows performance is about 75% that of Linux's at the moment. I'm looking into how to speed things up.
5666

5767
## Testing
58-
You can run the tests with `build/cpprl_tests`.
68+
You can run the tests with `build/cpprl_tests` (`build/Release/cpprl_tests.exe` on Windows).

appveyor.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '1.0.0-{build}'
2+
3+
clone_folder: C:\pytorch-cpp-rl
4+
5+
image:
6+
- Visual Studio 2017
7+
8+
platform:
9+
- x64
10+
11+
before_build:
12+
# Load submodules
13+
- sed -i 's/git@github.com:/https:\/\/github.com\//' .gitmodules
14+
- git submodule update --init --recursive
15+
# Install libtorch
16+
- curl -fsS -o libtorch.zip https://download.pytorch.org/libtorch/cpu/libtorch-win-shared-with-deps-latest.zip
17+
- 7z x libtorch.zip -y -oC:\
18+
- set PATH=C:\libtorch\lib;%PATH%
19+
# Run CMake
20+
- mkdir build
21+
- cd build
22+
- cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH=C:\libtorch ..
23+
24+
build_script:
25+
- cmake --build . --config Release
26+
27+
test_script:
28+
- dir
29+
- cd Release
30+
- cpprl_tests.exe

example/CMakeLists.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
add_executable(gym_client gym_client.cpp communicator.cpp)
22

3+
set(LIB_DIR ${CMAKE_CURRENT_LIST_DIR}/lib)
4+
set(CPPZMQ_DIR ${LIB_DIR}/cppzmq)
5+
set(MSGPACK_DIR ${LIB_DIR}/msgpack-c)
6+
set(ZMQ_DIR ${LIB_DIR}/libzmq)
7+
8+
# ZMQ
9+
option(ZMQ_BUILD_TESTS "" OFF)
10+
add_subdirectory(${ZMQ_DIR})
11+
312
target_include_directories(gym_client
413
PRIVATE
514
.
615
../include
7-
../lib/msgpack-c/include
816
../lib/spdlog/include
17+
${CPPZMQ_DIR}
18+
${MSGPACK_DIR}/include
19+
${ZMQ_DIR}/include
920
)
1021

11-
target_link_libraries(gym_client PRIVATE zmq cpprl)
22+
target_link_libraries(gym_client PRIVATE libzmq-static cpprl)

example/communicator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include <memory>
22
#include <string>
33

4-
#include <zmq.hpp>
54
#include <spdlog/spdlog.h>
65

76
#include "communicator.h"
87
#include "requests.h"
8+
#include "third_party/zmq.hpp"
99

1010
namespace gym_client
1111
{

example/communicator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
#include <string>
77

88
#include <msgpack.hpp>
9-
#include <zmq.hpp>
109
#include <spdlog/spdlog.h>
1110
#include <spdlog/fmt/bundled/ostream.h>
1211

1312
#include "requests.h"
13+
#include "third_party/zmq.hpp"
1414

1515
namespace gym_client
1616
{

example/gym_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int main(int argc, char *argv[])
152152
storage.get_masks()[step]);
153153
}
154154
auto actions_tensor = act_result[1].cpu();
155-
long *actions_array = actions_tensor.data<long>();
155+
int64_t *actions_array = actions_tensor.data<int64_t>();
156156
std::vector<std::vector<int>> actions(num_envs);
157157
for (int i = 0; i < num_envs; ++i)
158158
{

example/lib/libzmq

Submodule libzmq added at 7d26319

0 commit comments

Comments
 (0)