From 5eee01464288ee797caad32ee4c5af66427cc9b2 Mon Sep 17 00:00:00 2001 From: Richard Ulrich Date: Tue, 18 Feb 2014 22:28:18 +0100 Subject: [PATCH] * using cmake * small changes towards running on my Intel4400 or Geforce9800 --- .gitignore | 4 +- CMakeLists.txt | 88 ++++++++++++++++++++++++++++++++++++++++ FindOpenCL.cmake | 103 +++++++++++++++++++++++++++++++++++++++++++++++ FindPCRE.cmake | 53 ++++++++++++++++++++++++ oclengine.c | 21 +++++++--- 5 files changed, 262 insertions(+), 7 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 FindOpenCL.cmake create mode 100644 FindPCRE.cmake diff --git a/.gitignore b/.gitignore index 0542885..3bb21bf 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ keyconv oclvanitygen oclvanityminer -vanitygen \ No newline at end of file +vanitygen +build/ + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..179b385 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,88 @@ +CMAKE_MINIMUM_REQUIRED(VERSION 2.8) + +PROJECT(vanitygen) +SET(CMAKE_MODULE_PATH ${vanitygen_SOURCE_DIR}) +SET(CMAKE_THREAD_PREFER_PTHREAD True) + +IF(NOT VG_OCL_SOURCE_PREFIX) + SET(VG_OCL_SOURCE_PREFIX ${vanitygen_SOURCE_DIR}/) +ENDIF(NOT VG_OCL_SOURCE_PREFIX) + +FIND_PACKAGE(OpenSSL REQUIRED) +FIND_PACKAGE(Threads REQUIRED) +FIND_PACKAGE(PCRE REQUIRED) +FIND_PACKAGE(CURL) +FIND_PACKAGE(OpenCL) + +INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${PCRE_INCLUDE_DIR}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +SET(VANY_LIBS + ${PCRE_LIBRARIES} + ${OPENSSL_LIBRARIES} + m + ${CMAKE_THREAD_LIBS_INIT} +) + +ADD_EXECUTABLE(vanitygen + vanitygen.c + pattern.c + util.c +) +TARGET_LINK_LIBRARIES(vanitygen + ${VANY_LIBS} +) +INSTALL(TARGETS vanitygen RUNTIME DESTINATION bin) + +ADD_EXECUTABLE(keyconv + keyconv.c + util.c +) +TARGET_LINK_LIBRARIES(keyconv + ${VANY_LIBS} +) +INSTALL(TARGETS keyconv RUNTIME DESTINATION bin) + +IF(OPENCL_FOUND) + INCLUDE_DIRECTORIES(${OPENCL_INCLUDE_DIRS}) + + ADD_EXECUTABLE(oclvanitygen + oclvanitygen.c + oclengine.c + pattern.c + util.c + ) + TARGET_LINK_LIBRARIES(oclvanitygen + ${VANY_LIBS} + ${OPENCL_LIBRARIES} + ) + SET_TARGET_PROPERTIES(oclvanitygen PROPERTIES +# VERSION + COMPILE_DEFINITIONS VG_OCL_SOURCE_PREFIX="${VG_OCL_SOURCE_PREFIX}/" + ) + INSTALL(TARGETS oclvanitygen RUNTIME DESTINATION bin) + INSTALL(FILES calc_addrs.cl DESTINATION share/vanitygen/scripts) + + IF(CURL_FOUND) + INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS}) + ADD_EXECUTABLE(oclvanityminer + oclvanityminer.c + oclengine.c + pattern.c + util.c + ) + TARGET_LINK_LIBRARIES(oclvanityminer + ${VANY_LIBS} + ${OPENCL_LIBRARIES} + ${CURL_LIBRARIES} + ) + INSTALL(TARGETS oclvanityminer RUNTIME DESTINATION bin) + ENDIF(CURL_FOUND) +ENDIF(OPENCL_FOUND) + + + + + + diff --git a/FindOpenCL.cmake b/FindOpenCL.cmake new file mode 100644 index 0000000..01baab2 --- /dev/null +++ b/FindOpenCL.cmake @@ -0,0 +1,103 @@ +# +# This file taken from FindOpenCL project @ http://gitorious.com/findopencl +# +# - Try to find OpenCL +# This module tries to find an OpenCL implementation on your system. It supports +# AMD / ATI, Apple and NVIDIA implementations, but shoudl work, too. +# +# Once done this will define +# OPENCL_FOUND - system has OpenCL +# OPENCL_INCLUDE_DIRS - the OpenCL include directory +# OPENCL_LIBRARIES - link these to use OpenCL +# +# WIN32 should work, but is untested + +FIND_PACKAGE( PackageHandleStandardArgs ) + +SET (OPENCL_VERSION_STRING "0.1.0") +SET (OPENCL_VERSION_MAJOR 0) +SET (OPENCL_VERSION_MINOR 1) +SET (OPENCL_VERSION_PATCH 0) + +IF (APPLE) + + FIND_LIBRARY(OPENCL_LIBRARIES OpenCL DOC "OpenCL lib for OSX") + FIND_PATH(OPENCL_INCLUDE_DIRS OpenCL/cl.h DOC "Include for OpenCL on OSX") + FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS OpenCL/cl.hpp DOC "Include for OpenCL CPP bindings on OSX") + +ELSE (APPLE) + + IF (WIN32) + + FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h) + FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp) + + # The AMD SDK currently installs both x86 and x86_64 libraries + # This is only a hack to find out architecture + IF( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" ) + SET(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86_64") + SET(OPENCL_LIB_DIR "$ENV{ATIINTERNALSTREAMSDKROOT}/lib/x86_64") + ELSE (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64") + SET(OPENCL_LIB_DIR "$ENV{ATISTREAMSDKROOT}/lib/x86") + SET(OPENCL_LIB_DIR "$ENV{ATIINTERNALSTREAMSDKROOT}/lib/x86") + ENDIF( ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64" ) + + # find out if the user asked for a 64-bit build, and use the corresponding + # 64 or 32 bit NVIDIA library paths to the search: + STRING(REGEX MATCH "Win64" ISWIN64 ${CMAKE_GENERATOR}) + IF("${ISWIN64}" STREQUAL "Win64") + FIND_LIBRARY(OPENCL_LIBRARIES OpenCL.lib ${OPENCL_LIB_DIR} $ENV{CUDA_LIB_PATH} $ENV{CUDA_PATH}/lib/x64) + ELSE("${ISWIN64}" STREQUAL "Win64") + FIND_LIBRARY(OPENCL_LIBRARIES OpenCL.lib ${OPENCL_LIB_DIR} $ENV{CUDA_LIB_PATH} $ENV{CUDA_PATH}/lib/Win32) + ENDIF("${ISWIN64}" STREQUAL "Win64") + + GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE) + + # On Win32 search relative to the library + FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS "${_OPENCL_INC_CAND}" $ENV{CUDA_INC_PATH} $ENV{CUDA_PATH}/include) + FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS "${_OPENCL_INC_CAND}" $ENV{CUDA_INC_PATH} $ENV{CUDA_PATH}/include) + + ELSE (WIN32) + + # Unix style platforms + FIND_LIBRARY(OPENCL_LIBRARIES OpenCL + ENV LD_LIBRARY_PATH + "/usr/lib/nvidia-current" + "/usr/lib/beignet" + "/usr/lib/x86_64-linux-gnu" + "/usr/lib/x86-linux-gnu" + ) + + GET_FILENAME_COMPONENT(OPENCL_LIB_DIR ${OPENCL_LIBRARIES} PATH) + GET_FILENAME_COMPONENT(_OPENCL_INC_CAND ${OPENCL_LIB_DIR}/../../include ABSOLUTE) + + # The AMD SDK currently does not place its headers + # in /usr/include, therefore also search relative + # to the library + FIND_PATH(OPENCL_INCLUDE_DIRS CL/cl.h PATHS + ${_OPENCL_INC_CAND} + "/usr/local/cuda/include" + "/usr/include/nvidia-current" + ) + FIND_PATH(_OPENCL_CPP_INCLUDE_DIRS CL/cl.hpp PATHS + ${_OPENCL_INC_CAND} + "/usr/local/cuda/include" + "/usr/include/nvidia-current" + ) + + ENDIF (WIN32) + +ENDIF (APPLE) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS( OpenCL DEFAULT_MSG OPENCL_LIBRARIES OPENCL_INCLUDE_DIRS ) + +IF( _OPENCL_CPP_INCLUDE_DIRS ) + SET( OPENCL_HAS_CPP_BINDINGS TRUE ) + LIST( APPEND OPENCL_INCLUDE_DIRS ${_OPENCL_CPP_INCLUDE_DIRS} ) + # This is often the same, so clean up + LIST( REMOVE_DUPLICATES OPENCL_INCLUDE_DIRS ) +ENDIF( _OPENCL_CPP_INCLUDE_DIRS ) + +MARK_AS_ADVANCED( + OPENCL_INCLUDE_DIRS +) diff --git a/FindPCRE.cmake b/FindPCRE.cmake new file mode 100644 index 0000000..6127f6d --- /dev/null +++ b/FindPCRE.cmake @@ -0,0 +1,53 @@ +# Martin Konrad +# License: GPLv2/v3 +# +# Try to find libpcre (Perl Compatible Regular Expressions) +# +# Once done this will define +# +# PCRE_FOUND - system has libpcre +# PCRE_INCLUDE_DIR - the libpcre include directory +# PCRE_LIBRARY - where to find libpcre +# PCRE_LIBRARIES - Link these to use libpcre + +if(PCRE_INCLUDE_DIR AND PCRE_LIBRARIES) + # in cache already + set(LIBUSB_FOUND TRUE) +else(PCRE_INCLUDE_DIR AND PCRE_LIBRARIES) + if(NOT WIN32) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + find_package(PkgConfig) + pkg_check_modules(PC_PCRE libpcre) + endif(NOT WIN32) + + find_path(PCRE_INCLUDE_DIR + NAMES + pcre.h + HINTS + ${PCRE_PKG_INCLUDE_DIRS} + PATHS + /usr/include + /usr/local/include + ) + + find_library(PCRE_LIBRARY + NAMES + pcre + HINTS + ${PCRE_PKG_LIBRARY_DIRS} + PATHS + /usr/lib + /usr/local/lib + ) + + set(PCRE_LIBRARIES ${PCRE_LIBRARY}) + + # handle the QUIETLY AND REQUIRED arguments AND set PCRE_FOUND to TRUE if + # all listed variables are TRUE + # include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(PCRE DEFAULT_MSG PCRE_LIBRARY PCRE_INCLUDE_DIR) + + mark_as_advanced(PCRE_INCLUDE_DIR PCRE_LIBRARY) +endif(PCRE_INCLUDE_DIR AND PCRE_LIBRARIES) diff --git a/oclengine.c b/oclengine.c index 4a6a232..e64a7e0 100644 --- a/oclengine.c +++ b/oclengine.c @@ -5,7 +5,7 @@ * Vanitygen is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or - * any later version. + * any later version. * * Vanitygen is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -49,6 +49,10 @@ #define is_pow2(v) (!((v) & ((v)-1))) #define round_up_pow2(x, a) (((x) + ((a)-1)) & ~((a)-1)) +#ifndef VG_OCL_SOURCE_PREFIX + #define VG_OCL_SOURCE_PREFIX +#endif // VG_OCL_SOURCE_PREFIX + static void vg_ocl_free_args(vg_ocl_context_t *vocp); static void *vg_opencl_loop(vg_exec_context_t *arg); @@ -399,6 +403,7 @@ enum { VG_OCL_NV_VERBOSE = (1 << 5), VG_OCL_BROKEN = (1 << 6), VG_OCL_NO_BINARIES = (1 << 7), + VG_OCL_NO_CALLBACK = (1 << 8), VG_OCL_OPTIMIZATIONS = (VG_OCL_DEEP_PREPROC_UNROLL | VG_OCL_PRAGMA_UNROLL | @@ -453,6 +458,10 @@ vg_ocl_get_quirks(vg_ocl_context_t *vocp) } } break; + case 0x0166: /* Intel */ + quirks |= VG_OCL_NO_CALLBACK; + quirks &= ~VG_OCL_DEEP_PREPROC_UNROLL; + break; default: break; } @@ -897,7 +906,7 @@ vg_ocl_init(vg_context_t *vcp, vg_ocl_context_t *vocp, cl_device_id did, vocp->voc_oclctx = clCreateContext(NULL, 1, &did, - vg_ocl_context_callback, + ((vocp->voc_quirks & VG_OCL_NO_CALLBACK) ? NULL : vg_ocl_context_callback), NULL, &ret); if (!vocp->voc_oclctx) { @@ -937,7 +946,7 @@ vg_ocl_init(vg_context_t *vcp, vg_ocl_context_t *vocp, cl_device_id did, end += snprintf(optbuf + end, sizeof(optbuf) - end, "-cl-nv-verbose "); - if (!vg_ocl_load_program(vcp, vocp, "calc_addrs.cl", optbuf)) + if (!vg_ocl_load_program(vcp, vocp, VG_OCL_SOURCE_PREFIX "calc_addrs.cl", optbuf)) return 0; return 1; } @@ -1023,7 +1032,7 @@ vg_ocl_kernel_arg_alloc(vg_ocl_context_t *vocp, int slot, karg, sizeof(clbuf), &clbuf); - + if (ret) { fprintf(stderr, "clSetKernelArg(%d,%d): ", knum, karg); @@ -1055,7 +1064,7 @@ vg_ocl_copyout_arg(vg_ocl_context_t *vocp, int wslot, int arg, buffer, 0, NULL, NULL); - + if (ret) { fprintf(stderr, "clEnqueueWriteBuffer(%d): ", arg); vg_ocl_error(vocp, ret, NULL); @@ -2182,7 +2191,7 @@ vg_opencl_loop(vg_exec_context_t *arg) slot_busy = 1; slot = (slot + 1) % nslots; - } else { + } else { if (slot_busy) { pthread_mutex_lock(&vocp->voc_lock); while (vocp->voc_ocl_slot != -1) {