Files
TheRock/rocm-systems/projects/clr/opencl/tests/ocltst/module/perf/OCLPerfSVMMemFill.cpp
T
derek.holloway 7502bf64a4
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
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

192 lines
6.0 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include "OCLPerfSVMMemFill.h"
#include <Timer.h>
#include <assert.h>
#include <stdio.h>
#include <sstream>
#include <string>
#include "CL/cl.h"
#include "CL/cl_ext.h"
// Quiet pesky warnings
#ifdef WIN_OS
#define SNPRINTF sprintf_s
#else
#define SNPRINTF snprintf
#endif
#define NUM_MODES 3
#define NUM_CG_FLAGS 2
#define NUM_FG_FLAGS 3
static size_t typeSizeList[] = {
1, // sizeof(cl_uchar)
2, 4, 8, 16, 32, 64,
128, // sizeof(cl_ulong16)
};
static unsigned int eleNumList[] = {
0x0020000, 0x0080000, 0x0200000, 0x0800000, 0x2000000,
};
#if defined(CL_VERSION_2_0)
static const cl_svm_mem_flags CGFlags[NUM_CG_FLAGS] = {
CL_MEM_READ_WRITE,
CL_MEM_WRITE_ONLY,
};
static const cl_svm_mem_flags FGFlags[NUM_FG_FLAGS] = {
0,
CL_MEM_SVM_FINE_GRAIN_BUFFER,
CL_MEM_SVM_FINE_GRAIN_BUFFER | CL_MEM_SVM_ATOMICS,
};
#endif
OCLPerfSVMMemFill::OCLPerfSVMMemFill() {
num_typeSize_ = sizeof(typeSizeList) / sizeof(size_t);
num_elements_ = sizeof(eleNumList) / sizeof(unsigned int);
_numSubTests = num_elements_ * num_typeSize_ * (NUM_FG_FLAGS * NUM_CG_FLAGS + 1);
failed_ = false;
skip_ = false;
}
OCLPerfSVMMemFill::~OCLPerfSVMMemFill() {}
void OCLPerfSVMMemFill::open(unsigned int test, char* units, double& conversion,
unsigned int deviceId) {
OCLTestImp::open(test, units, conversion, deviceId);
CHECK_RESULT((error_ != CL_SUCCESS), "Error opening test");
#if defined(CL_VERSION_2_0)
FGSystem_ = (test >= (num_elements_ * num_typeSize_ * NUM_FG_FLAGS * NUM_CG_FLAGS));
testFGFlag_ = (test / (num_elements_ * num_typeSize_ * NUM_CG_FLAGS)) % NUM_FG_FLAGS;
testCGFlag_ = (test / (num_elements_ * num_typeSize_)) % NUM_CG_FLAGS;
testTypeSize_ = typeSizeList[(test / num_elements_) % num_typeSize_];
testNumEle_ = eleNumList[test % num_elements_];
cl_device_svm_capabilities caps;
error_ = clGetDeviceInfo(devices_[deviceId], CL_DEVICE_SVM_CAPABILITIES,
sizeof(cl_device_svm_capabilities), &caps, NULL);
CHECK_RESULT(error_ != CL_SUCCESS, "clGetDeviceInfo failed");
if ((caps & CL_DEVICE_SVM_COARSE_GRAIN_BUFFER) == 0) {
skip_ = true; // Should never happen as OCL 2.0 devices are required to
// support coarse grain SVM
testDescString = "Coarse Grain Buffer NOT supported. Test Skipped.";
return;
} else if (testFGFlag_ > 0 && (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) == 0) {
skip_ = true; // No support for fine grain buffer SVM
testDescString = "Fine Grain Buffer NOT supported. Test Skipped.";
return;
} else if (FGSystem_ && (caps & CL_DEVICE_SVM_FINE_GRAIN_SYSTEM) == 0) {
skip_ = true; // No support for fine grain system SVM
testDescString = "Fine Grain System NOT supported. Test Skipped.";
return;
} else if (testFGFlag_ == 2 && ((caps & CL_DEVICE_SVM_ATOMICS) == 0)) {
skip_ = true; // No support for SVM Atomic
testDescString = "SVM Atomic NOT supported. Test Skipped.";
return;
}
cl_device_type deviceType;
error_ = _wrapper->clGetDeviceInfo(devices_[deviceId], CL_DEVICE_TYPE, sizeof(deviceType),
&deviceType, NULL);
CHECK_RESULT((error_ != CL_SUCCESS), "CL_DEVICE_TYPE failed");
if (!(deviceType & CL_DEVICE_TYPE_GPU)) {
printf("GPU device is required for this test!\n");
failed_ = true;
return;
}
return;
#else
skip_ = true;
testDescString = "SVM NOT supported for < 2.0 builds. Test Skipped.";
return;
#endif
}
static void CL_CALLBACK notify_callback(const char* errinfo, const void* private_info, size_t cb,
void* user_data) {}
void OCLPerfSVMMemFill::run(void) {
if (skip_) {
return;
}
if (failed_) {
return;
}
#if defined(CL_VERSION_2_0)
cl_uint* buffer = NULL;
CPerfCounter timer;
size_t iter = 100, bufSize = testNumEle_ * 4;
cl_mem_flags flags = CGFlags[testCGFlag_] | FGFlags[testFGFlag_];
void* data = malloc(bufSize);
timer.Reset();
if (!FGSystem_) {
buffer = (cl_uint*)clSVMAlloc(context_, flags, bufSize, (cl_uint)testTypeSize_);
CHECK_RESULT(buffer == 0, "Allocation failed");
} else { // FGSystem_ = true
buffer = (cl_uint*)malloc(bufSize);
CHECK_RESULT(buffer == 0, "Allocation failed");
}
timer.Start();
for (size_t i = 0; i < iter; ++i) {
error_ = clEnqueueSVMMemFill(cmdQueues_[_deviceId], buffer, data, testTypeSize_, bufSize, 0,
NULL, NULL);
CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueSVMMemFill() failed");
}
_wrapper->clFinish(cmdQueues_[_deviceId]);
timer.Stop();
if (!FGSystem_) {
clSVMFree(context_, (void*)buffer);
} else {
free(buffer);
}
char pFlags[5];
pFlags[0] = (testCGFlag_ == 0 || testCGFlag_ == 2) ? 'R' : '_'; // CL_MEM_READ_ONLY
pFlags[1] = (testCGFlag_ == 0 || testCGFlag_ == 1) ? 'W' : '_'; // CL_MEM_WRITE_ONLY
pFlags[2] = (testFGFlag_ == 1 || testFGFlag_ == 2) ? 'F' : '_'; // CL_MEM_SVM_FINE_GRAIN_BUFFER
pFlags[3] = (testFGFlag_ == 2) ? 'A' : '_'; // CL_MEM_SVM_ATOMICS
char buf[256];
if (!FGSystem_ && (testFGFlag_ == 0)) {
SNPRINTF(buf, sizeof(buf),
"Coarse Grain Buffer SVMMemFill (GB/s) for %6d KB, typeSize:%3d, "
"flags=%4s",
(int)bufSize / 1024, (int)testTypeSize_, pFlags);
} else if (!FGSystem_ && (testFGFlag_ > 0)) {
SNPRINTF(buf, sizeof(buf),
"Fine Grain Buffer SVMMemFill (GB/s) for %6d KB, typeSize:%3d, "
"flags=%4s",
(int)bufSize / 1024, (int)testTypeSize_, pFlags);
} else if (FGSystem_) {
SNPRINTF(buf, sizeof(buf),
"Fine Grain System SVMMemFill (GB/s) for %6d KB, typeSize:%3d, "
"flags=%4s",
(int)bufSize / 1024, (int)testTypeSize_, pFlags);
}
testDescString = buf;
double sec = timer.GetElapsedTime();
_perfInfo = static_cast<float>((bufSize * iter * (double)(1e-09)) / sec);
#endif
}
unsigned int OCLPerfSVMMemFill::close(void) { return OCLTestImp::close(); }