diff --git a/xmrstak/backend/amd/amd_gpu/gpu.cpp b/xmrstak/backend/amd/amd_gpu/gpu.cpp index a2cbe8f54..5005a914e 100644 --- a/xmrstak/backend/amd/amd_gpu/gpu.cpp +++ b/xmrstak/backend/amd/amd_gpu/gpu.cpp @@ -774,7 +774,7 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, size_t platform_idx) // Same as the platform index sanity check, except we must check all requested device indexes for(int i = 0; i < num_gpus; ++i) { - if(entries <= ctx[i].deviceIdx) + if(entries < ctx[i].deviceIdx) { printer::inst()->print_msg(L1,"Selected OpenCL device index %lu doesn't exist.\n", ctx[i].deviceIdx); return ERR_STUPID_PARAMS; @@ -793,17 +793,22 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, size_t platform_idx) } // Indexes sanity checked above -#ifdef __GNUC__ - cl_device_id TempDeviceList[num_gpus]; -#else - cl_device_id* TempDeviceList = (cl_device_id*)_alloca(entries * sizeof(cl_device_id)); -#endif + std::vector TempDeviceList(num_gpus, nullptr); + + printer::inst()->print_msg(LDEBUG, "Number of OpenCL GPUs %d", entries); for(int i = 0; i < num_gpus; ++i) { ctx[i].DeviceID = DeviceIDList[ctx[i].deviceIdx]; TempDeviceList[i] = DeviceIDList[ctx[i].deviceIdx]; } + cl_context opencl_ctx = clCreateContext(NULL, num_gpus, TempDeviceList.data(), NULL, NULL, &ret); + if(ret != CL_SUCCESS) + { + printer::inst()->print_msg(L1,"Error %s when calling clCreateContext.", err_to_str(ret)); + return ERR_OCL_API; + } + const char *fastIntMathV2CL = #include "./opencl/fast_int_math_v2.cl" ; @@ -847,22 +852,9 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, size_t platform_idx) std::vector> interleaveData(num_gpus, nullptr); - std::vector context_vec(entries, nullptr); - for(int i = 0; i < num_gpus; ++i) - { - if(context_vec[ctx[i].deviceIdx] == nullptr) - { - context_vec[ctx[i].deviceIdx] = clCreateContext(NULL, 1, &(ctx[i].DeviceID), NULL, NULL, &ret); - if(ret != CL_SUCCESS) - { - printer::inst()->print_msg(L1,"Error %s when calling clCreateContext.", err_to_str(ret)); - return ERR_OCL_API; - } - } - } - for(int i = 0; i < num_gpus; ++i) { + printer::inst()->print_msg(LDEBUG,"OpenCL Init device %d", ctx[i].deviceIdx); const size_t devIdx = ctx[i].deviceIdx; if(interleaveData.size() <= devIdx) { @@ -879,7 +871,7 @@ size_t InitOpenCL(GpuContext* ctx, size_t num_gpus, size_t platform_idx) ctx[i].interleaveData = interleaveData[devIdx]; ctx[i].interleaveData->adjustThreshold = static_cast(ctx[i].interleave)/100.0; ctx[i].interleaveData->startAdjustThreshold = ctx[i].interleaveData->adjustThreshold; - ctx[i].opencl_ctx = context_vec[ctx[i].deviceIdx]; + ctx[i].opencl_ctx = opencl_ctx; if((ret = InitOpenCLGpu(ctx->opencl_ctx, &ctx[i], source_code.c_str())) != ERR_SUCCESS) {