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
135 lines
2.6 KiB
C++
135 lines
2.6 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#ifndef OCL_THREAD_H
|
|
#define OCL_THREAD_H
|
|
|
|
//!
|
|
//! \file Thread.h
|
|
//!
|
|
|
|
#ifdef _WIN32
|
|
#ifndef _WIN32_WINNT
|
|
#define _WIN32_WINNT 0x0501
|
|
#endif
|
|
|
|
#include "windows.h"
|
|
#else
|
|
#include "pthread.h"
|
|
#endif
|
|
|
|
//! Entry point for the thread
|
|
//! prototype of the entry point in windows
|
|
typedef void* (*oclThreadFunc)(void*);
|
|
|
|
namespace OCLutil {
|
|
//! \class Lock
|
|
//! \brief Provides a wrapper for locking primitives used to
|
|
//! synchronize _CPU_ threads.
|
|
//!
|
|
//! Common usage would be:
|
|
//!
|
|
//! OCL::Lock lock;
|
|
//!
|
|
//! ....
|
|
//!
|
|
//! // Critical section begins
|
|
//!
|
|
//! lock.lock();
|
|
//!
|
|
//! .....
|
|
//!
|
|
//! // Critical section ends
|
|
//!
|
|
//! lock.unlock();
|
|
//!
|
|
|
|
class Lock {
|
|
public:
|
|
//! Constructor for OCLLock
|
|
Lock();
|
|
|
|
//! Destructor for OCLLock
|
|
~Lock();
|
|
|
|
//! Try to acquire the lock, if available continue, else wait on the lock
|
|
void lock();
|
|
|
|
//! Try to acquire the lock, if available, hold it, else continue doing
|
|
//! something else
|
|
bool tryLock();
|
|
|
|
//! Unlock the lock and return
|
|
void unlock();
|
|
|
|
private:
|
|
/////////////////////////////////////////////////////////////
|
|
//!
|
|
//! Private data members and methods
|
|
//!
|
|
|
|
//! System specific synchronization primitive
|
|
#ifdef _WIN32
|
|
CRITICAL_SECTION _cs;
|
|
#else
|
|
pthread_mutex_t _lock;
|
|
#endif
|
|
};
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
//!
|
|
//! \class Thread
|
|
//! \brief Provides a wrapper for creating a _CPU_ thread.
|
|
//!
|
|
//! This class provides a simple wrapper to a CPU thread/
|
|
//! The class name might be a bit confusing, esp considering
|
|
//! the GPU has it's own threads as well.
|
|
//!
|
|
class Thread {
|
|
public:
|
|
//! Thread constructor and destructor. Note that the thread is
|
|
//! NOT created in the constructor. The thread creation takes
|
|
//! place in the create method
|
|
Thread();
|
|
|
|
~Thread();
|
|
|
|
//! Wrapper for pthread_create. Pass the thread's entry
|
|
//! point and data to be passed to the routine
|
|
bool create(oclThreadFunc func, void* arg);
|
|
|
|
//! Wrapper for pthread_join. The calling thread
|
|
//! will wait until _this_ thread exits
|
|
bool join();
|
|
|
|
//! Get the thread data passed by the application
|
|
void* getData() { return _data; }
|
|
|
|
//! Get the thread ID
|
|
static unsigned int getID();
|
|
|
|
private:
|
|
/////////////////////////////////////////////////////////////
|
|
//!
|
|
//! Private data members and methods
|
|
//!
|
|
|
|
#ifdef _WIN32
|
|
//! store the handle
|
|
HANDLE _tid;
|
|
|
|
unsigned int _ID;
|
|
#else
|
|
pthread_t _tid;
|
|
|
|
pthread_attr_t _attr;
|
|
#endif
|
|
|
|
void* _data;
|
|
};
|
|
}; // namespace OCLutil
|
|
#endif
|