Files
TheRock/rocm-systems/projects/clr/opencl/tests/ocltst/module/runtime/OCLGetQueueThreadID.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

97 lines
2.7 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include "OCLGetQueueThreadID.h"
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "CL/cl.h"
#include "CL/cl_ext.h"
#if !defined(__linux__)
#include "WinBase.h"
typedef DWORD(WINAPI* GetThreadId)(__in HANDLE Thread);
#endif
bool badThread = false;
OCLGetQueueThreadID::OCLGetQueueThreadID() {
_numSubTests = 1;
failed_ = false;
}
OCLGetQueueThreadID::~OCLGetQueueThreadID() {}
void OCLGetQueueThreadID::open(unsigned int test, char* units, double& conversion,
unsigned int deviceId) {
OCLTestImp::open(test, units, conversion, deviceId);
CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test");
char name[1024] = {0};
size_t size = 0;
if (deviceId >= deviceCount_) {
failed_ = true;
return;
}
cl_mem buffer;
buffer = _wrapper->clCreateBuffer(context_, CL_MEM_READ_WRITE, sizeof(cl_uint), NULL, &error_);
CHECK_RESULT((error_ != CL_SUCCESS), "clCreateBuffer() failed");
buffers_.push_back(buffer);
}
static void CL_CALLBACK notify_callback(cl_event event, cl_int event_command_exec_status,
void* user_data) {
#if defined(__linux__)
pthread_t id = (pthread_t)user_data;
pthread_t handle = pthread_self();
#else
HMODULE module = GetModuleHandle("kernel32.dll");
GetThreadId getThreadId = reinterpret_cast<GetThreadId>(GetProcAddress(module, "GetThreadId"));
if (NULL == getThreadId) {
return;
}
DWORD id = getThreadId((HANDLE)user_data);
DWORD handle = GetCurrentThreadId();
#endif
if (id != handle) {
badThread = true;
}
}
void OCLGetQueueThreadID::run(void) {
if (failed_) {
return;
}
void* handle;
cl_event clEvent;
cl_event userEvent = clCreateUserEvent(context_, &error_);
CHECK_RESULT((error_ != CL_SUCCESS), "clCreateUserEvent() failed");
cl_uint initVal[2] = {5, 10};
error_ = _wrapper->clGetCommandQueueInfo(cmdQueues_[_deviceId], CL_QUEUE_THREAD_HANDLE_AMD,
sizeof(void*), &handle, NULL);
error_ = _wrapper->clEnqueueWriteBuffer(cmdQueues_[_deviceId], buffers()[0], false, 0,
sizeof(cl_uint), &initVal[0], 1, &userEvent, &clEvent);
CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueWriteBuffer() failed");
error_ = _wrapper->clSetEventCallback(clEvent, CL_SUBMITTED, notify_callback, handle);
clSetUserEventStatus(userEvent, CL_COMPLETE);
clFinish(cmdQueues_[_deviceId]);
clReleaseEvent(clEvent);
clReleaseEvent(userEvent);
CHECK_RESULT(badThread, "Thread ID is incorrect!");
}
unsigned int OCLGetQueueThreadID::close(void) { return OCLTestImp::close(); }