diff --git a/INSTALL b/INSTALL index 872c05a..b27ba4b 100644 --- a/INSTALL +++ b/INSTALL @@ -40,3 +40,18 @@ and comment/delete the line 82 : #error -- unsupported GNU version! gcc 4.9 ./ccminer -n + +** How to compile on macOS ** +# Step 1: download and install CUDA Toolkit 8 or more recent +# https://developer.nvidia.com/cuda-toolkit-archive + +# Step 2: install Homebrew +ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" + +# Step 3: dependencies +brew install pkg-config autoconf automake curl openssl llvm + +./build.sh + +./ccminer -n + diff --git a/Makefile.am b/Makefile.am index 21678b4..08971d0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -91,6 +91,13 @@ ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@ ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@ $(nvml_libs) ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) $(DEF_INCLUDES) $(nvml_defs) +if HAVE_OSX +ccminer_CPPFLAGS += -I/usr/local/llvm/lib/clang/4.0.0/include +ccminer_LDFLAGS += -L/usr/local/llvm/lib +ccminer_LDADD += -lomp +endif + + nvcc_ARCH = -gencode=arch=compute_50,code=\"sm_50,compute_50\" nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\" diff --git a/bench.cpp b/bench.cpp index 43121fe..3e68224 100644 --- a/bench.cpp +++ b/bench.cpp @@ -10,6 +10,10 @@ #include "algos.h" #include +#ifdef __APPLE__ +#include "compat/pthreads/pthread_barrier.hpp" +#endif + int bench_algo = -1; static double algo_hashrates[MAX_GPUS][ALGO_COUNT] = { 0 }; diff --git a/compat/pthreads/pthread_barrier.hpp b/compat/pthreads/pthread_barrier.hpp new file mode 100644 index 0000000..b0c3172 --- /dev/null +++ b/compat/pthreads/pthread_barrier.hpp @@ -0,0 +1,69 @@ +/** + * Meant to improve clang 4 / macos compatibility (untested) + */ + +#ifndef PTHREAD_BARRIER_H_ +#define PTHREAD_BARRIER_H_ + +#include +#include + +typedef int pthread_barrierattr_t; +typedef struct +{ + pthread_mutex_t mutex; + pthread_cond_t cond; + int count; + int tripCount; +} pthread_barrier_t; + + +int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count) +{ + if(count == 0) + { + errno = EINVAL; + return -1; + } + if(pthread_mutex_init(&barrier->mutex, 0) < 0) + { + return -1; + } + if(pthread_cond_init(&barrier->cond, 0) < 0) + { + pthread_mutex_destroy(&barrier->mutex); + return -1; + } + barrier->tripCount = count; + barrier->count = 0; + + return 0; +} + +int pthread_barrier_destroy(pthread_barrier_t *barrier) +{ + pthread_cond_destroy(&barrier->cond); + pthread_mutex_destroy(&barrier->mutex); + return 0; +} + +int pthread_barrier_wait(pthread_barrier_t *barrier) +{ + pthread_mutex_lock(&barrier->mutex); + ++(barrier->count); + if(barrier->count >= barrier->tripCount) + { + barrier->count = 0; + pthread_cond_broadcast(&barrier->cond); + pthread_mutex_unlock(&barrier->mutex); + return 1; + } + else + { + pthread_cond_wait(&barrier->cond, &(barrier->mutex)); + pthread_mutex_unlock(&barrier->mutex); + return 0; + } +} + +#endif // PTHREAD_BARRIER_H_ diff --git a/configure.ac b/configure.ac index 7842201..1c76b70 100644 --- a/configure.ac +++ b/configure.ac @@ -63,6 +63,10 @@ case $target in PTHREAD_FLAGS="" WS2_LIBS="-lws2_32" ;; + *86*-apple-darwin*) + have_osx=true + PTHREAD_FLAGS="" + ;; esac AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true) @@ -78,6 +82,7 @@ AC_CHECK_LIB([crypto],[EVP_DigestFinal_ex], [], [AC_MSG_ERROR([OpenSSL library r AM_CONDITIONAL([WANT_JANSSON], [test x$request_jansson = xtrue]) AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = xtrue]) +AM_CONDITIONAL([HAVE_OSX], [test x$have_osx = xtrue]) AM_CONDITIONAL([ARCH_x86], [test x$have_x86 = xtrue]) AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue]) @@ -111,6 +116,11 @@ else SUFFIX="" fi +if test x$have_osx = xtrue +then + SUFFIX="" +fi + dnl Setup CUDA paths AC_ARG_WITH([cuda], [ --with-cuda=PATH prefix where cuda is installed [default=/usr/local/cuda]]) diff --git a/crypto/xmr-rpc.cpp b/crypto/xmr-rpc.cpp index 3cce2d5..b70debd 100644 --- a/crypto/xmr-rpc.cpp +++ b/crypto/xmr-rpc.cpp @@ -23,6 +23,13 @@ #include // mmap #endif +#if defined(__APPLE__) && !defined(MAP_HUGETLB) +#define MAP_ANONYMOUS MAP_ANON +#define MAP_HUGETLB 0 +#define MAP_POPULATE 0 +#define MADV_HUGEPAGE 0 +#endif + #ifndef PRIu64 #define PRIu64 "I64u" #endif diff --git a/scrypt.cpp b/scrypt.cpp index 1d53d17..a6b9b70 100644 --- a/scrypt.cpp +++ b/scrypt.cpp @@ -43,9 +43,16 @@ using namespace Concurrency; #include #include +#ifndef __APPLE__ #include +#endif #include +#if _MSC_VER > 1800 +#undef _THROW1 +#define _THROW1(x) throw(std::bad_alloc) +#endif + // A thin wrapper around the builtin __m128i type class uint32x4_t { diff --git a/scrypt/salsa_kernel.h b/scrypt/salsa_kernel.h index d4ffae3..f0ea15a 100644 --- a/scrypt/salsa_kernel.h +++ b/scrypt/salsa_kernel.h @@ -3,7 +3,10 @@ #include #include +#include +#ifndef __APPLE__ #include +#endif #include #include diff --git a/serialize.hpp b/serialize.hpp index 24bba7e..e06a434 100644 --- a/serialize.hpp +++ b/serialize.hpp @@ -20,6 +20,25 @@ #include #include +#ifdef __APPLE__ +#include + +#define htobe16(x) OSSwapHostToBigInt16(x) +#define htole16(x) OSSwapHostToLittleInt16(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) + +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) + +#define htobe64(x) OSSwapHostToBigInt64(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define be64toh(x) OSSwapBigToHostInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) +#endif + class CScript; static const unsigned int MAX_SIZE = 0x02000000; @@ -824,11 +843,6 @@ inline void SerReadWrite(Stream& s, T& obj, int nType, int nVersion, CSerActionU - - - - - class CSizeComputer { protected: