MCPcopy Create free account
hub / github.com/KhronosGroup/OpenCL-CTS / ThreadPool_Init

Function ThreadPool_Init

test_common/harness/ThreadPool.cpp:498–693  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496}
497
498void ThreadPool_Init(void)
499{
500 cl_int i;
501 int err;
502 std::atomic<cl_uint> threadID{ 0 };
503
504 // Check for manual override of multithreading code. We add this for better
505 // debuggability.
506 if (getenv("CL_TEST_SINGLE_THREADED"))
507 {
508 log_error("ERROR: CL_TEST_SINGLE_THREADED is set in the environment. "
509 "Running single threaded.\n*** TEST IS INVALID! ***\n");
510 gThreadCount = 1;
511 return;
512 }
513
514 // Figure out how many threads to run -- check first for non-zero to give
515 // the implementation the chance
516 if (0 == gThreadCount)
517 {
518#if defined(_MSC_VER) || defined(__MINGW64__)
519 PSYSTEM_LOGICAL_PROCESSOR_INFORMATION buffer = NULL;
520 DWORD length = 0;
521
522 GetLogicalProcessorInformation(NULL, &length);
523 buffer = (PSYSTEM_LOGICAL_PROCESSOR_INFORMATION)malloc(length);
524 if (buffer != NULL)
525 {
526 if (GetLogicalProcessorInformation(buffer, &length) == TRUE)
527 {
528 PSYSTEM_LOGICAL_PROCESSOR_INFORMATION ptr = buffer;
529 while (
530 ptr
531 < &buffer[length
532 / sizeof(SYSTEM_LOGICAL_PROCESSOR_INFORMATION)])
533 {
534 if (ptr->Relationship == RelationProcessorCore)
535 {
536 // Count the number of bits in ProcessorMask (number of
537 // logical cores)
538 ULONG_PTR mask = ptr->ProcessorMask;
539 while (mask)
540 {
541 ++gThreadCount;
542 mask &= mask - 1; // Remove 1 bit at a time
543 }
544 }
545 ++ptr;
546 }
547 }
548 free(buffer);
549 }
550#elif defined(__MINGW32__)
551 {
552#warning How about this, instead of hard coding it to 2?
553 SYSTEM_INFO sysinfo;
554 GetSystemInfo(&sysinfo);
555 gThreadCount = sysinfo.dwNumberOfProcessors;

Callers 3

_ThreadPool_InitFunction · 0.85
ThreadPool_DoFunction · 0.85
GetThreadCountFunction · 0.85

Calls 1

Tested by

no test coverage detected