Files
TheRock/rocm-systems/projects/hip-tests/catch/unit/module/coopKernel.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

90 lines
2.2 KiB
C++

/*
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
*
* SPDX-License-Identifier: MIT
*/
#include <hip/hip_runtime.h>
#include <hip/hip_cooperative_groups.h>
using namespace cooperative_groups;
extern "C" {
__global__ void cooperativeKernelEx(int* output, int totalThreads) {
grid_group grid = this_grid();
int tid = threadIdx.x + blockDim.x * blockIdx.x;
if (tid < totalThreads) {
output[tid] = tid * 3;
}
// TODO: remove syncthreads with grid sync when compiler issue is fixed
// grid.sync();
__syncthreads();
if (tid == 0) {
output[0] = 2222;
}
}
/*
* Kernel which doesn't use cooperative groups and without any arguments
*/
__global__ void emptyKernel() {}
/*
* Kernel which doesn't use cooperative groups and takes an argument
* and updates the value with 100
*/
__global__ void argKernel(int* val) { *val = 100; }
/*
* Kernel which uses cooperative groups and without any arguments
*/
__global__ void coopEmptykernel() {
cooperative_groups::grid_group grid = cooperative_groups::this_grid();
// TODO: remove syncthreads with grid sync when compiler issue is fixed
// grid.sync();
__syncthreads();
}
/*
* Kernel which uses cooperative groups and takes arguments
* and performs below operations
* 1) All the threads in the block fills the element in the arr array
* based on the blockIdx.x
* 2) Wait for all the blocks completes it's operations
* 3) Fill each element in the output array with sum of elements in arr
*/
__global__ void coopFillArrayKernel(int* arr, int* output, int N) {
cooperative_groups::grid_group grid = cooperative_groups::this_grid();
if (blockIdx.x == 0)
arr[0] = 10;
else if (blockIdx.x == 1)
arr[1] = 20;
else if (blockIdx.x == 2)
arr[2] = 30;
else if (blockIdx.x == 3)
arr[3] = 40;
else if (blockIdx.x == 4)
arr[4] = 50;
else if (blockIdx.x == 5)
arr[5] = 60;
else if (blockIdx.x == 6)
arr[6] = 70;
else if (blockIdx.x == 7)
arr[7] = 80;
else if (blockIdx.x == 8)
arr[8] = 90;
else if (blockIdx.x == 9)
arr[9] = 100;
// TODO: remove syncthreads with grid sync when compiler issue is fixed
// grid.sync();
__syncthreads();
for (int i = 0; i < N; i++) {
output[blockIdx.x] = output[blockIdx.x] + arr[i];
}
}
}