Skip to content

Commit

Permalink
Add nvml for GPU monitoring (squashed)
Browse files Browse the repository at this point in the history
  Based on mwhite73 <marvin.white@gmail.com> implementation

  Linked to the api system

  Also fix Makefile to support standard c++ files
  This prevent nvcc use without device code

Signed-off-by: Tanguy Pruvot <tanguy.pruvot@gmail.com>
  • Loading branch information
tpruvot committed Nov 13, 2014
1 parent 1118d6c commit 49f3c45
Show file tree
Hide file tree
Showing 13 changed files with 752 additions and 66 deletions.
21 changes: 14 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# allow to use Host cuda functions in C/C++
DEF_INCLUDES = @CUDA_INCLUDES@

JANSSON_INCLUDES=
if WANT_JANSSON
JANSSON_INCLUDES= -I$(top_srcdir)/compat/jansson
else
JANSSON_INCLUDES=
endif

EXTRA_DIST = autogen.sh README.txt LICENSE.txt \
Expand All @@ -17,7 +18,7 @@ ccminer_SOURCES = elist.h miner.h compat.h \
compat/inttypes.h compat/stdbool.h compat/unistd.h \
compat/sys/time.h compat/getopt/getopt.h \
cpu-miner.c util.c crc32.c hefty1.c scrypt.c \
api.c hashlog.cpp stats.cpp cuda.cu \
api.cpp hashlog.cpp stats.cpp cuda.cpp \
heavy/heavy.cu \
heavy/cuda_blake512.cu heavy/cuda_blake512.h \
heavy/cuda_combine.cu heavy/cuda_combine.h \
Expand Down Expand Up @@ -49,19 +50,25 @@ ccminer_SOURCES = elist.h miner.h compat.h \
x17/x17.cu x17/cuda_x17_haval512.cu x17/cuda_x17_sha512.cu \
x11/s3.cu

if HAVE_NVML
ccminer_SOURCES += nvml.cpp
nvml_defs = -DUSE_WRAPNVML
nvml_libs = -ldl
endif

if HAVE_WINDOWS
ccminer_SOURCES += compat/winansi.c
endif

ccminer_LDFLAGS = $(PTHREAD_FLAGS) @CUDA_LDFLAGS@
ccminer_LDADD = @LIBCURL@ @JANSSON_LIBS@ @PTHREAD_LIBS@ @WS2_LIBS@ @CUDA_LIBS@ @OPENMP_CFLAGS@ @LIBS@
ccminer_CPPFLAGS = @LIBCURL_CPPFLAGS@ @OPENMP_CFLAGS@ $(CPPFLAGS) $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES) -DSCRYPT_KECCAK512 -DSCRYPT_CHACHA -DSCRYPT_CHOOSE_COMPILETIME
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) -DSCRYPT_KECCAK512 -DSCRYPT_CHACHA -DSCRYPT_CHOOSE_COMPILETIME

nvcc_ARCH = -gencode=arch=compute_50,code=\"sm_50,compute_50\"
#nvcc_ARCH += -gencode=arch=compute_35,code=\"sm_35,compute_35\"
#nvcc_ARCH += -gencode=arch=compute_30,code=\"sm_30,compute_30\"

nvcc_FLAGS = $(nvcc_ARCH) -I . @CUDA_CFLAGS@
nvcc_FLAGS = $(nvcc_ARCH) @CUDA_INCLUDES@ -I. @CUDA_CFLAGS@
nvcc_FLAGS += $(JANSSON_INCLUDES) --ptxas-options="-v"

# we're now targeting all major compute architectures within one binary.
Expand Down
8 changes: 6 additions & 2 deletions README.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

ccMiner release 1.4.8-tpruvot (12 Nov 2014) - "API Stats"
ccMiner release 1.4.9-tpruvot (Nov 2014) - "GPU Monitoring"
---------------------------------------------------------------

***************************************************************
Expand Down Expand Up @@ -155,9 +155,13 @@ features.

>>> RELEASE HISTORY <<<

Nov. 13th 2014 v1.4.9
Add nvml unit to monitor nvidia cards (api)
API: small changes, bump v1.1

Nov. 12th 2014 v1.4.8
Add a basic API and sample php json wrapper
Add statsavg (def 20) and api-bind parameters
Add statsavg (def 20) and api-bind parameters
Fix displayed hashrate for multi gpus systems

Nov. 11th 2014 v1.4.7
Expand Down
51 changes: 30 additions & 21 deletions api.c → api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Software Foundation; either version 2 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
#define APIVERSION "1.0"
#define APIVERSION "1.1"

#ifdef _MSC_VER
# define _WINSOCK_DEPRECATED_NO_WARNINGS
Expand All @@ -35,6 +35,10 @@
#include "compat.h"
#include "miner.h"

#ifdef USE_WRAPNVML
#include "nvml.h"
#endif

#ifndef _MSC_VER
# include <errno.h>
# include <sys/socket.h>
Expand Down Expand Up @@ -105,25 +109,26 @@ extern uint32_t rejected_count;

#define gpu_threads opt_n_threads

extern void get_currentalgo(char* buf, int sz);

