diff options
Diffstat (limited to 'test_conformance/math_brute_force/ternary_float.cpp')
-rw-r--r-- | test_conformance/math_brute_force/ternary_float.cpp | 126 |
1 files changed, 58 insertions, 68 deletions
diff --git a/test_conformance/math_brute_force/ternary_float.cpp b/test_conformance/math_brute_force/ternary_float.cpp index cf361841..d11f4ba3 100644 --- a/test_conformance/math_brute_force/ternary_float.cpp +++ b/test_conformance/math_brute_force/ternary_float.cpp @@ -27,32 +27,16 @@ namespace { -int BuildKernel(const char *name, int vectorSize, cl_kernel *k, cl_program *p, - bool relaxedMode) -{ - auto kernel_name = GetKernelName(vectorSize); - auto source = GetTernaryKernel(kernel_name, name, ParameterType::Float, - ParameterType::Float, ParameterType::Float, - ParameterType::Float, vectorSize); - std::array<const char *, 1> sources{ source.c_str() }; - return MakeKernel(sources.data(), sources.size(), kernel_name.c_str(), k, p, - relaxedMode); -} - -struct BuildKernelInfo2 -{ - cl_kernel *kernels; - Programs &programs; - const char *nameInCode; - bool relaxedMode; // Whether to build with -cl-fast-relaxed-math. -}; - cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p) { - BuildKernelInfo2 *info = (BuildKernelInfo2 *)p; - cl_uint vectorSize = gMinVectorSizeIndex + job_id; - return BuildKernel(info->nameInCode, vectorSize, info->kernels + vectorSize, - &(info->programs[vectorSize]), info->relaxedMode); + BuildKernelInfo &info = *(BuildKernelInfo *)p; + auto generator = [](const std::string &kernel_name, const char *builtin, + cl_uint vector_size_index) { + return GetTernaryKernel(kernel_name, builtin, ParameterType::Float, + ParameterType::Float, ParameterType::Float, + ParameterType::Float, vector_size_index); + }; + return BuildKernels(info, job_id, generator); } // A table of more difficult cases to get right @@ -146,7 +130,8 @@ int TestFunc_Float_Float_Float_Float(const Func *f, MTdata d, bool relaxedMode) logFunctionInfo(f->name, sizeof(cl_float), relaxedMode); Programs programs; - cl_kernel kernels[VECTOR_SIZE_COUNT]; + const unsigned thread_id = 0; // Test is currently not multithreaded. + KernelMatrix kernels; float maxError = 0.0f; int ftz = f->ftz || gForceFTZ || 0 == (CL_FP_DENORM & gFloatCapabilities); float maxErrorVal = 0.0f; @@ -165,14 +150,12 @@ int TestFunc_Float_Float_Float_Float(const Func *f, MTdata d, bool relaxedMode) int skipNanInf = (0 == strcmp("fma", f->nameInCode)) && !gInfNanSupport; // Init the kernels - { - BuildKernelInfo2 build_info{ kernels, programs, f->nameInCode, - relaxedMode }; - if ((error = ThreadPool_Do(BuildKernelFn, - gMaxVectorSizeIndex - gMinVectorSizeIndex, - &build_info))) - return error; - } + BuildKernelInfo build_info{ 1, kernels, programs, f->nameInCode, + relaxedMode }; + if ((error = ThreadPool_Do(BuildKernelFn, + gMaxVectorSizeIndex - gMinVectorSizeIndex, + &build_info))) + return error; for (uint64_t i = 0; i < (1ULL << 32); i += step) { @@ -237,18 +220,33 @@ int TestFunc_Float_Float_Float_Float(const Func *f, MTdata d, bool relaxedMode) return error; } - // write garbage into output arrays + // Write garbage into output arrays for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++) { uint32_t pattern = 0xffffdead; - memset_pattern4(gOut[j], &pattern, BUFFER_SIZE); - if ((error = - clEnqueueWriteBuffer(gQueue, gOutBuffer[j], CL_FALSE, 0, - BUFFER_SIZE, gOut[j], 0, NULL, NULL))) + if (gHostFill) { - vlog_error("\n*** Error %d in clEnqueueWriteBuffer2(%d) ***\n", - error, j); - goto exit; + memset_pattern4(gOut[j], &pattern, BUFFER_SIZE); + if ((error = clEnqueueWriteBuffer(gQueue, gOutBuffer[j], + CL_FALSE, 0, BUFFER_SIZE, + gOut[j], 0, NULL, NULL))) + { + vlog_error( + "\n*** Error %d in clEnqueueWriteBuffer2(%d) ***\n", + error, j); + return error; + } + } + else + { + if ((error = clEnqueueFillBuffer(gQueue, gOutBuffer[j], + &pattern, sizeof(pattern), 0, + BUFFER_SIZE, 0, NULL, NULL))) + { + vlog_error("Error: clEnqueueFillBuffer failed! err: %d\n", + error); + return error; + } } } @@ -258,37 +256,37 @@ int TestFunc_Float_Float_Float_Float(const Func *f, MTdata d, bool relaxedMode) size_t vectorSize = sizeof(cl_float) * sizeValues[j]; size_t localCount = (BUFFER_SIZE + vectorSize - 1) / vectorSize; // BUFFER_SIZE / vectorSize rounded up - if ((error = clSetKernelArg(kernels[j], 0, sizeof(gOutBuffer[j]), - &gOutBuffer[j]))) + if ((error = clSetKernelArg(kernels[j][thread_id], 0, + sizeof(gOutBuffer[j]), &gOutBuffer[j]))) { LogBuildError(programs[j]); - goto exit; + return error; } - if ((error = clSetKernelArg(kernels[j], 1, sizeof(gInBuffer), - &gInBuffer))) + if ((error = clSetKernelArg(kernels[j][thread_id], 1, + sizeof(gInBuffer), &gInBuffer))) { LogBuildError(programs[j]); - goto exit; + return error; } - if ((error = clSetKernelArg(kernels[j], 2, sizeof(gInBuffer2), - &gInBuffer2))) + if ((error = clSetKernelArg(kernels[j][thread_id], 2, + sizeof(gInBuffer2), &gInBuffer2))) { LogBuildError(programs[j]); - goto exit; + return error; } - if ((error = clSetKernelArg(kernels[j], 3, sizeof(gInBuffer3), - &gInBuffer3))) + if ((error = clSetKernelArg(kernels[j][thread_id], 3, + sizeof(gInBuffer3), &gInBuffer3))) { LogBuildError(programs[j]); - goto exit; + return error; } - if ((error = - clEnqueueNDRangeKernel(gQueue, kernels[j], 1, NULL, - &localCount, NULL, 0, NULL, NULL))) + if ((error = clEnqueueNDRangeKernel(gQueue, kernels[j][thread_id], + 1, NULL, &localCount, NULL, 0, + NULL, NULL))) { vlog_error("FAILED -- could not execute kernel\n"); - goto exit; + return error; } } @@ -326,7 +324,7 @@ int TestFunc_Float_Float_Float_Float(const Func *f, MTdata d, bool relaxedMode) BUFFER_SIZE, gOut[j], 0, NULL, NULL))) { vlog_error("ReadArray failed %d\n", error); - goto exit; + return error; } } @@ -754,8 +752,7 @@ int TestFunc_Float_Float_Float_Float(const Func *f, MTdata d, bool relaxedMode) f->name, sizeNames[k], err, s[j], s2[j], s3[j], ((cl_uint *)s)[j], ((cl_uint *)s2)[j], ((cl_uint *)s3)[j], ((float *)gOut_Ref)[j], test); - error = -1; - goto exit; + return -1; } } } @@ -789,12 +786,5 @@ int TestFunc_Float_Float_Float_Float(const Func *f, MTdata d, bool relaxedMode) vlog("\n"); -exit: - // Release - for (auto k = gMinVectorSizeIndex; k < gMaxVectorSizeIndex; k++) - { - clReleaseKernel(kernels[k]); - } - - return error; + return CL_SUCCESS; } |