Skip to content

Commit

Permalink
Merge branch 'main' into fp16_basic_explicit_s2v
Browse files Browse the repository at this point in the history
  • Loading branch information
shajder committed Jul 6, 2023
2 parents b067494 + 9e8430a commit 94fa1ef
Show file tree
Hide file tree
Showing 128 changed files with 7,180 additions and 8,827 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ if(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?Clang"
add_cxx_flag_if_supported(-Wall)
# Suppress warnings that currently trigger on the code base.
# This list should shrink over time when warnings are fixed.
add_cxx_flag_if_supported(-Wno-unused-but-set-variable)
add_cxx_flag_if_supported(-Wno-sometimes-uninitialized)
add_cxx_flag_if_supported(-Wno-sign-compare)
endif()
add_cxx_flag_if_supported(-Wno-narrowing)
Expand Down
1 change: 0 additions & 1 deletion presubmit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ cmake .. -G Ninja \
-DBUILD_WSI_XLIB_SUPPORT=OFF \
-DBUILD_WSI_XCB_SUPPORT=OFF \
-DBUILD_WSI_WAYLAND_SUPPORT=OFF \
-DUSE_GAS=OFF \
-C helper.cmake ..
cmake --build . -j2

Expand Down
4 changes: 2 additions & 2 deletions test_common/gl/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ void * CreateGLRenderbuffer( GLsizei width, GLsizei height,
// Reverse and reorder to validate since in the
// kernel the read_imagef() call always returns RGBA
cl_uchar *p = (cl_uchar *)buffer;
for( size_t i = 0; i < (size_t)width * height; i++ )
for (GLsizei i = 0; i < width * height; i++)
{
cl_uchar uc0 = p[i * 4 + 0];
cl_uchar uc1 = p[i * 4 + 1];
Expand All @@ -1733,7 +1733,7 @@ void * CreateGLRenderbuffer( GLsizei width, GLsizei height,
// Reverse and reorder to validate since in the
// kernel the read_imagef() call always returns RGBA
cl_uchar *p = (cl_uchar *)buffer;
for( size_t i = 0; i < width * height; i++ )
for (GLsizei i = 0; i < width * height; i++)
{
cl_uchar uc0 = p[i * 4 + 0];
cl_uchar uc1 = p[i * 4 + 1];
Expand Down
6 changes: 3 additions & 3 deletions test_common/harness/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef _COMPAT_H_
#define _COMPAT_H_
#ifndef COMPAT_H_
#define COMPAT_H_

#if defined(_WIN32) && defined(_MSC_VER)
#include <Windows.h>
Expand Down Expand Up @@ -398,4 +398,4 @@ EXTERN_C int __builtin_clz(unsigned int pattern);
#define sleep(sec) Sleep((sec)*1000)
#endif

#endif // _COMPAT_H_
#endif // COMPAT_H_
4 changes: 2 additions & 2 deletions test_common/harness/crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Agreement or Khronos Conformance Test Source License Agreement as
executed between Khronos and the recipient.
******************************************************************/

#ifndef _CRC32_H_
#define _CRC32_H_
#ifndef CRC32_H_
#define CRC32_H_

#include <stdint.h>
#include <stddef.h>
Expand Down
10 changes: 0 additions & 10 deletions test_common/harness/imageHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3537,7 +3537,6 @@ void copy_image_data(image_descriptor *srcImageInfo,
{
size_t src_width_lod = 1 /*srcImageInfo->width*/;
size_t src_height_lod = 1 /*srcImageInfo->height*/;
size_t src_depth_lod = 1 /*srcImageInfo->depth*/;

switch (srcImageInfo->type)
{
Expand Down Expand Up @@ -3572,10 +3571,6 @@ void copy_image_data(image_descriptor *srcImageInfo,
src_height_lod = (srcImageInfo->height >> src_lod)
? (srcImageInfo->height >> src_lod)
: 1;
if (srcImageInfo->type == CL_MEM_OBJECT_IMAGE3D)
src_depth_lod = (srcImageInfo->depth >> src_lod)
? (srcImageInfo->depth >> src_lod)
: 1;
break;
}
src_mip_level_offset = compute_mip_level_offset(srcImageInfo, src_lod);
Expand All @@ -3588,7 +3583,6 @@ void copy_image_data(image_descriptor *srcImageInfo,
{
size_t dst_width_lod = 1 /*dstImageInfo->width*/;
size_t dst_height_lod = 1 /*dstImageInfo->height*/;
size_t dst_depth_lod = 1 /*dstImageInfo->depth*/;
switch (dstImageInfo->type)
{
case CL_MEM_OBJECT_IMAGE1D:
Expand Down Expand Up @@ -3622,10 +3616,6 @@ void copy_image_data(image_descriptor *srcImageInfo,
dst_height_lod = (dstImageInfo->height >> dst_lod)
? (dstImageInfo->height >> dst_lod)
: 1;
if (dstImageInfo->type == CL_MEM_OBJECT_IMAGE3D)
dst_depth_lod = (dstImageInfo->depth >> dst_lod)
? (dstImageInfo->depth >> dst_lod)
: 1;
break;
}
dst_mip_level_offset = compute_mip_level_offset(dstImageInfo, dst_lod);
Expand Down
20 changes: 20 additions & 0 deletions test_common/harness/parseParameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ std::string gCompilationCachePath = ".";
std::string gCompilationProgram = DEFAULT_COMPILATION_PROGRAM;
bool gDisableSPIRVValidation = false;
std::string gSPIRVValidator = DEFAULT_SPIRV_VALIDATOR;
unsigned gNumWorkerThreads;

void helpInfo()
{
Expand All @@ -48,6 +49,8 @@ void helpInfo()
online Use online compilation (default)
binary Use binary offline compilation
spir-v Use SPIR-V offline compilation
--num-worker-threads <num>
Select parallel execution with the specified number of worker threads.
For offline compilation (binary and spir-v modes) only:
--compilation-cache-mode <cache-mode>
Expand Down Expand Up @@ -137,6 +140,23 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore)
return -1;
}
}
else if (!strcmp(argv[i], "--num-worker-threads"))
{
delArg++;
if ((i + 1) < argc)
{
delArg++;
const char *numthstr = argv[i + 1];

gNumWorkerThreads = atoi(numthstr);
}
else
{
log_error(
"A parameter to --num-worker-threads must be provided!\n");
return -1;
}
}
else if (!strcmp(argv[i], "--compilation-cache-mode"))
{
delArg++;
Expand Down
41 changes: 41 additions & 0 deletions test_common/harness/stringHelpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright (c) 2023 The Khronos Group Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#ifndef STRING_HELPERS_H
#define STRING_HELPERS_H

#include <memory>
#include <string>

inline std::string concat_kernel(const char *sstr[], int num)
{
std::string res;
for (int i = 0; i < num; i++) res += std::string(sstr[i]);
return res;
}

template <typename... Args>
inline std::string str_sprintf(const std::string &str, Args... args)
{
int str_size = std::snprintf(nullptr, 0, str.c_str(), args...) + 1;
if (str_size <= 0) throw std::runtime_error("Formatting error.");
size_t s = static_cast<size_t>(str_size);
std::unique_ptr<char[]> buffer(new char[s]);
std::snprintf(buffer.get(), s, str.c_str(), args...);
return std::string(buffer.get(), buffer.get() + s - 1);
}

#endif // STRING_HELPERS_H
130 changes: 104 additions & 26 deletions test_common/harness/testHarness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#include <stdlib.h>
#include <string.h>
#include <cassert>
#include <deque>
#include <mutex>
#include <stdexcept>
#include <thread>
#include <vector>
#include "errorHelpers.h"
#include "kernelHelpers.h"
Expand Down Expand Up @@ -583,10 +586,12 @@ int runTestHarnessWithCheck(int argc, const char *argv[], int testNum,
FPU_mode_type oldMode;
DisableFTZ(&oldMode);
#endif
extern unsigned gNumWorkerThreads;
test_harness_config config = { forceNoContextCreation, num_elements,
queueProps, gNumWorkerThreads };

int error = parseAndCallCommandLineTests(argc, argv, device, testNum,
testList, forceNoContextCreation,
queueProps, num_elements);
testList, config);

#if defined(__APPLE__) && defined(__arm__)
// Restore the old FP mode before leaving.
Expand Down Expand Up @@ -677,9 +682,7 @@ static void print_results(int failed, int count, const char *name)
int parseAndCallCommandLineTests(int argc, const char *argv[],
cl_device_id device, int testNum,
test_definition testList[],
int forceNoContextCreation,
cl_command_queue_properties queueProps,
int num_elements)
const test_harness_config &config)
{
int ret = EXIT_SUCCESS;

Expand Down Expand Up @@ -725,8 +728,7 @@ int parseAndCallCommandLineTests(int argc, const char *argv[],
std::vector<test_status> resultTestList(testNum, TEST_PASS);

callTestFunctions(testList, selectedTestList, resultTestList.data(),
testNum, device, forceNoContextCreation, num_elements,
queueProps);
testNum, device, config);

print_results(gFailCount, gTestCount, "sub-test");
print_results(gTestsFailed, gTestsFailed + gTestsPassed, "test");
Expand Down Expand Up @@ -754,21 +756,97 @@ int parseAndCallCommandLineTests(int argc, const char *argv[],
return ret;
}

struct test_harness_state
{
test_definition *tests;
test_status *results;
cl_device_id device;
test_harness_config config;
};

static std::deque<int> gTestQueue;
static std::mutex gTestStateMutex;

void test_function_runner(test_harness_state *state)
{
int testID;
test_definition test;
while (true)
{
// Attempt to get a test
{
std::lock_guard<std::mutex> lock(gTestStateMutex);

// The queue is empty, we're done
if (gTestQueue.size() == 0)
{
return;
}

// Get the test at the front of the queue
testID = gTestQueue.front();
gTestQueue.pop_front();
test = state->tests[testID];
}

// Execute test
auto status =
callSingleTestFunction(test, state->device, state->config);

// Store result
{
std::lock_guard<std::mutex> lock(gTestStateMutex);
state->results[testID] = status;
}
}
}

void callTestFunctions(test_definition testList[],
unsigned char selectedTestList[],
test_status resultTestList[], int testNum,
cl_device_id deviceToUse, int forceNoContextCreation,
int numElementsToUse,
cl_command_queue_properties queueProps)
cl_device_id deviceToUse,
const test_harness_config &config)
{
for (int i = 0; i < testNum; ++i)
// Execute tests serially
if (config.numWorkerThreads == 0)
{
if (selectedTestList[i])
for (int i = 0; i < testNum; ++i)
{
if (selectedTestList[i])
{
resultTestList[i] =
callSingleTestFunction(testList[i], deviceToUse, config);
}
}
// Execute tests in parallel with the specified number of worker threads
}
else
{
// Queue all tests that need to run
for (int i = 0; i < testNum; ++i)
{
if (selectedTestList[i])
{
gTestQueue.push_back(i);
}
}

// Spawn thread pool
std::vector<std::thread *> threads;
test_harness_state state = { testList, resultTestList, deviceToUse,
config };
for (unsigned i = 0; i < config.numWorkerThreads; i++)
{
log_info("Spawning worker thread %u\n", i);
threads.push_back(new std::thread(test_function_runner, &state));
}

// Wait for all threads to complete
for (auto th : threads)
{
resultTestList[i] = callSingleTestFunction(
testList[i], deviceToUse, forceNoContextCreation,
numElementsToUse, queueProps);
th->join();
}
assert(gTestQueue.size() == 0);
}
}

Expand All @@ -781,9 +859,7 @@ void CL_CALLBACK notify_callback(const char *errinfo, const void *private_info,
// Actual function execution
test_status callSingleTestFunction(test_definition test,
cl_device_id deviceToUse,
int forceNoContextCreation,
int numElementsToUse,
const cl_queue_properties queueProps)
const test_harness_config &config)
{
test_status status;
cl_int error;
Expand Down Expand Up @@ -811,7 +887,7 @@ test_status callSingleTestFunction(test_definition test,
}

/* Create a context to work with, unless we're told not to */
if (!forceNoContextCreation)
if (!config.forceNoContextCreation)
{
context = clCreateContext(NULL, 1, &deviceToUse, notify_callback, NULL,
&error);
Expand All @@ -825,15 +901,16 @@ test_status callSingleTestFunction(test_definition test,

if (device_version < Version(2, 0))
{
queue =
clCreateCommandQueue(context, deviceToUse, queueProps, &error);
queue = clCreateCommandQueue(context, deviceToUse,
config.queueProps, &error);
}
else
{
const cl_command_queue_properties cmd_queueProps =
(queueProps) ? CL_QUEUE_PROPERTIES : 0;
cl_command_queue_properties queueCreateProps[] = { cmd_queueProps,
queueProps, 0 };
(config.queueProps) ? CL_QUEUE_PROPERTIES : 0;
cl_command_queue_properties queueCreateProps[] = {
cmd_queueProps, config.queueProps, 0
};
queue = clCreateCommandQueueWithProperties(
context, deviceToUse, &queueCreateProps[0], &error);
}
Expand All @@ -858,7 +935,8 @@ test_status callSingleTestFunction(test_definition test,
}
else
{
int ret = test.func(deviceToUse, context, queue, numElementsToUse);
int ret =
test.func(deviceToUse, context, queue, config.numElementsToUse);
if (ret == TEST_SKIPPED_ITSELF)
{
/* Tests can also let us know they're not supported by the
Expand All @@ -885,7 +963,7 @@ test_status callSingleTestFunction(test_definition test,
}

/* Release the context */
if (!forceNoContextCreation)
if (!config.forceNoContextCreation)
{
int error = clFinish(queue);
if (error)
Expand Down
Loading

0 comments on commit 94fa1ef

Please sign in to comment.