Skip to content

Commit

Permalink
Merge pull request #6 from stotiks/windows-fury-road
Browse files Browse the repository at this point in the history
Windows fury road
  • Loading branch information
stotiks committed Jun 10, 2021
2 parents 3b553d3 + 8d88fef commit 07611ea
Show file tree
Hide file tree
Showing 20 changed files with 1,302 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
/build
*.out
*.tmp
*.bak
43 changes: 35 additions & 8 deletions CMakeLists.txt
Expand Up @@ -4,9 +4,13 @@ project(chia-plotter C CXX ASM)

add_subdirectory(lib/bls-signatures)

find_package(Threads REQUIRED)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
else()
find_package(Threads REQUIRED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-function")
endif()

set(BLAKE3_PATH lib/BLAKE3/c)
set(FSE_PATH lib/FSE/lib)
Expand All @@ -25,10 +29,10 @@ set(BLAKE3_SRC
${BLAKE3_PATH}/blake3.c
${BLAKE3_PATH}/blake3_portable.c
${BLAKE3_PATH}/blake3_dispatch.c
${BLAKE3_PATH}/blake3_avx2_x86-64_windows_gnu.S
${BLAKE3_PATH}/blake3_sse41_x86-64_windows_gnu.S
${BLAKE3_PATH}/blake3_avx512_x86-64_windows_gnu.S
${BLAKE3_PATH}/blake3_sse2_x86-64_windows_gnu.S
${BLAKE3_PATH}/blake3_avx2.c
${BLAKE3_PATH}/blake3_avx512.c
${BLAKE3_PATH}/blake3_sse2.c
${BLAKE3_PATH}/blake3_sse41.c
)
ELSEIF(OSX_NATIVE_ARCHITECTURE STREQUAL "arm64")
set(BLAKE3_SRC
Expand Down Expand Up @@ -63,8 +67,11 @@ add_library(chia_plotter STATIC
lib/chacha8.c
src/settings.cpp
)

target_link_libraries(chia_plotter blake3 fse Threads::Threads)
if (MSVC)
target_link_libraries(chia_plotter blake3 fse)
else()
target_link_libraries(chia_plotter blake3 fse Threads::Threads)
endif()

add_executable(test_copy test/test_copy.cpp)
add_executable(test_disk_sort test/test_disk_sort.cpp)
Expand All @@ -78,6 +85,24 @@ add_executable(check_phase_1 test/check_phase_1.cpp)

add_executable(chia_plot src/chia_plot.cpp)

if (MSVC)

add_library(uint128 STATIC uint128_t/uint128_t.cpp)
target_include_directories(uint128 PUBLIC uint128_t)

target_link_libraries(test_copy chia_plotter)
target_link_libraries(test_disk_sort chia_plotter uint128)
target_link_libraries(test_phase_1 chia_plotter uint128)
target_link_libraries(test_phase_2 chia_plotter uint128)
target_link_libraries(test_phase_3 chia_plotter uint128)
target_link_libraries(test_phase_4 chia_plotter uint128)
target_link_libraries(check_phase_1 chia_plotter uint128)

target_link_libraries(chia_plot chia_plotter bls uint128)
set_target_properties(chia_plot PROPERTIES LINK_OPTIONS -NODEFAULTLIB:LIBCMT)

else()

target_link_libraries(test_copy chia_plotter)
target_link_libraries(test_disk_sort chia_plotter)

Expand All @@ -89,3 +114,5 @@ target_link_libraries(test_phase_4 chia_plotter)
target_link_libraries(check_phase_1 chia_plotter)

target_link_libraries(chia_plot chia_plotter bls)

endif()
3 changes: 2 additions & 1 deletion include/chia/DiskSort.hpp
Expand Up @@ -8,6 +8,7 @@
#ifndef INCLUDE_CHIA_DISKSORT_HPP_
#define INCLUDE_CHIA_DISKSORT_HPP_

#include <chia/stdiox.hpp>
#include <chia/DiskSort.h>
#include <chia/util.hpp>

Expand All @@ -22,7 +23,7 @@ void DiskSort<T, Key>::bucket_t::open(const char* mode)
if(file) {
fclose(file);
}
file = fopen(file_name.c_str(), mode);
file = FOPEN(file_name.c_str(), mode);
if(!file) {
throw std::runtime_error("fopen() failed");
}
Expand Down
7 changes: 4 additions & 3 deletions include/chia/DiskTable.h
Expand Up @@ -8,6 +8,7 @@
#ifndef INCLUDE_CHIA_DISKTABLE_H_
#define INCLUDE_CHIA_DISKTABLE_H_

#include <chia/stdiox.hpp>
#include <chia/buffer.h>
#include <chia/ThreadPool.h>

Expand All @@ -34,7 +35,7 @@ class DiskTable {
num_entries(num_entries)
{
if(!num_entries) {
file_out = fopen(file_name.c_str(), "wb");
file_out = FOPEN(file_name.c_str(), "wb");
}
}

Expand Down Expand Up @@ -68,7 +69,7 @@ class DiskTable {

for(size_t i = 0; i < pool.num_threads(); ++i)
{
FILE* file = fopen(file_name.c_str(), "rb");
FILE* file = FOPEN(file_name.c_str(), "rb");
if(!file) {
throw std::runtime_error("fopen() failed");
}
Expand Down Expand Up @@ -120,7 +121,7 @@ class DiskTable {
std::pair<std::vector<T>, size_t>& out,
local_t& local) const
{
if(int err = fseek(local.file, param.first * T::disk_size, SEEK_SET)) {
if(int err = FSEEK(local.file, param.first * T::disk_size, SEEK_SET)) {
throw std::runtime_error("fseek() failed");
}
if(fread(local.buffer, T::disk_size, param.second, local.file) != param.second) {
Expand Down
5 changes: 3 additions & 2 deletions include/chia/copy.h
Expand Up @@ -8,6 +8,7 @@
#ifndef INCLUDE_CHIA_COPY_H_
#define INCLUDE_CHIA_COPY_H_

#include <chia/stdiox.hpp>
#include <chia/settings.h>

#include <string>
Expand All @@ -21,11 +22,11 @@
inline
uint64_t copy_file(const std::string& src_path, const std::string& dst_path)
{
FILE* src = fopen(src_path.c_str(), "rb");
FILE* src = FOPEN(src_path.c_str(), "rb");
if(!src) {
throw std::runtime_error("fopen() failed");
}
FILE* dst = fopen(dst_path.c_str(), "wb");
FILE* dst = FOPEN(dst_path.c_str(), "wb");
if(!dst) {
throw std::runtime_error("fopen() failed");
}
Expand Down
3 changes: 2 additions & 1 deletion include/chia/phase3.hpp
Expand Up @@ -8,6 +8,7 @@
#ifndef INCLUDE_CHIA_PHASE3_HPP_
#define INCLUDE_CHIA_PHASE3_HPP_

#include <chia/stdiox.hpp>
#include <chia/chia.h>
#include <chia/phase3.h>
#include <chia/encoding.hpp>
Expand Down Expand Up @@ -458,7 +459,7 @@ void compute( phase2::output_t& input, output_t& out,
out.params = input.params;
out.plot_file_name = tmp_dir + plot_name + ".plot.tmp";

FILE* plot_file = fopen(out.plot_file_name.c_str(), "wb");
FILE* plot_file = FOPEN(out.plot_file_name.c_str(), "wb");
if(!plot_file) {
throw std::runtime_error("fopen() failed");
}
Expand Down
4 changes: 2 additions & 2 deletions include/chia/phase4.hpp
Expand Up @@ -4,7 +4,7 @@
* Created on: Jun 3, 2021
* Author: mad
*/

#include <chia/stdiox.hpp>
#include <chia/phase4.h>
#include <chia/DiskSort.hpp>

Expand Down Expand Up @@ -235,7 +235,7 @@ void compute( const phase3::output_t& input, output_t& out,
{
const auto total_begin = get_wall_time_micros();

FILE* plot_file = fopen(input.plot_file_name.c_str(), "rb+");
FILE* plot_file = FOPEN(input.plot_file_name.c_str(), "rb+");
if(!plot_file) {
throw std::runtime_error("fopen() failed");
}
Expand Down
32 changes: 32 additions & 0 deletions include/chia/stdiox.hpp
@@ -0,0 +1,32 @@

#ifndef INCLUDE_CHIA_STDIOX_HPP_
#define INCLUDE_CHIA_STDIOX_HPP_
#include <stdio.h>

#ifdef _WIN32
#define FOPEN(...) _wfopenX(__VA_ARGS__)
#define FSEEK(...) _fseeki64(__VA_ARGS__)

#include <locale>
#include <codecvt>
#include <string>
#include <iostream>

inline FILE* _wfopenX(char const* _FileName, char const* _Mode) {
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring w_FileName = converter.from_bytes(_FileName);
std::wstring w_Mode = converter.from_bytes(_Mode);

FILE* file = _wfopen(w_FileName.c_str(), w_Mode.c_str());


return file;
}

#else
#define FOPEN(...) fopen(__VA_ARGS__)
#define FSEEK(...) fseek(__VA_ARGS__)
#endif


#endif // INCLUDE_CHIA_STDIOX_HPP_
3 changes: 2 additions & 1 deletion include/chia/util.hpp
Expand Up @@ -15,6 +15,7 @@
#ifndef SRC_CPP_UTIL_HPP_
#define SRC_CPP_UTIL_HPP_

#include <chia/stdiox.hpp>
#include <cassert>
#include <chrono>
#include <cstring>
Expand Down Expand Up @@ -419,7 +420,7 @@ std::ifstream::pos_type get_file_size(const char* file_name)

inline
void fseek_set(FILE* file, uint64_t offset) {
if(fseek(file, offset, SEEK_SET)) {
if(FSEEK(file, offset, SEEK_SET)) {
throw std::runtime_error("fseek() failed");
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/chia_plot.cpp
Expand Up @@ -4,7 +4,7 @@
* Created on: Jun 5, 2021
* Author: mad
*/

#include <chia/stdiox.hpp>
#include <chia/phase1.hpp>
#include <chia/phase2.hpp>
#include <chia/phase3.hpp>
Expand Down Expand Up @@ -108,6 +108,12 @@ phase4::output_t create_plot( const int num_threads,

int main(int argc, char** argv)
{

#ifdef _WIN32
// the following line increases the number of open simultaneous files
int newmaxstdio = _setmaxstdio(8192);
#endif

cxxopts::Options options("chia_plot",
"Multi-threaded pipelined Chia k32 plotter.\n\n"
"For <poolkey> and <farmerkey> see output of `chia keys show`.\n"
Expand Down Expand Up @@ -197,6 +203,7 @@ int main(int argc, char** argv)
std::cout << "Invalid <buckets> parameter: 2^" << log_num_buckets << " (supported: 2^[4..16])" << std::endl;
return -2;
}

{
const std::string path = tmp_dir + ".chia_plot_tmp";
if(auto file = fopen(path.c_str(), "wb")) {
Expand Down
12 changes: 9 additions & 3 deletions test/test_phase_3.cpp
Expand Up @@ -4,7 +4,7 @@
* Created on: May 30, 2021
* Author: mad
*/

#include <chia/stdiox.hpp>
#include <chia/phase3.hpp>
#include <chia/DiskSort.hpp>
#include <chia/DiskTable.h>
Expand All @@ -16,6 +16,12 @@ using namespace phase3;

int main(int argc, char** argv)
{

#ifdef _WIN32
// the following line increases the number of open simultaneous files
int newmaxstdio = _setmaxstdio(8192);
#endif

const int num_threads = argc > 1 ? atoi(argv[1]) : 4;
const int log_num_buckets = argc > 2 ? atoi(argv[2]) : 7;

Expand All @@ -36,15 +42,15 @@ int main(int argc, char** argv)

bitfield bitfield_1(table_1.num_entries);
{
FILE* file = fopen("test.p2.bitfield1.tmp", "rb");
FILE* file = FOPEN("test.p2.bitfield1.tmp", "rb");
if(!file) {
throw std::runtime_error("bitfield1 missing");
}
bitfield_1.read(file);
fclose(file);
}

FILE* plot_file = fopen("test.plot.tmp", "wb");
FILE* plot_file = FOPEN("test.plot.tmp", "wb");
if(!plot_file) {
throw std::runtime_error("fopen() failed");
}
Expand Down
5 changes: 2 additions & 3 deletions test/test_phase_4.cpp
Expand Up @@ -4,9 +4,8 @@
* Created on: Jun 3, 2021
* Author: mad
*/

#include <chia/stdiox.hpp>
#include <chia/phase4.hpp>

#include <iostream>

using namespace phase4;
Expand All @@ -19,7 +18,7 @@ int main(int argc, char** argv)

const auto total_begin = get_wall_time_micros();

FILE* plot_file = fopen("test.plot.tmp", "rb+");
FILE* plot_file = FOPEN("test.plot.tmp", "rb+");
if(!plot_file) {
throw std::runtime_error("fopen() failed");
}
Expand Down
21 changes: 21 additions & 0 deletions uint128_t/LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2013 - 2017 Jason Lee @ calccrypto at gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

0 comments on commit 07611ea

Please sign in to comment.