Код: Выделить всё
#define CL_HPP_TARGET_OPENCL_VERSION 300
#define CL_HPP_ENABLE_EXCEPTIONS
//This function can throw exceptions
int clSearch(const std::string& str, const std::string& substr) {
PROFILE_FUNCTION();
int hostResult = -1;
Timer* setupTimer = new Timer("Setup Context and Queue");
// Create context (first available device)
cl::Context context(CL_DEVICE_TYPE_DEFAULT);
// Create a command queue
cl::CommandQueue queue(context);
delete setupTimer;
//Each work-item checks if 'substr' occurs at position `i` of 'str'.
std::string kernelSource = R"(
__kernel void searchNaive(
__global const char* text,
__global const char* pattern,
const int textLen,
const int patternLen,
__global int* result
)
{
int i = get_global_id(0);
// If there's room for the pattern starting at i:
if (i + patternLen
Подробнее здесь: [url]https://stackoverflow.com/questions/79449514/how-to-speed-up-string-search-using-opencl[/url]