/***************************************************************/

static void gpustatus(int thr_id)
{
char buf[MYBUFSIZ];
float gt;
int gf, gp;
int gp, gf;

if (thr_id >= 0 && thr_id < gpu_threads) {
struct cgpu_info *cgpu = &thr_info[thr_id].gpu;

#ifdef HAVE_HWMONITORING
cgpu->thr_id = thr_id;

#ifdef USE_WRAPNVML
// todo
if (gpu->has_monitoring) {
gt = gpu_temp(gpu);
gf = gpu_fanspeed(gpu);
gp = gpu_fanpercent(gpu);
if (1 || cgpu->has_monitoring) {
gf = gpu_fanpercent(cgpu);
gt = gpu_temp(cgpu);
gp = gpu_power(cgpu);
// gpu_clock(cgpu);
}
else
#endif
Expand All @@ -148,7 +153,7 @@ static void gpustatus(int thr_id)

cgpu->khashes = stats_get_speed(thr_id) / 1000.0;

sprintf(buf, "GPU=%d;TEMP=%.1f;FAN=%d;FANP=%d;KHS=%.2f;"
sprintf(buf, "GPU=%d;TEMP=%.1f;FAN=%d;POWER=%d;KHS=%.2f;"
"HWF=%d;I=%d|",
thr_id, gt, gf, gp, cgpu->khashes,
cgpu->hw_errors, cgpu->intensity);
Expand All @@ -162,14 +167,14 @@ static void gpustatus(int thr_id)
static char *getsummary(char *params)
{
char algo[64] = "";
time_t uptime = (time(NULL) - startup);
double accps = (60.0 * accepted_count) / (uptime ? (uint32_t) uptime : 1.0);
double uptime = difftime(time(NULL), startup);
double accps = (60.0 * accepted_count) / (uptime ? uptime : 1.0);

get_currentalgo(algo, sizeof(algo));

*buffer = '\0';
sprintf(buffer, "NAME=%s;VER=%s;API=%s;"
"ALGO=%s;KHS=%.2f;ACC=%d;REJ=%d;ACCMN=%.3f;UPTIME=%d|",
"ALGO=%s;KHS=%.2f;ACC=%d;REJ=%d;ACCMN=%.3f;UPTIME=%.1f|",
PACKAGE_NAME, PACKAGE_VERSION, APIVERSION,
algo, (double)global_hashrate / 1000.0,
accepted_count, rejected_count,
Expand All @@ -186,7 +191,7 @@ static char *getstats(char *params)
}

struct CMDS {
char *name;
const char *name;
char *(*func)(char *);
} cmds[] = {
{ "summary", getsummary },
Expand All @@ -195,15 +200,18 @@ struct CMDS {

#define CMDMAX 2

static void send_result(SOCKETTYPE c, char *result)
static int send_result(SOCKETTYPE c, char *result)
{
int n;

if (result == NULL)
result = "";
if (!result) {
n = send(c, "", 1, 0);
} else {
// ignore failure - it's closed immediately anyway
n = send(c, result, strlen(result) + 1, 0);
}

// ignore failure - it's closed immediately anyway
n = send(c, result, strlen(result) + 1, 0);
return n;
}

/*
Expand Down Expand Up @@ -400,7 +408,8 @@ static void api()
if ((time(NULL) - bindstart) > 61)
break;
else {
applog(LOG_ERR, "API bind to port %d failed - trying again in 15sec", port);
if (!opt_quiet || opt_debug)
applog(LOG_WARNING, "API bind to port %d failed - trying again in 15sec", port);
sleep(15);
}
}
Expand All @@ -409,7 +418,7 @@ static void api()
}

if (bound == 0) {
applog(LOG_ERR, "API bind to port %d failed (%s)%s", port, binderror, UNAVAILABLE);
applog(LOG_WARNING, "API bind to port %d failed (%s)%s", port, binderror, UNAVAILABLE);
free(apisock);
return;
}
Expand Down
15 changes: 7 additions & 8 deletions ccminer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;USE_WRAPNVML;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;compat;compat\curl-for-windows\curl\include;compat\jansson;compat\getopt;compat\pthreads;compat\curl-for-windows\openssl\openssl\include;compat\curl-for-windows\zlib;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
</ClCompile>
Expand All @@ -114,7 +114,7 @@
<Optimization>Disabled</Optimization>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;USE_WRAPNVML;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;compat;compat\curl-for-windows\curl\include;compat\jansson;compat\getopt;compat\pthreads;compat\curl-for-windows\openssl\openssl\include;compat\curl-for-windows\zlib;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
<StructMemberAlignment>8Bytes</StructMemberAlignment>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
Expand Down Expand Up @@ -150,7 +150,7 @@
<CompileAsManaged>false</CompileAsManaged>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;USE_WRAPNVML;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;compat;compat\curl-for-windows\curl\include;compat\jansson;compat\getopt;compat\pthreads;compat\curl-for-windows\openssl\openssl\include;compat\curl-for-windows\zlib;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
<EnableParallelCodeGeneration>true</EnableParallelCodeGeneration>
<ExceptionHandling>SyncCThrow</ExceptionHandling>
Expand Down Expand Up @@ -193,7 +193,7 @@
<CompileAsManaged>false</CompileAsManaged>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;CURL_STATICLIB;USE_WRAPNVML;SCRYPT_KECCAK512;SCRYPT_CHACHA;SCRYPT_CHOOSE_COMPILETIME;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories>.;compat;compat\curl-for-windows\curl\include;compat\jansson;compat\getopt;compat\pthreads;compat\curl-for-windows\openssl\openssl\include;compat\curl-for-windows\zlib;%(AdditionalIncludeDirectories);$(CudaToolkitIncludeDir)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
Expand Down Expand Up @@ -240,9 +240,8 @@
<ClCompile Include="groestlcoin.cpp" />
<ClCompile Include="hashlog.cpp" />
<ClCompile Include="stats.cpp" />
<ClCompile Include="api.c">
<AdditionalOptions>/Tp %(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<ClCompile Include="nvml.cpp" />
<ClCompile Include="api.cpp" />
<ClCompile Include="hefty1.c" />
<ClCompile Include="myriadgroestl.cpp" />
<ClCompile Include="scrypt.c">
Expand Down Expand Up @@ -321,7 +320,7 @@
<ClInclude Include="uint256.h" />
</ItemGroup>
<ItemGroup>
<CudaCompile Include="cuda.cu" />
<CudaCompile Include="cuda.cpp" />
<CudaCompile Include="bitslice_transformations_quad.cu">
<ExcludedFromBuild>true</ExcludedFromBuild>
</CudaCompile>
Expand Down
9 changes: 6 additions & 3 deletions ccminer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,10 @@
<ClCompile Include="stats.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="api.c">
<ClCompile Include="api.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="nvml.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
Expand Down Expand Up @@ -313,7 +316,7 @@
</ClInclude>
</ItemGroup>
<ItemGroup>
<CudaCompile Include="cuda.cu">
<CudaCompile Include="cuda.cpp">
<Filter>Source Files\CUDA</Filter>
</CudaCompile>
<CudaCompile Include="cuda_fugue256.cu">
Expand Down Expand Up @@ -482,4 +485,4 @@
<Filter>Source Files\CUDA\x11</Filter>
</CudaCompile>
</ItemGroup>
</Project>
</Project>
31 changes: 22 additions & 9 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([ccminer], [1.4.8])
AC_INIT([ccminer], [1.4.9])

AC_PREREQ([2.59c])
AC_CANONICAL_SYSTEM
Expand Down Expand Up @@ -142,19 +142,32 @@ dnl Setup CUDA paths
AC_ARG_WITH([cuda],
[ --with-cuda=PATH prefix where cuda is installed [default=/usr/local/cuda]])

AC_ARG_WITH([nvml],
[ --with-nvml=PATH prefix where libnvml is installed [default=/usr/lib]])

AM_CONDITIONAL([HAVE_NVML], [test -n "$with_nvml"])

if test -n "$with_cuda"
then
CUDA_CFLAGS="-I$with_cuda/include $CUDA_CFLAGS"
CUDA_LIBS="-lcudart"
CUDA_LDFLAGS="-L$with_cuda/lib$SUFFIX"
NVCC="$with_cuda/bin/nvcc"
CUDA_INCLUDES="-I$with_cuda/include"
CUDA_LIBS="-lcudart"
CUDA_LDFLAGS="-L$with_cuda/lib$SUFFIX"
NVCC="$with_cuda/bin/nvcc"
else
CUDA_CFLAGS="-I/usr/local/cuda/include $CUDA_CFLAGS"
CUDA_LIBS="-lcudart -static-libstdc++"
CUDA_LDFLAGS="-L/usr/local/cuda/lib$SUFFIX"
NVCC="nvcc"
CUDA_INCLUDES="-I/usr/local/cuda/include"
CUDA_LIBS="-lcudart -static-libstdc++"
CUDA_LDFLAGS="-L/usr/local/cuda/lib$SUFFIX"
NVCC="nvcc"
fi

if test -n "$with_nvml" ; then
NVML_LIBPATH=$with_nvml
CUDA_LDFLAGS="$CUDA_LDFLAGS -ldl"
fi
AC_SUBST(NVML_LIBPATH)

AC_SUBST(CUDA_CFLAGS)
AC_SUBST(CUDA_INCLUDES)
AC_SUBST(CUDA_LIBS)
AC_SUBST(CUDA_LDFLAGS)
AC_SUBST(NVCC)
Expand Down
2 changes: 1 addition & 1 deletion configure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@

extracflags="-march=native -D_REENTRANT -falign-functions=16 -falign-jumps=16 -falign-labels=16"

CUDA_CFLAGS="-O3 -Xcompiler -Wall" ./configure CXXFLAGS="-O3 $extracflags" --with-cuda=/usr/local/cuda
CUDA_CFLAGS="-O3 -Xcompiler -Wall" ./configure CXXFLAGS="-O3 $extracflags" --with-cuda=/usr/local/cuda --with-nvml=libnvidia-ml.so

Loading

0 comments on commit 49f3c45

Please sign in to comment.