Skip to content

Commit 07611ea

Browse files
authored
Merge pull request #6 from stotiks/windows-fury-road
Windows fury road
2 parents 3b553d3 + 8d88fef commit 07611ea

20 files changed

+1302
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/build
22
*.out
33
*.tmp
4+
*.bak

CMakeLists.txt

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ project(chia-plotter C CXX ASM)
44

55
add_subdirectory(lib/bls-signatures)
66

7-
find_package(Threads REQUIRED)
87

9-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
8+
if (MSVC)
9+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
10+
else()
11+
find_package(Threads REQUIRED)
12+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
13+
endif()
1014

1115
set(BLAKE3_PATH lib/BLAKE3/c)
1216
set(FSE_PATH lib/FSE/lib)
@@ -25,10 +29,10 @@ set(BLAKE3_SRC
2529
${BLAKE3_PATH}/blake3.c
2630
${BLAKE3_PATH}/blake3_portable.c
2731
${BLAKE3_PATH}/blake3_dispatch.c
28-
${BLAKE3_PATH}/blake3_avx2_x86-64_windows_gnu.S
29-
${BLAKE3_PATH}/blake3_sse41_x86-64_windows_gnu.S
30-
${BLAKE3_PATH}/blake3_avx512_x86-64_windows_gnu.S
31-
${BLAKE3_PATH}/blake3_sse2_x86-64_windows_gnu.S
32+
${BLAKE3_PATH}/blake3_avx2.c
33+
${BLAKE3_PATH}/blake3_avx512.c
34+
${BLAKE3_PATH}/blake3_sse2.c
35+
${BLAKE3_PATH}/blake3_sse41.c
3236
)
3337
ELSEIF(OSX_NATIVE_ARCHITECTURE STREQUAL "arm64")
3438
set(BLAKE3_SRC
@@ -63,8 +67,11 @@ add_library(chia_plotter STATIC
6367
lib/chacha8.c
6468
src/settings.cpp
6569
)
66-
67-
target_link_libraries(chia_plotter blake3 fse Threads::Threads)
70+
if (MSVC)
71+
target_link_libraries(chia_plotter blake3 fse)
72+
else()
73+
target_link_libraries(chia_plotter blake3 fse Threads::Threads)
74+
endif()
6875

6976
add_executable(test_copy test/test_copy.cpp)
7077
add_executable(test_disk_sort test/test_disk_sort.cpp)
@@ -78,6 +85,24 @@ add_executable(check_phase_1 test/check_phase_1.cpp)
7885

7986
add_executable(chia_plot src/chia_plot.cpp)
8087

88+
if (MSVC)
89+
90+
add_library(uint128 STATIC uint128_t/uint128_t.cpp)
91+
target_include_directories(uint128 PUBLIC uint128_t)
92+
93+
target_link_libraries(test_copy chia_plotter)
94+
target_link_libraries(test_disk_sort chia_plotter uint128)
95+
target_link_libraries(test_phase_1 chia_plotter uint128)
96+
target_link_libraries(test_phase_2 chia_plotter uint128)
97+
target_link_libraries(test_phase_3 chia_plotter uint128)
98+
target_link_libraries(test_phase_4 chia_plotter uint128)
99+
target_link_libraries(check_phase_1 chia_plotter uint128)
100+
101+
target_link_libraries(chia_plot chia_plotter bls uint128)
102+
set_target_properties(chia_plot PROPERTIES LINK_OPTIONS -NODEFAULTLIB:LIBCMT)
103+
104+
else()
105+
81106
target_link_libraries(test_copy chia_plotter)
82107
target_link_libraries(test_disk_sort chia_plotter)
83108

@@ -89,3 +114,5 @@ target_link_libraries(test_phase_4 chia_plotter)
89114
target_link_libraries(check_phase_1 chia_plotter)
90115

91116
target_link_libraries(chia_plot chia_plotter bls)
117+
118+
endif()

include/chia/DiskSort.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef INCLUDE_CHIA_DISKSORT_HPP_
99
#define INCLUDE_CHIA_DISKSORT_HPP_
1010

11+
#include <chia/stdiox.hpp>
1112
#include <chia/DiskSort.h>
1213
#include <chia/util.hpp>
1314

@@ -22,7 +23,7 @@ void DiskSort<T, Key>::bucket_t::open(const char* mode)
2223
if(file) {
2324
fclose(file);
2425
}
25-
file = fopen(file_name.c_str(), mode);
26+
file = FOPEN(file_name.c_str(), mode);
2627
if(!file) {
2728
throw std::runtime_error("fopen() failed");
2829
}

include/chia/DiskTable.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef INCLUDE_CHIA_DISKTABLE_H_
99
#define INCLUDE_CHIA_DISKTABLE_H_
1010

11+
#include <chia/stdiox.hpp>
1112
#include <chia/buffer.h>
1213
#include <chia/ThreadPool.h>
1314

@@ -34,7 +35,7 @@ class DiskTable {
3435
num_entries(num_entries)
3536
{
3637
if(!num_entries) {
37-
file_out = fopen(file_name.c_str(), "wb");
38+
file_out = FOPEN(file_name.c_str(), "wb");
3839
}
3940
}
4041

@@ -68,7 +69,7 @@ class DiskTable {
6869

6970
for(size_t i = 0; i < pool.num_threads(); ++i)
7071
{
71-
FILE* file = fopen(file_name.c_str(), "rb");
72+
FILE* file = FOPEN(file_name.c_str(), "rb");
7273
if(!file) {
7374
throw std::runtime_error("fopen() failed");
7475
}
@@ -120,7 +121,7 @@ class DiskTable {
120121
std::pair<std::vector<T>, size_t>& out,
121122
local_t& local) const
122123
{
123-
if(int err = fseek(local.file, param.first * T::disk_size, SEEK_SET)) {
124+
if(int err = FSEEK(local.file, param.first * T::disk_size, SEEK_SET)) {
124125
throw std::runtime_error("fseek() failed");
125126
}
126127
if(fread(local.buffer, T::disk_size, param.second, local.file) != param.second) {

include/chia/copy.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef INCLUDE_CHIA_COPY_H_
99
#define INCLUDE_CHIA_COPY_H_
1010

11+
#include <chia/stdiox.hpp>
1112
#include <chia/settings.h>
1213

1314
#include <string>
@@ -21,11 +22,11 @@
2122
inline
2223
uint64_t copy_file(const std::string& src_path, const std::string& dst_path)
2324
{
24-
FILE* src = fopen(src_path.c_str(), "rb");
25+
FILE* src = FOPEN(src_path.c_str(), "rb");
2526
if(!src) {
2627
throw std::runtime_error("fopen() failed");
2728
}
28-
FILE* dst = fopen(dst_path.c_str(), "wb");
29+
FILE* dst = FOPEN(dst_path.c_str(), "wb");
2930
if(!dst) {
3031
throw std::runtime_error("fopen() failed");
3132
}

include/chia/phase3.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef INCLUDE_CHIA_PHASE3_HPP_
99
#define INCLUDE_CHIA_PHASE3_HPP_
1010

11+
#include <chia/stdiox.hpp>
1112
#include <chia/chia.h>
1213
#include <chia/phase3.h>
1314
#include <chia/encoding.hpp>
@@ -458,7 +459,7 @@ void compute( phase2::output_t& input, output_t& out,
458459
out.params = input.params;
459460
out.plot_file_name = tmp_dir + plot_name + ".plot.tmp";
460461

461-
FILE* plot_file = fopen(out.plot_file_name.c_str(), "wb");
462+
FILE* plot_file = FOPEN(out.plot_file_name.c_str(), "wb");
462463
if(!plot_file) {
463464
throw std::runtime_error("fopen() failed");
464465
}

include/chia/phase4.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created on: Jun 3, 2021
55
* Author: mad
66
*/
7-
7+
#include <chia/stdiox.hpp>
88
#include <chia/phase4.h>
99
#include <chia/DiskSort.hpp>
1010

@@ -235,7 +235,7 @@ void compute( const phase3::output_t& input, output_t& out,
235235
{
236236
const auto total_begin = get_wall_time_micros();
237237

238-
FILE* plot_file = fopen(input.plot_file_name.c_str(), "rb+");
238+
FILE* plot_file = FOPEN(input.plot_file_name.c_str(), "rb+");
239239
if(!plot_file) {
240240
throw std::runtime_error("fopen() failed");
241241
}

include/chia/stdiox.hpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
#ifndef INCLUDE_CHIA_STDIOX_HPP_
3+
#define INCLUDE_CHIA_STDIOX_HPP_
4+
#include <stdio.h>
5+
6+
#ifdef _WIN32
7+
#define FOPEN(...) _wfopenX(__VA_ARGS__)
8+
#define FSEEK(...) _fseeki64(__VA_ARGS__)
9+
10+
#include <locale>
11+
#include <codecvt>
12+
#include <string>
13+
#include <iostream>
14+
15+
inline FILE* _wfopenX(char const* _FileName, char const* _Mode) {
16+
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
17+
std::wstring w_FileName = converter.from_bytes(_FileName);
18+
std::wstring w_Mode = converter.from_bytes(_Mode);
19+
20+
FILE* file = _wfopen(w_FileName.c_str(), w_Mode.c_str());
21+
22+
23+
return file;
24+
}
25+
26+
#else
27+
#define FOPEN(...) fopen(__VA_ARGS__)
28+
#define FSEEK(...) fseek(__VA_ARGS__)
29+
#endif
30+
31+
32+
#endif // INCLUDE_CHIA_STDIOX_HPP_

include/chia/util.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#ifndef SRC_CPP_UTIL_HPP_
1616
#define SRC_CPP_UTIL_HPP_
1717

18+
#include <chia/stdiox.hpp>
1819
#include <cassert>
1920
#include <chrono>
2021
#include <cstring>
@@ -419,7 +420,7 @@ std::ifstream::pos_type get_file_size(const char* file_name)
419420

420421
inline
421422
void fseek_set(FILE* file, uint64_t offset) {
422-
if(fseek(file, offset, SEEK_SET)) {
423+
if(FSEEK(file, offset, SEEK_SET)) {
423424
throw std::runtime_error("fseek() failed");
424425
}
425426
}

src/chia_plot.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created on: Jun 5, 2021
55
* Author: mad
66
*/
7-
7+
#include <chia/stdiox.hpp>
88
#include <chia/phase1.hpp>
99
#include <chia/phase2.hpp>
1010
#include <chia/phase3.hpp>
@@ -108,6 +108,12 @@ phase4::output_t create_plot( const int num_threads,
108108

109109
int main(int argc, char** argv)
110110
{
111+
112+
#ifdef _WIN32
113+
// the following line increases the number of open simultaneous files
114+
int newmaxstdio = _setmaxstdio(8192);
115+
#endif
116+
111117
cxxopts::Options options("chia_plot",
112118
"Multi-threaded pipelined Chia k32 plotter.\n\n"
113119
"For <poolkey> and <farmerkey> see output of `chia keys show`.\n"
@@ -197,6 +203,7 @@ int main(int argc, char** argv)
197203
std::cout << "Invalid <buckets> parameter: 2^" << log_num_buckets << " (supported: 2^[4..16])" << std::endl;
198204
return -2;
199205
}
206+
200207
{
201208
const std::string path = tmp_dir + ".chia_plot_tmp";
202209
if(auto file = fopen(path.c_str(), "wb")) {

0 commit comments

Comments
 (0)