Files
TheRock/rocm-libraries/projects/hipsparse/clients/include/testing_gthrz.hpp
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

170 lines
6.3 KiB
C++

/* ************************************************************************
* Copyright (C) 2018-2026 Advanced Micro Devices, Inc. All rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* ************************************************************************ */
#pragma once
#ifndef TESTING_GTHRZ_HPP
#define TESTING_GTHRZ_HPP
#include "display.hpp"
#include "flops.hpp"
#include "gbyte.hpp"
#include "hipsparse.hpp"
#include "hipsparse_arguments.hpp"
#include "hipsparse_graph.hpp"
#include "hipsparse_test_unique_ptr.hpp"
#include "unit.hpp"
#include "utility.hpp"
#include <hipsparse.h>
using namespace hipsparse;
using namespace hipsparse_test;
template <typename T>
void testing_gthrz_bad_arg(const Arguments& argus)
{
int nnz = 100;
int safe_size = 100;
hipsparseIndexBase_t idx_base = HIPSPARSE_INDEX_BASE_ZERO;
hipsparseLocalHandle_t handle;
auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free};
auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * safe_size), device_free};
auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * safe_size), device_free};
T* dx_val = (T*)dx_val_managed.get();
int* dx_ind = (int*)dx_ind_managed.get();
T* dy = (T*)dy_managed.get();
#if(!defined(CUDART_VERSION))
verify_hipsparse_status_invalid_pointer(
hipsparseXgthrz(handle, nnz, dy, dx_val, (int*)nullptr, idx_base),
"Error: x_ind is nullptr");
verify_hipsparse_status_invalid_pointer(
hipsparseXgthrz(handle, nnz, dy, (T*)nullptr, dx_ind, idx_base), "Error: x_val is nullptr");
verify_hipsparse_status_invalid_pointer(
hipsparseXgthrz(handle, nnz, (T*)nullptr, dx_val, dx_ind, idx_base), "Error: y is nullptr");
verify_hipsparse_status_invalid_handle(
hipsparseXgthrz((hipsparseHandle_t) nullptr, nnz, dy, dx_val, dx_ind, idx_base));
#endif
}
template <typename T>
void testing_gthrz(Arguments argus)
{
#if(!defined(CUDART_VERSION) || CUDART_VERSION < 12000)
int N = argus.N;
int nnz = argus.nnz;
hipsparseIndexBase_t idx_base = argus.baseA;
hipsparseLocalHandle_t handle(argus);
// Host structures
std::vector<int> hx_ind(nnz);
std::vector<T> hx_val(nnz);
std::vector<T> hx_val_gold(nnz);
std::vector<T> hy(N);
std::vector<T> hy_gold(N);
// Initial Data on CPU
srand(12345ULL);
hipsparseInitIndex(hx_ind.data(), nnz, idx_base, N + idx_base);
hipsparseInit<T>(hy, 1, N);
hy_gold = hy;
// allocate memory on device
auto dx_ind_managed = hipsparse_unique_ptr{device_malloc(sizeof(int) * nnz), device_free};
auto dx_val_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * nnz), device_free};
auto dy_managed = hipsparse_unique_ptr{device_malloc(sizeof(T) * N), device_free};
int* dx_ind = (int*)dx_ind_managed.get();
T* dx_val = (T*)dx_val_managed.get();
T* dy = (T*)dy_managed.get();
// copy data from CPU to device
CHECK_HIP_ERROR(hipMemcpy(dx_ind, hx_ind.data(), sizeof(int) * nnz, hipMemcpyHostToDevice));
CHECK_HIP_ERROR(hipMemcpy(dy, hy.data(), sizeof(T) * N, hipMemcpyHostToDevice));
if(argus.unit_check)
{
// HIPSPARSE pointer mode host
CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST));
CHECK_HIPSPARSE_ERROR(
testing::hipsparseXgthrz<T>(handle, nnz, dy, dx_val, dx_ind, idx_base));
// copy output from device to CPU
CHECK_HIP_ERROR(hipMemcpy(hx_val.data(), dx_val, sizeof(T) * nnz, hipMemcpyDeviceToHost));
CHECK_HIP_ERROR(hipMemcpy(hy.data(), dy, sizeof(T) * N, hipMemcpyDeviceToHost));
// CPU
host_gthrz(nnz, hy_gold.data(), hx_val_gold.data(), hx_ind.data(), idx_base);
// enable unit check, notice unit check is not invasive, but norm check is,
// unit check and norm check can not be interchanged their order
unit_check_general(1, nnz, 1, hx_val_gold.data(), hx_val.data());
unit_check_general(1, N, 1, hy_gold.data(), hy.data());
}
if(argus.timing)
{
int number_cold_calls = 2;
int number_hot_calls = argus.iters;
CHECK_HIPSPARSE_ERROR(hipsparseSetPointerMode(handle, HIPSPARSE_POINTER_MODE_HOST));
// Warm up
for(int iter = 0; iter < number_cold_calls; ++iter)
{
CHECK_HIPSPARSE_ERROR(
testing::hipsparseXgthrz<T>(handle, nnz, dy, dx_val, dx_ind, idx_base));
}
double gpu_time_used = get_time_us();
// Performance run
for(int iter = 0; iter < number_hot_calls; ++iter)
{
CHECK_HIPSPARSE_ERROR(
testing::hipsparseXgthrz<T>(handle, nnz, dy, dx_val, dx_ind, idx_base));
}
gpu_time_used = (get_time_us() - gpu_time_used) / number_hot_calls;
double gbyte_count = gthrz_gbyte_count<T>(nnz);
double gpu_gbyte = get_gpu_gbyte(gpu_time_used, gbyte_count);
display_timing_info(display_key_t::nnz,
nnz,
display_key_t::bandwidth,
gpu_gbyte,
display_key_t::time_ms,
get_gpu_time_msec(gpu_time_used));
}
#endif
}
#endif // TESTING_GTHRZ_HPP