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
58 lines
1.9 KiB
Plaintext
58 lines
1.9 KiB
Plaintext
// Copyright Advanced Micro Devices, Inc.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include <hip/hip_runtime.h>
|
|
|
|
#include <iostream>
|
|
|
|
// Functions marked with __device__ are executed on the device and called from the device only.
|
|
__device__ unsigned int get_thread_idx()
|
|
{
|
|
// Built-in threadIdx returns the 3D coordinate of the active work item in the block of threads.
|
|
return threadIdx.x;
|
|
}
|
|
|
|
// Functions marked with __host__ are executed on the host and called from the host.
|
|
__host__ void print_hello_host()
|
|
{
|
|
std::cout << "Hello world from host!" << std::endl;
|
|
}
|
|
|
|
// Functions marked with __device__ and __host__ are compiled both for host and device.
|
|
// These functions cannot use coordinate built-ins.
|
|
__device__ __host__ void print_hello()
|
|
{
|
|
// Only printf is supported for printing from device code.
|
|
printf("Hello world from device or host!\n");
|
|
}
|
|
|
|
// Functions marked with __global__ are executed on the device and called from the host only.
|
|
__global__ void helloworld_kernel()
|
|
{
|
|
unsigned int thread_idx = get_thread_idx();
|
|
// Built-in blockIdx returns the 3D coorindate of the active work item in the grid of blocks.
|
|
unsigned int block_idx = blockIdx.x;
|
|
|
|
print_hello();
|
|
|
|
// Only printf is supported for printing from device code.
|
|
printf("Hello world from device kernel block %u thread %u!\n", block_idx, thread_idx);
|
|
}
|
|
|
|
int main()
|
|
{
|
|
print_hello_host();
|
|
|
|
print_hello();
|
|
|
|
// Launch the kernel.
|
|
helloworld_kernel<<<dim3(2), // 3D grid specifying number of blocks to launch: (2, 1, 1)
|
|
dim3(2), // 3D grid specifying number of threads to launch: (2, 1, 1)
|
|
0, // number of bytes of additional shared memory to allocate
|
|
hipStreamDefault // stream where the kernel should execute: default stream
|
|
>>>();
|
|
|
|
// Wait on all active streams on the current device.
|
|
return hipDeviceSynchronize();
|
|
}
|