Skip to content

Commit

Permalink
Improve project build compatibility (mac/vs2015)
Browse files Browse the repository at this point in the history
This is incomplete, but is a first step...
  • Loading branch information
tpruvot committed May 9, 2017
1 parent 5dfeee4 commit 81d5f4e
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 5 deletions.
15 changes: 15 additions & 0 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -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

7 changes: 7 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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\"
Expand Down
4 changes: 4 additions & 0 deletions bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
#include "algos.h"
#include <cuda_runtime.h>

#ifdef __APPLE__
#include "compat/pthreads/pthread_barrier.hpp"
#endif

int bench_algo = -1;

static double algo_hashrates[MAX_GPUS][ALGO_COUNT] = { 0 };
Expand Down
69 changes: 69 additions & 0 deletions compat/pthreads/pthread_barrier.hpp
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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])

Expand Down Expand Up @@ -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]])
Expand Down
7 changes: 7 additions & 0 deletions crypto/xmr-rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
#include <sys/mman.h> // 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
Expand Down
7 changes: 7 additions & 0 deletions scrypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,16 @@ using namespace Concurrency;
#include <string.h>

#include <emmintrin.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <new>

#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
{
Expand Down
3 changes: 3 additions & 0 deletions scrypt/salsa_kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#ifndef __APPLE__
#include <malloc.h>
#endif
#include <string.h>
#include <cuda_runtime.h>

Expand Down
24 changes: 19 additions & 5 deletions serialize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@
#include <utility>
#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;

static const unsigned int MAX_SIZE = 0x02000000;
Expand Down Expand Up @@ -824,11 +843,6 @@ inline void SerReadWrite(Stream& s, T& obj, int nType, int nVersion, CSerActionU








class CSizeComputer
{
protected:
Expand Down

0 comments on commit 81d5f4e

Please sign in to comment.