Skip to content

Commit

Permalink
Merge pull request #121 from sampath1117/sr/num_threads_update
Browse files Browse the repository at this point in the history
Default value for numThreads used for OpenMp
  • Loading branch information
r-abishek authored Apr 5, 2023
2 parents bb6bb37 + 6b69ec1 commit 2fc7dad
Show file tree
Hide file tree
Showing 24 changed files with 73 additions and 8 deletions.
5 changes: 4 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ AMD ROCm Performance Primitives (**RPP**) library is a comprehensive high-perfor
sudo make install
```

## Build & Install RPP
## Build & Install RPP

The ROCm Performance Primitives (RPP) library has support for three backends: HIP, OpenCL, and CPU:

Expand Down Expand Up @@ -221,6 +221,9 @@ $ sudo make install

// Create handle
rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
2 changes: 1 addition & 1 deletion include/rpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ extern "C" SHARED_PUBLIC rppStatus_t rppCreate(rppHandle_t* handle);
// *param[in] nBatchSize Batch size
// *param[in] numThreads number of threads to be used for OpenMP pragma
// *returns a rppStatus_t enumeration.
extern "C" SHARED_PUBLIC rppStatus_t rppCreateWithBatchSize(rppHandle_t* handle, size_t nBatchSize, Rpp32u numThreads);
extern "C" SHARED_PUBLIC rppStatus_t rppCreateWithBatchSize(rppHandle_t* handle, size_t nBatchSize, Rpp32u numThreads = 0);

/******************** rppDestroy ********************/

Expand Down
2 changes: 1 addition & 1 deletion src/include/common/rpp/handle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ using rocblas_handle_ptr = RPP_MANAGE_PTR(rocblas_handle, rocblas_destroy_handle
struct Handle : rppHandle
{
Handle();
Handle(size_t nBatchSize, Rpp32u numThreads);
Handle(size_t nBatchSize, Rpp32u numThreads = 0);
Handle(Handle&&) noexcept;
~Handle();

Expand Down
8 changes: 5 additions & 3 deletions src/modules/handlehost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <unistd.h>
#endif

#include<thread>
#include "config.h"
#include "rpp/logger.hpp"
#include "rpp/handle.hpp"
Expand All @@ -46,9 +47,6 @@ struct HandleImpl
void PreInitializeBufferCPU()
{
this->initHandle = new InitHandle();
if(this->numThreads == 0)
this->numThreads = this->nBatchSize;

this->initHandle->nbatchSize = this->nBatchSize;
this->initHandle->mem.mcpu.maxSrcSize = (RppiSize *)malloc(sizeof(RppiSize) * this->nBatchSize);
this->initHandle->mem.mcpu.maxDstSize = (RppiSize *)malloc(sizeof(RppiSize) * this->nBatchSize);
Expand All @@ -60,6 +58,7 @@ struct HandleImpl
Handle::Handle(size_t batchSize, Rpp32u numThreads) : impl(new HandleImpl())
{
impl->nBatchSize = batchSize;
numThreads = std::min(numThreads, std::thread::hardware_concurrency());
if(numThreads == 0)
numThreads = batchSize;
impl->numThreads = numThreads;
Expand All @@ -69,6 +68,9 @@ Handle::Handle(size_t batchSize, Rpp32u numThreads) : impl(new HandleImpl())
Handle::Handle() : impl(new HandleImpl())
{
impl->PreInitializeBufferCPU();
impl->numThreads = std::min(impl->numThreads, std::thread::hardware_concurrency());
if(impl->numThreads == 0)
impl->numThreads = impl->nBatchSize;
RPP_LOG_I(*this);
}

Expand Down
7 changes: 5 additions & 2 deletions src/modules/hip/handlehip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <unistd.h>
#endif

#include<thread>
#include "config.h"
#include "rpp/device_name.hpp"
#include "rpp/errors.hpp"
Expand Down Expand Up @@ -172,8 +173,6 @@ struct HandleImpl
void PreInitializeBufferCPU()
{
this->initHandle = new InitHandle();
if(this->numThreads == 0)
this->numThreads = this->nBatchSize;

this->initHandle->nbatchSize = this->nBatchSize;
this->initHandle->mem.mcpu.srcSize = (RppiSize *)malloc(sizeof(RppiSize) * this->nBatchSize);
Expand Down Expand Up @@ -283,6 +282,7 @@ Handle::Handle(rppAcceleratorQueue_t stream) : impl(new HandleImpl())
Handle::Handle(size_t batchSize, Rpp32u numThreads) : impl(new HandleImpl())
{
impl->nBatchSize = batchSize;
numThreads = std::min(numThreads, std::thread::hardware_concurrency());
if(numThreads == 0)
numThreads = batchSize;
impl->numThreads = numThreads;
Expand All @@ -303,6 +303,9 @@ Handle::Handle() : impl(new HandleImpl())
#endif
this->SetAllocator(nullptr, nullptr, nullptr);
impl->PreInitializeBuffer();
impl->numThreads = std::min(impl->numThreads, std::thread::hardware_concurrency());
if(impl->numThreads == 0)
impl->numThreads = impl->nBatchSize;
RPP_LOG_I(*this);
}

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/HIP_NEW/Single_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ int main(int argc, char **argv)

closedir(dr2);
rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/HOST_NEW/BatchPD_host_pkd3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,9 @@ int main(int argc, char **argv)
}

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/HOST_NEW/BatchPD_host_pln1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,9 @@ int main(int argc, char **argv)
}

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/HOST_NEW/BatchPD_host_pln3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,9 @@ int main(int argc, char **argv)
}

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/HOST_NEW/Single_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ int main(int argc, char **argv)

closedir(dr2);
rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/HOST_NEW/Tensor_host_pkd3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,9 @@ int main(int argc, char **argv)
// Run case-wise RPP API and measure time

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/HOST_NEW/Tensor_host_pln1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ int main(int argc, char **argv)
// Run case-wise RPP API and measure time

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/HOST_NEW/Tensor_host_pln3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,9 @@ int main(int argc, char **argv)
// Run case-wise RPP API and measure time

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-performancetests/OCL_NEW/Single_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ int main(int argc, char **argv)

closedir(dr2);
rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/HIP_NEW/Single_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ int main(int argc, char **argv)

closedir(dr2);
rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/HOST_NEW/BatchPD_host_pkd3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,9 @@ int main(int argc, char **argv)
}

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/HOST_NEW/BatchPD_host_pln1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ int main(int argc, char **argv)
}

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/HOST_NEW/BatchPD_host_pln3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,9 @@ int main(int argc, char **argv)
}

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/HOST_NEW/Single_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ int main(int argc, char **argv)

closedir(dr2);
rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/HOST_NEW/Tensor_host_pkd3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ int main(int argc, char **argv)
// Run case-wise RPP API and measure time

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/HOST_NEW/Tensor_host_pln1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,9 @@ int main(int argc, char **argv)
// Run case-wise RPP API and measure time

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/HOST_NEW/Tensor_host_pln3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ int main(int argc, char **argv)
// Run case-wise RPP API and measure time

rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);
clock_t start, end;
Expand Down
3 changes: 3 additions & 0 deletions utilities/rpp-unittests/OCL_NEW/Single_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ int main(int argc, char **argv)

closedir(dr2);
rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down
3 changes: 3 additions & 0 deletions utilities/test_suite/HOST/Tensor_host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ int main(int argc, char **argv)

// Run case-wise RPP API and measure time
rppHandle_t handle;

// Set the number of threads to be used by OpenMP pragma for RPP batch processing on host.
// If numThreads value passed is 0, number of OpenMP threads used by RPP will be set to batch size
Rpp32u numThreads = 0;
rppCreateWithBatchSize(&handle, noOfImages, numThreads);

Expand Down

0 comments on commit 2fc7dad

Please sign in to comment.