Browse Source

Improve project build compatibility (mac/vs2015)

This is incomplete, but is a first step...
master
Tanguy Pruvot 8 years ago
parent
commit
81d5f4e862
  1. 15
      INSTALL
  2. 7
      Makefile.am
  3. 4
      bench.cpp
  4. 69
      compat/pthreads/pthread_barrier.hpp
  5. 10
      configure.ac
  6. 7
      crypto/xmr-rpc.cpp
  7. 7
      scrypt.cpp
  8. 3
      scrypt/salsa_kernel.h
  9. 24
      serialize.hpp

15
INSTALL

@ -40,3 +40,18 @@ and comment/delete the line 82 : #error -- unsupported GNU version! gcc 4.9
./ccminer -n ./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

7
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_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) 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_50,code=\"sm_50,compute_50\"
nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\" nvcc_ARCH += -gencode=arch=compute_52,code=\"sm_52,compute_52\"

4
bench.cpp

@ -10,6 +10,10 @@
#include "algos.h" #include "algos.h"
#include <cuda_runtime.h> #include <cuda_runtime.h>
#ifdef __APPLE__
#include "compat/pthreads/pthread_barrier.hpp"
#endif
int bench_algo = -1; int bench_algo = -1;
static double algo_hashrates[MAX_GPUS][ALGO_COUNT] = { 0 }; static double algo_hashrates[MAX_GPUS][ALGO_COUNT] = { 0 };

69
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 <pthread.h>
#include <errno.h>
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_

10
configure.ac

@ -63,6 +63,10 @@ case $target in
PTHREAD_FLAGS="" PTHREAD_FLAGS=""
WS2_LIBS="-lws2_32" WS2_LIBS="-lws2_32"
;; ;;
*86*-apple-darwin*)
have_osx=true
PTHREAD_FLAGS=""
;;
esac esac
AC_CHECK_LIB(jansson, json_loads, request_jansson=false, request_jansson=true) 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([WANT_JANSSON], [test x$request_jansson = xtrue])
AM_CONDITIONAL([HAVE_WINDOWS], [test x$have_win32 = 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], [test x$have_x86 = xtrue])
AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue]) AM_CONDITIONAL([ARCH_x86_64], [test x$have_x86_64 = xtrue])
@ -111,6 +116,11 @@ else
SUFFIX="" SUFFIX=""
fi fi
if test x$have_osx = xtrue
then
SUFFIX=""
fi
dnl Setup CUDA paths dnl Setup CUDA paths
AC_ARG_WITH([cuda], AC_ARG_WITH([cuda],
[ --with-cuda=PATH prefix where cuda is installed [default=/usr/local/cuda]]) [ --with-cuda=PATH prefix where cuda is installed [default=/usr/local/cuda]])

7
crypto/xmr-rpc.cpp

@ -23,6 +23,13 @@
#include <sys/mman.h> // mmap #include <sys/mman.h> // mmap
#endif #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 #ifndef PRIu64
#define PRIu64 "I64u" #define PRIu64 "I64u"
#endif #endif

7
scrypt.cpp

@ -43,9 +43,16 @@ using namespace Concurrency;
#include <string.h> #include <string.h>
#include <emmintrin.h> #include <emmintrin.h>
#ifndef __APPLE__
#include <malloc.h> #include <malloc.h>
#endif
#include <new> #include <new>
#if _MSC_VER > 1800
#undef _THROW1
#define _THROW1(x) throw(std::bad_alloc)
#endif
// A thin wrapper around the builtin __m128i type // A thin wrapper around the builtin __m128i type
class uint32x4_t class uint32x4_t
{ {

3
scrypt/salsa_kernel.h

@ -3,7 +3,10 @@
#include <stdio.h> #include <stdio.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h> #include <malloc.h>
#endif
#include <string.h> #include <string.h>
#include <cuda_runtime.h> #include <cuda_runtime.h>

24
serialize.hpp

@ -20,6 +20,25 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
#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; class CScript;
static const unsigned int MAX_SIZE = 0x02000000; 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 class CSizeComputer
{ {
protected: protected:

Loading…
Cancel
Save