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
142 lines
3.7 KiB
C++
142 lines
3.7 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
/**
|
|
* @addtogroup hipPerfStreamCreateCopyDestroy hipPerfStreamCreateCopyDestroy
|
|
* @{
|
|
* @ingroup PerformanceTestStream
|
|
* `hipError_t hipStreamCreate(hipStream_t* stream)` -
|
|
* Create an asynchronous stream.
|
|
*/
|
|
|
|
#include <hip_test_kernels.hh>
|
|
#include <hip_test_checkers.hh>
|
|
#include <hip_test_common.hh>
|
|
|
|
#define BufSize 0x1000
|
|
#define Iterations 0x100
|
|
#define TotalStreams 4
|
|
#define TotalBufs 4
|
|
|
|
|
|
class hipPerfStreamCreateCopyDestroy {
|
|
private:
|
|
unsigned int numBuffers_;
|
|
unsigned int numStreams_;
|
|
const size_t totalStreams_[TotalStreams];
|
|
const size_t totalBuffers_[TotalBufs];
|
|
|
|
public:
|
|
hipPerfStreamCreateCopyDestroy()
|
|
: numBuffers_(0),
|
|
numStreams_(0),
|
|
totalStreams_{1, 2, 4, 8},
|
|
totalBuffers_{1, 100, 1000, 5000} {};
|
|
~hipPerfStreamCreateCopyDestroy() {};
|
|
bool open(int deviceID);
|
|
bool run(unsigned int testNumber);
|
|
};
|
|
|
|
bool hipPerfStreamCreateCopyDestroy::open(int deviceId) {
|
|
int nGpu = 0;
|
|
HIP_CHECK(hipGetDeviceCount(&nGpu));
|
|
if (nGpu < 1) {
|
|
HIP_SKIP_TEST(HipTest::SkipReason::kNoGpuDevice);
|
|
}
|
|
HIP_CHECK(hipSetDevice(deviceId));
|
|
hipDeviceProp_t props;
|
|
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
|
|
|
|
CONSOLE_PRINT("info: running on bus 0x%x %s with %d CUs and device id: %d\n", props.pciBusID,
|
|
props.name, props.multiProcessorCount, deviceId);
|
|
return true;
|
|
}
|
|
|
|
bool hipPerfStreamCreateCopyDestroy::run(unsigned int testNumber) {
|
|
numStreams_ = totalStreams_[testNumber % TotalStreams];
|
|
size_t iter =
|
|
Iterations / (numStreams_ * (static_cast<size_t>(1) << (testNumber / TotalBufs + 1)));
|
|
hipStream_t* streams = new hipStream_t[numStreams_];
|
|
|
|
numBuffers_ = totalBuffers_[testNumber / TotalBufs];
|
|
float** dSrc = new float*[numBuffers_];
|
|
size_t nBytes = BufSize * sizeof(float);
|
|
|
|
for (size_t b = 0; b < numBuffers_; ++b) {
|
|
HIP_CHECK(hipMalloc(&dSrc[b], nBytes));
|
|
}
|
|
|
|
float* hSrc;
|
|
hSrc = new float[nBytes];
|
|
HIP_CHECK(hSrc == 0 ? hipErrorOutOfMemory : hipSuccess);
|
|
for (size_t i = 0; i < BufSize; i++) {
|
|
hSrc[i] = 1.618f + i;
|
|
}
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
|
|
|
for (size_t i = 0; i < iter; ++i) {
|
|
for (size_t s = 0; s < numStreams_; ++s) {
|
|
HIP_CHECK(hipStreamCreate(&streams[s]));
|
|
}
|
|
|
|
for (size_t s = 0; s < numStreams_; ++s) {
|
|
for (size_t b = 0; b < numBuffers_; ++b) {
|
|
HIP_CHECK(hipMemcpyWithStream(dSrc[b], hSrc, nBytes, hipMemcpyHostToDevice, streams[s]));
|
|
}
|
|
}
|
|
|
|
for (size_t s = 0; s < numStreams_; ++s) {
|
|
HIP_CHECK(hipStreamDestroy(streams[s]));
|
|
}
|
|
}
|
|
|
|
auto end = std::chrono::steady_clock::now();
|
|
std::chrono::duration<double> diff = end - start;
|
|
|
|
auto time = static_cast<float>(diff.count() * 1000 / (iter * numStreams_));
|
|
|
|
CONSOLE_PRINT(
|
|
"Create+Copy+Destroy time for %u streams and %u buffers and %zu iterations %.6f (ms)\n",
|
|
numStreams_, numBuffers_, iter, time);
|
|
|
|
delete[] hSrc;
|
|
for (size_t b = 0; b < numBuffers_; ++b) {
|
|
HIP_CHECK(hipFree(dSrc[b]));
|
|
}
|
|
|
|
delete[] streams;
|
|
delete[] dSrc;
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Verify the Create+Copy+Destroy time for different stream.
|
|
* Test source
|
|
* ------------------------
|
|
* - performance/scenarios/stream/hipPerfStreamCreateCopyDestroy.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.6
|
|
*/
|
|
|
|
HIP_TEST_CASE(Performance_hipPerfStreamCreateCopyDestroy) {
|
|
hipPerfStreamCreateCopyDestroy streamCCD;
|
|
int deviceId = 0;
|
|
REQUIRE(true == streamCCD.open(deviceId));
|
|
|
|
for (auto testCase = 0; testCase < TotalStreams * TotalBufs; testCase++) {
|
|
REQUIRE(true == streamCCD.run(testCase));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* End doxygen group perfStreamTest.
|
|
* @}
|
|
*/
|