From 52ae2d7fd8b6d70a9179ab73fa8a0c782ded80d9 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 6 Apr 2016 19:53:53 -0500 Subject: [PATCH] Fixing some opencl issues. --- rai/node/openclwork.cpp | 49 +++++++++++++++++++--------------- rai/node/wallet.cpp | 4 +++ rai/plat/posix/openclapi.cpp | 7 +++++ rai/plat/windows/openclapi.cpp | 7 +++++ 4 files changed, 45 insertions(+), 22 deletions(-) diff --git a/rai/node/openclwork.cpp b/rai/node/openclwork.cpp index d676f94e..9d2d9cb0 100644 --- a/rai/node/openclwork.cpp +++ b/rai/node/openclwork.cpp @@ -160,6 +160,15 @@ static inline ulong rotr64( const ulong w, const unsigned c ) return ( w >> c ) | ( w << ( 64 - c ) ); } +static void ucharset (void * dest_a, int val, size_t count) +{ + uchar * dest = (uchar *)dest_a; + for (size_t i = 0; i < count; ++i) + { + *dest++ = val; + } +} + /* init xors IV with input parameter block */ static inline int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) { @@ -168,7 +177,7 @@ static inline int blake2b_init_param( blake2b_state *S, const blake2b_param *P ) h = ( uchar * )( S->h ); p = ( uchar * )( P ); /* IV XOR ParamBlock */ - memset( S, 0, sizeof( blake2b_state ) ); + ucharset( S, 0, sizeof( blake2b_state ) ); for( int i = 0; i < BLAKE2B_OUTBYTES; ++i ) h[i] = v[i] ^ p[i]; @@ -189,9 +198,9 @@ static inline int blake2b_init( blake2b_state *S, const uchar outlen ) store64( &P->node_offset, 0 ); P->node_depth = 0; P->inner_length = 0; - memset( P->reserved, 0, sizeof( P->reserved ) ); - memset( P->salt, 0, sizeof( P->salt ) ); - memset( P->personal, 0, sizeof( P->personal ) ); + ucharset( P->reserved, 0, sizeof( P->reserved ) ); + ucharset( P->salt, 0, sizeof( P->salt ) ); + ucharset( P->personal, 0, sizeof( P->personal ) ); return blake2b_init_param( S, P ); } @@ -307,14 +316,6 @@ static int blake2b_update( blake2b_state *S, const uchar *in, ulong inlen ) return 0; } -static void ucharset (uchar * dest, int val, size_t count) -{ - for (size_t i = 0; i < count; ++i) - { - *dest++ = val; - } -} - /* Is this correct? */ static int blake2b_final( blake2b_state *S, uchar *out, uchar outlen ) { @@ -496,7 +497,7 @@ pool (pool_a) auto i (environment_a.devices.begin ()); auto selected_platform (i->first); std::array selected_devices; - selected_devices [0] = i->second [1]; + selected_devices [0] = i->second [0]; cl_context_properties contextProperties [] = { CL_CONTEXT_PLATFORM, @@ -536,17 +537,10 @@ pool (pool_a) error_a |= program_error != CL_SUCCESS; if (!error_a) { - error_a |= clBuildProgram (program, selected_devices.size (), selected_devices.data (), "-D __APPLE__", nullptr, nullptr) != CL_SUCCESS; + auto clBuildProgramError(clBuildProgram(program, selected_devices.size(), selected_devices.data(), "-D __APPLE__", nullptr, nullptr)); + error_a |= clBuildProgramError != CL_SUCCESS; if (!error_a) { - /*for (auto i (selected_devices.begin ()), n (selected_devices.end ()); i != n; ++i) - { - size_t log_size (0); - clGetProgramBuildInfo (program, *i, CL_PROGRAM_BUILD_LOG, 0, nullptr, &log_size); - std::vector log (log_size); - clGetProgramBuildInfo (program, *i, CL_PROGRAM_BUILD_LOG, log.size (), log.data (), nullptr); - std::cout << log.data () << std::endl; - }*/ cl_int kernel_error (0); kernel = clCreateKernel (program, "raiblocks_work", &kernel_error); error_a |= kernel_error != CL_SUCCESS; @@ -566,6 +560,17 @@ pool (pool_a) } } } + else + { + for (auto i (selected_devices.begin ()), n (selected_devices.end ()); i != n; ++i) + { + size_t log_size (0); + clGetProgramBuildInfo (program, *i, CL_PROGRAM_BUILD_LOG, 0, nullptr, &log_size); + std::vector log (log_size); + clGetProgramBuildInfo (program, *i, CL_PROGRAM_BUILD_LOG, log.size (), log.data (), nullptr); + std::cout << log.data () << std::endl; + } + } } } } diff --git a/rai/node/wallet.cpp b/rai/node/wallet.cpp index 8293c8af..29ad6c47 100644 --- a/rai/node/wallet.cpp +++ b/rai/node/wallet.cpp @@ -33,6 +33,10 @@ done (false) auto error (false); rai::opencl_environment environment (error); opencl.reset (new rai::opencl_work (error, environment, *this)); + if (error) + { + opencl.reset(); + } } } diff --git a/rai/plat/posix/openclapi.cpp b/rai/plat/posix/openclapi.cpp index d0cb3151..4b3240a0 100644 --- a/rai/plat/posix/openclapi.cpp +++ b/rai/plat/posix/openclapi.cpp @@ -21,6 +21,7 @@ public: clCreateBuffer = reinterpret_cast (dlsym(opencl_library, "clCreateBuffer")); clCreateProgramWithSource = reinterpret_cast (dlsym(opencl_library, "clCreateProgramWithSource")); clBuildProgram = reinterpret_cast (dlsym(opencl_library, "clBuildProgram")); + clGetProgramBuildInfo = reinterpret_cast (GetProcAddress(opencl_library, "clGetProgramBuildInfo")); clCreateKernel = reinterpret_cast (dlsym(opencl_library, "clCreateKernel")); clSetKernelArg = reinterpret_cast (dlsym(opencl_library, "clSetKernelArg")); clReleaseKernel = reinterpret_cast (dlsym(opencl_library, "clReleaseKernel")); @@ -46,6 +47,7 @@ public: cl_mem (* clCreateBuffer) (cl_context, cl_mem_flags, size_t, void *, cl_int *); cl_program (* clCreateProgramWithSource) (cl_context, cl_uint, char const **, size_t const *, cl_int *); cl_int (* clBuildProgram) (cl_program, cl_uint, cl_device_id const *, char const *, void (*)(cl_program, void *), void *); + cl_int(*clGetProgramBuildInfo) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *); cl_kernel (* clCreateKernel) (cl_program, char const *, cl_int *); cl_int (* clSetKernelArg) (cl_kernel, cl_uint, size_t, void const *); cl_int (* clReleaseKernel) (cl_kernel); @@ -116,6 +118,11 @@ cl_int clBuildProgram (cl_program program, cl_uint num_devices, cl_device_id con return opencl_initializer::initializer.clBuildProgram (program, num_devices, device_list, options, pfn_notify, user_data); } +cl_int clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) +{ + return opencl_initializer::initializer.clGetProgramBuildInfo(program, device, param_name, param_value_size, param_value, param_value_size_ret); +} + cl_kernel clCreateKernel (cl_program program, char const * kernel_name, cl_int * errcode_ret) { return opencl_initializer::initializer.clCreateKernel (program, kernel_name, errcode_ret); diff --git a/rai/plat/windows/openclapi.cpp b/rai/plat/windows/openclapi.cpp index 8a685f9a..46883c89 100644 --- a/rai/plat/windows/openclapi.cpp +++ b/rai/plat/windows/openclapi.cpp @@ -21,6 +21,7 @@ namespace clCreateBuffer = reinterpret_cast (GetProcAddress(opencl_library, "clCreateBuffer")); clCreateProgramWithSource = reinterpret_cast (GetProcAddress(opencl_library, "clCreateProgramWithSource")); clBuildProgram = reinterpret_cast (GetProcAddress(opencl_library, "clBuildProgram")); + clGetProgramBuildInfo = reinterpret_cast (GetProcAddress(opencl_library, "clGetProgramBuildInfo")); clCreateKernel = reinterpret_cast (GetProcAddress(opencl_library, "clCreateKernel")); clSetKernelArg = reinterpret_cast (GetProcAddress(opencl_library, "clSetKernelArg")); clReleaseKernel = reinterpret_cast (GetProcAddress(opencl_library, "clReleaseKernel")); @@ -46,6 +47,7 @@ namespace cl_mem(*clCreateBuffer) (cl_context, cl_mem_flags, size_t, void *, cl_int *); cl_program(*clCreateProgramWithSource) (cl_context, cl_uint, char const **, size_t const *, cl_int *); cl_int(*clBuildProgram) (cl_program, cl_uint, cl_device_id const *, char const *, void(*)(cl_program, void *), void *); + cl_int (*clGetProgramBuildInfo) (cl_program, cl_device_id, cl_program_build_info, size_t, void *, size_t *); cl_kernel(*clCreateKernel) (cl_program, char const *, cl_int *); cl_int(*clSetKernelArg) (cl_kernel, cl_uint, size_t, void const *); cl_int(*clReleaseKernel) (cl_kernel); @@ -119,6 +121,11 @@ cl_int clBuildProgram(cl_program program, cl_uint num_devices, cl_device_id cons return opencl_initializer::initializer.clBuildProgram(program, num_devices, device_list, options, pfn_notify, user_data); } +cl_int clGetProgramBuildInfo(cl_program program, cl_device_id device, cl_program_build_info param_name, size_t param_value_size, void * param_value, size_t * param_value_size_ret) +{ + return opencl_initializer::initializer.clGetProgramBuildInfo(program, device, param_name, param_value_size, param_value, param_value_size_ret); +} + cl_kernel clCreateKernel(cl_program program, char const * kernel_name, cl_int * errcode_ret) { return opencl_initializer::initializer.clCreateKernel(program, kernel_name, errcode_ret);