Skip to content
Permalink
Browse files

Replaced static cuckoo lib with git submodule

  • Loading branch information...
octavonce committed May 21, 2019
1 parent b5551e7 commit d0b91549ae5fed3e5949405932501b5b248f3de3
@@ -63,4 +63,4 @@ install:
build: false

test_script:
- cargo test --verbose --all %cargoflags%
- cargo test --verbose --all %cargoflags% --features gpu
@@ -0,0 +1,3 @@
[submodule "src/miner/cuckoo_src/cuckoo"]
path = src/miner/cuckoo_src/cuckoo
url = https://github.com/tromp/cuckoo_src/cuckoo
@@ -12,4 +12,4 @@ matrix:
fast_finish: true

script:
- cargo test --verbose --all
- cargo test --verbose --all --features gpu

Some generated files are not rendered by default. Learn more.

@@ -33,7 +33,7 @@ If you want a clear description of the progress so far you can look at the [mile


## Building
Building the project requires cmake and clang/llvm. After all dependencies are installed, run:
Building the project requires cmake, clang/llvm and the CUDA toolkit. After all dependencies are installed, run:

```
cargo build
@@ -5,8 +5,11 @@ authors = ["Octavian Oncescu <octavonce@gmail.com>"]
edition = "2018"

[dependencies]
cuckoo-sys = { path = "../util/cuckoo-sys" }

[build-dependencies]
cmake = "0.1.24"
fs_extra = "1.1.0"

[features]
default = []
gpu = ["cuckoo-sys/gpu"]
gpu = []
@@ -0,0 +1,84 @@
/*
Copyright 2018 The Purple Library Authors
This file is part of the Purple Library.
The Purple Library is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The Purple Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the Purple Library. If not, see <http://www.gnu.org/licenses/>.
This is a modified version of the following file:
https://github.com/mimblewimble/grin-miner/blob/master/cuckoo-miner/src/build.rs
*/

use cmake::Config;
use std::{env, fs};
use std::path::PathBuf;
use fs_extra::dir::*;

#[cfg(feature = "gpu")]
const BUILD_CUDA_PLUGINS: &str = "TRUE";
#[cfg(not(feature = "gpu"))]
const BUILD_CUDA_PLUGINS: &str = "FALSE";

fn fail_on_empty_directory(name: &str) {
if fs::read_dir(name).unwrap().count() == 0 {
println!(
"The `{}` directory is empty. Did you forget to pull the submodules?",
name
);
println!("Try `git submodule update --init --recursive`");
panic!();
}
}

fn main() {
fail_on_empty_directory("cuckoo_src/cuckoo");
let path_str = env::var("OUT_DIR").unwrap();
let mut out_path = PathBuf::from(&path_str);
out_path.pop();
out_path.pop();
out_path.pop();
let mut plugin_path = PathBuf::from(&path_str);
plugin_path.push("build");
plugin_path.push("plugins");
// Collect the files and directories we care about
let p = PathBuf::from("cuckoo_src");
let dir_content = match get_dir_content(p) {
Ok(c) => c,
Err(e) => panic!("Error getting directory content: {}", e),
};
for d in dir_content.directories {
let file_content = get_dir_content(d).unwrap();
for f in file_content.files {
println!("cargo:rerun-if-changed={}", f);
}
}
for f in dir_content.files {
println!("cargo:rerun-if-changed={}", f);
}

let dst = Config::new("cuckoo_src")
.define("BUILD_CUDA_PLUGINS",BUILD_CUDA_PLUGINS) //whatever flags go here
//.cflag("-foo") //and here
.build_target("")
.build();

println!("Plugin path: {:?}", plugin_path);
println!("OUT PATH: {:?}", out_path);
let mut options = CopyOptions::new();
options.overwrite = true;
if let Err(e) = copy(plugin_path, out_path, &options) {
println!("{:?}", e);
}

println!("cargo:rustc-link-search=native={}", dst.display());
}
@@ -0,0 +1,43 @@
#
# Compute target flags macros by Anatoly Baksheev
#
# Usage in CmakeLists.txt:
# include(CudaComputeTargetFlags.cmake)
# APPEND_TARGET_ARCH_FLAGS()

#compute flags macros
MACRO(CUDA_COMPUTE_TARGET_FLAGS arch_bin arch_ptx cuda_nvcc_target_flags)
string(REGEX REPLACE "\\." "" ARCH_BIN_WITHOUT_DOTS "${${arch_bin}}")
string(REGEX REPLACE "\\." "" ARCH_PTX_WITHOUT_DOTS "${${arch_ptx}}")

set(cuda_computer_target_flags_temp "")

# Tell NVCC to add binaries for the specified GPUs
string(REGEX MATCHALL "[0-9()]+" ARCH_LIST "${ARCH_BIN_WITHOUT_DOTS}")
foreach(ARCH IN LISTS ARCH_LIST)
if (ARCH MATCHES "([0-9]+)\\(([0-9]+)\\)")
# User explicitly specified PTX for the concrete BIN
set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1})
else()
# User didn't explicitly specify PTX for the concrete BIN, we assume PTX=BIN
set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${ARCH},code=sm_${ARCH})
endif()
endforeach()

# Tell NVCC to add PTX intermediate code for the specified architectures
string(REGEX MATCHALL "[0-9]+" ARCH_LIST "${ARCH_PTX_WITHOUT_DOTS}")
foreach(ARCH IN LISTS ARCH_LIST)
set(cuda_computer_target_flags_temp ${cuda_computer_target_flags_temp} -gencode arch=compute_${ARCH},code=compute_${ARCH})
endforeach()

set(${cuda_nvcc_target_flags} ${cuda_computer_target_flags_temp})
ENDMACRO()

MACRO(APPEND_TARGET_ARCH_FLAGS)
set(cuda_nvcc_target_flags "")
CUDA_COMPUTE_TARGET_FLAGS(CUDA_ARCH_BIN CUDA_ARCH_PTX cuda_nvcc_target_flags)
if (cuda_nvcc_target_flags)
message(STATUS "CUDA NVCC target flags: ${cuda_nvcc_target_flags}")
list(APPEND CUDA_NVCC_FLAGS ${cuda_nvcc_target_flags})
endif()
ENDMACRO()
@@ -0,0 +1,69 @@
#from: https://github.com/PointCloudLibrary/pcl/blob/master/cmake/pcl_find_cuda.cmake
# Find CUDA
if(MSVC)
# Setting this to true brakes Visual Studio builds.
set(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE OFF CACHE BOOL "CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE")
endif()

set(CUDA_FIND_QUIETLY TRUE)
find_package(CUDA 4)

if(CUDA_FOUND)
message(STATUS "Found CUDA Toolkit v${CUDA_VERSION_STRING}")

# CUDA 9.1 + installs a symlink to its preferred compiler, so use that if it exists
# Otherwise, try to default to /usr/bin/gcc if one hasn't been supplied at the command line
# This will not override an existing cache
# value if the user has passed CUDA_HOST_COMPILER_OVERRIDE on the command line.
if (CUDA_HOST_COMPILER_OVERRIDE)
set (CUDA_HOST_COMPILER ${CUDA_HOST_COMPILER_OVERRIDE})
elseif (EXISTS /opt/cuda/bin/gcc)
set(CUDA_HOST_COMPILER /opt/cuda/bin/gcc)
elseif (EXISTS /usr/bin/gcc)
set(CUDA_HOST_COMPILER /usr/bin/gcc)
elseif (EXISTS /usr/bin/cc)
set(CUDA_HOST_COMPILER /usr/bin/cc)
endif()

message(STATUS "Setting CMAKE_HOST_COMPILER to ${CUDA_HOST_COMPILER}.")

# Send a warning if CUDA_HOST_COMPILER is set to a compiler that is known
# to be unsupported.
if (CUDA_HOST_COMPILER STREQUAL CMAKE_C_COMPILER AND CMAKE_C_COMPILER_ID STREQUAL "Clang")
message(WARNING "CUDA_HOST_COMPILER is set to an unsupported compiler: ${CMAKE_C_COMPILER}.")
endif()

# CUDA_ARCH_BIN is a space separated list of versions to include in output so-file. So you can set CUDA_ARCH_BIN = 10 11 12 13 20
# Also user can specify virtual arch in parenthesis to limit instructions set,
# for example CUDA_ARCH_BIN = 11(11) 12(11) 13(11) 20(11) 21(11) -> forces using only sm_11 instructions.
# The CMake scripts interpret XX as XX (XX). This allows user to omit parenthesis.
# Arch 21 is an exceptional case since it doesn't have own sm_21 instructions set.
# So 21 = 21(21) is an invalid configuration and user has to explicitly force previous sm_20 instruction set via 21(20).
# CUDA_ARCH_BIN adds support of only listed GPUs. As alternative CMake scripts also parse 'CUDA_ARCH_PTX' variable,
# which is a list of intermediate PTX codes to include in final so-file. The PTX code can/will be JIT compiled for any current or future GPU.
# To add support of older GPU for kinfu, I would embed PTX 11 and 12 into so-file. GPU with sm_13 will run PTX 12 code (no difference for kinfu)

# Find a complete list for CUDA compute capabilities at http://developer.nvidia.com/cuda-gpus

if(NOT ${CUDA_VERSION_STRING} VERSION_LESS "10.0")
set(__cuda_arch_bin "3.5 3.7 5.0 5.2 6.0 6.1 7.0 7.2 7.5")
elseif(NOT ${CUDA_VERSION_STRING} VERSION_LESS "9.0")
set(__cuda_arch_bin "3.5 3.7 5.0 5.2 6.0 6.1 7.0")
elseif(NOT ${CUDA_VERSION_STRING} VERSION_LESS "8.0")
set(__cuda_arch_bin "3.5 5.0 5.2 5.3 6.0 6.1")
else()
set(__cuda_arch_bin "3.5")
endif()

set(CUDA_ARCH_BIN ${__cuda_arch_bin} CACHE STRING "Specify 'real' GPU architectures to build binaries for, BIN(PTX) format is supported")

set(CUDA_ARCH_PTX "" CACHE STRING "Specify 'virtual' PTX arch to build PTX intermediate code for. Example: 1.0 1.2 or 10 12")
#set(CUDA_ARCH_PTX "1.1 1.2" CACHE STRING "Specify 'virtual' PTX arch to build PTX intermediate code for. Example: 1.0 1.2 or 10 12")

# Guess this macros will be included in cmake distributive
include(cmake/CudaComputeTargetFlags.cmake)
APPEND_TARGET_ARCH_FLAGS()

# Prevent compilation issues between recent gcc versions and old CUDA versions
list(APPEND CUDA_NVCC_FLAGS "-D_FORCE_INLINES")
endif()
Submodule cuckoo_src added at 5a76f1

This file was deleted.

This file was deleted.

0 comments on commit d0b9154

Please sign in to comment.
You can’t perform that action at this time.