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
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
// Copyright (c) Advanced Micro Devices, Inc.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/*
|
|
An example code to execute sequential access to explore cache hits/misses in L2 Cache.
|
|
*/
|
|
|
|
#include <hip/hip_runtime.h>
|
|
#include <iostream>
|
|
#include <assert.h>
|
|
|
|
#define HIP_ASSERT(x) (assert((x)==hipSuccess))
|
|
|
|
// Kernel: sequential access, each thread reads/writes an element in order
|
|
__global__ void sequentialAccessKernel(int *d_data, int N)
|
|
{
|
|
int tid = blockIdx.x * blockDim.x + threadIdx.x;
|
|
if (tid < N)
|
|
{
|
|
d_data[tid] += 1;
|
|
}
|
|
}
|
|
|
|
int main()
|
|
{
|
|
const int N = 1 << 20; // 1M elements
|
|
size_t size = N * sizeof(int);
|
|
// Allocate host memory
|
|
int *h_data = (int *)malloc(size);
|
|
std::fill_n(h_data, N, 0);
|
|
|
|
// Allocate device memory
|
|
int *d_data;
|
|
HIP_ASSERT(hipMalloc(&d_data, size));
|
|
|
|
// Copy h_data to device
|
|
HIP_ASSERT(hipMemcpy(d_data, h_data, size, hipMemcpyHostToDevice));
|
|
|
|
// Configure kernel
|
|
dim3 blockSize(64);
|
|
dim3 gridSize((N + blockSize.x - 1) / blockSize.x);
|
|
|
|
// Repeat the launch so the profile is robust.
|
|
const int kIters = 30;
|
|
for (int i = 0; i < kIters; ++i)
|
|
{
|
|
hipLaunchKernelGGL(sequentialAccessKernel, gridSize, blockSize, 0, 0, d_data, N);
|
|
}
|
|
HIP_ASSERT(hipDeviceSynchronize());
|
|
|
|
// Copy back to host
|
|
HIP_ASSERT(hipMemcpy(h_data, d_data, size, hipMemcpyDeviceToHost));
|
|
|
|
// Cleanup
|
|
HIP_ASSERT(hipFree(d_data));
|
|
free(h_data);
|
|
|
|
std::cout << "SequentialAccess HIP test completed.\n";
|
|
return 0;
|
|
}
|