Skip to content

Commit

Permalink
Merge pull request #1515 from ROCm/hotfix-swdev-494236
Browse files Browse the repository at this point in the history
limits OPENMP threading in clients (#2753)
  • Loading branch information
vamovsik authored Nov 18, 2024
2 parents 1c781b1 + 64c3dea commit 8ebd6c1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clients/benchmarks/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,8 @@ void fix_batch(int argc, char* argv[])
int main(int argc, char* argv[])
try
{
rocblas_client_init();

fix_batch(argc, argv);
Arguments arg;
std::string function;
Expand Down Expand Up @@ -1844,6 +1846,8 @@ try
int status = 0;
// TODO: query for any failed tests

rocblas_client_shutdown();

return status;
}
catch(const std::invalid_argument& exp)
Expand Down
31 changes: 31 additions & 0 deletions clients/common/client_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
#include <new>
#include <stdexcept>
#include <stdlib.h>
#include <thread>
#ifdef _OPENMP
#include <omp.h>
#endif

#ifdef WIN32
#define strcasecmp(A, B) _stricmp(A, B)
Expand All @@ -54,6 +58,33 @@ namespace fs = std::experimental::filesystem;
#include <fcntl.h>
#endif

void rocblas_client_init()
{
// limit OMP usage as deadlock issues seen in reference library
#ifdef _OPENMP
const int processor_count = std::thread::hardware_concurrency();
if(processor_count > 0)
{
const int omp_current_threads = omp_get_max_threads();
if(omp_current_threads >= processor_count)
{
int limiter = processor_count > 4 ? processor_count - 2 : processor_count;
int omp_limit_threads = std::max(1, limiter);

if(omp_limit_threads != omp_current_threads)
{
omp_set_num_threads(omp_limit_threads);

rocblas_cerr << "rocBLAS info: client (OPENMP) reduced omp_set_num_threads to "
<< omp_limit_threads << std::endl;
}
}
}
#endif
}

void rocblas_client_shutdown() {}

/* ============================================================================================ */
// Return path of this executable
std::string rocblas_exepath()
Expand Down
4 changes: 4 additions & 0 deletions clients/gtest/rocblas_gtest_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ static void rocblas_set_test_device()
*****************/
int main(int argc, char** argv)
{
rocblas_client_init();

std::string args = rocblas_capture_args(argc, argv);

auto* no_signal_handling = getenv("ROCBLAS_TEST_NO_SIGACTION");
Expand Down Expand Up @@ -333,5 +335,7 @@ int main(int argc, char** argv)

//rocblas_shutdown();

rocblas_client_shutdown();

return status;
}
4 changes: 4 additions & 0 deletions clients/include/client_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@

#define NOOP (void)0

// general global initializations
void rocblas_client_init();
void rocblas_client_shutdown();

/*!
* Initialize rocBLAS for the requested number of HIP devices
* and report the time taken to complete the initialization.
Expand Down

0 comments on commit 8ebd6c1

Please sign in to comment.