Skip to content

Commit 8ebd6c1

Browse files
authored
Merge pull request #1515 from ROCm/hotfix-swdev-494236
limits OPENMP threading in clients (#2753)
2 parents 1c781b1 + 64c3dea commit 8ebd6c1

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

clients/benchmarks/client.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,8 @@ void fix_batch(int argc, char* argv[])
13601360
int main(int argc, char* argv[])
13611361
try
13621362
{
1363+
rocblas_client_init();
1364+
13631365
fix_batch(argc, argv);
13641366
Arguments arg;
13651367
std::string function;
@@ -1844,6 +1846,8 @@ try
18441846
int status = 0;
18451847
// TODO: query for any failed tests
18461848

1849+
rocblas_client_shutdown();
1850+
18471851
return status;
18481852
}
18491853
catch(const std::invalid_argument& exp)

clients/common/client_utility.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#include <new>
3636
#include <stdexcept>
3737
#include <stdlib.h>
38+
#include <thread>
39+
#ifdef _OPENMP
40+
#include <omp.h>
41+
#endif
3842

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

61+
void rocblas_client_init()
62+
{
63+
// limit OMP usage as deadlock issues seen in reference library
64+
#ifdef _OPENMP
65+
const int processor_count = std::thread::hardware_concurrency();
66+
if(processor_count > 0)
67+
{
68+
const int omp_current_threads = omp_get_max_threads();
69+
if(omp_current_threads >= processor_count)
70+
{
71+
int limiter = processor_count > 4 ? processor_count - 2 : processor_count;
72+
int omp_limit_threads = std::max(1, limiter);
73+
74+
if(omp_limit_threads != omp_current_threads)
75+
{
76+
omp_set_num_threads(omp_limit_threads);
77+
78+
rocblas_cerr << "rocBLAS info: client (OPENMP) reduced omp_set_num_threads to "
79+
<< omp_limit_threads << std::endl;
80+
}
81+
}
82+
}
83+
#endif
84+
}
85+
86+
void rocblas_client_shutdown() {}
87+
5788
/* ============================================================================================ */
5889
// Return path of this executable
5990
std::string rocblas_exepath()

clients/gtest/rocblas_gtest_main.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ static void rocblas_set_test_device()
284284
*****************/
285285
int main(int argc, char** argv)
286286
{
287+
rocblas_client_init();
288+
287289
std::string args = rocblas_capture_args(argc, argv);
288290

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

334336
//rocblas_shutdown();
335337

338+
rocblas_client_shutdown();
339+
336340
return status;
337341
}

clients/include/client_utility.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888

8989
#define NOOP (void)0
9090

91+
// general global initializations
92+
void rocblas_client_init();
93+
void rocblas_client_shutdown();
94+
9195
/*!
9296
* Initialize rocBLAS for the requested number of HIP devices
9397
* and report the time taken to complete the initialization.

0 commit comments

Comments
 (0)