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
169 lines
4.2 KiB
C
169 lines
4.2 KiB
C
|
|
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
#include <hip/hip_runtime.h>
|
|
#include "LaunchKernel.h"
|
|
#define KNRM "\x1B[0m"
|
|
#define KRED "\x1B[31m"
|
|
|
|
#define HIPCHECK(error) \
|
|
{ \
|
|
hipError_t localError = error; \
|
|
if ((localError != hipSuccess) && (localError != hipErrorPeerAccessAlreadyEnabled)) { \
|
|
printf("%serror: '%s'(%d) from %s at %s:%d%s\n", KRED, hipGetErrorString(localError), \
|
|
localError, #error, __FILE__, __LINE__, KNRM); \
|
|
printf("API returned error code.\n"); \
|
|
} \
|
|
}
|
|
|
|
bool LaunchKernelArg() {
|
|
dim3 blocks = {1, 1, 1};
|
|
dim3 threads = {1, 1, 1};
|
|
|
|
HIPCHECK(hipLaunchKernel(getKernelFunc(mykernel), blocks, threads, NULL, 0, 0));
|
|
|
|
return true;
|
|
}
|
|
|
|
bool LaunchKernelArg1() {
|
|
int A = 0;
|
|
int* A_d = NULL;
|
|
dim3 blocks = {1, 1, 1};
|
|
dim3 threads = {1, 1, 1};
|
|
|
|
// Allocate Device memory
|
|
HIPCHECK(hipMalloc((void**)&A_d, sizeof(int)));
|
|
|
|
void* Args[] = {&A_d};
|
|
|
|
HIPCHECK(hipLaunchKernel(getKernelFunc(mykernel1), blocks, threads, Args, 0, 0));
|
|
|
|
// Get the result back to host memory
|
|
HIPCHECK(hipMemcpy(&A, A_d, sizeof(int), hipMemcpyDeviceToHost));
|
|
|
|
HIPCHECK(hipFree(A_d));
|
|
|
|
if (A != 333) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool LaunchKernelArg2() {
|
|
int A = 0;
|
|
int B = 123;
|
|
int* A_d = NULL;
|
|
int* B_d = NULL;
|
|
|
|
dim3 blocks = {1, 1, 1};
|
|
dim3 threads = {1, 1, 1};
|
|
|
|
// Allocate Device memory
|
|
HIPCHECK(hipMalloc((void**)&A_d, sizeof(int)));
|
|
|
|
HIPCHECK(hipMalloc((void**)&B_d, sizeof(int)));
|
|
|
|
// Copy data from host memory to device memory
|
|
HIPCHECK(hipMemcpy(B_d, &B, sizeof(int), hipMemcpyHostToDevice));
|
|
|
|
void* Args[] = {&A_d, &B_d};
|
|
HIPCHECK(hipLaunchKernel(getKernelFunc(mykernel2), blocks, threads, Args, 0, 0));
|
|
|
|
// Get the result back to host memory
|
|
HIPCHECK(hipMemcpy(&A, A_d, sizeof(int), hipMemcpyDeviceToHost));
|
|
|
|
HIPCHECK(hipFree(A_d));
|
|
HIPCHECK(hipFree(B_d));
|
|
|
|
if (A != 123) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool LaunchKernelArg3() {
|
|
int A = 321;
|
|
int B = 123;
|
|
int C = 0;
|
|
int* A_d = NULL;
|
|
int* B_d = NULL;
|
|
int* C_d = NULL;
|
|
|
|
dim3 blocks = {1, 1, 1};
|
|
dim3 threads = {1, 1, 1};
|
|
|
|
// Allocate Device memory
|
|
HIPCHECK(hipMalloc((void**)&A_d, sizeof(int)));
|
|
|
|
HIPCHECK(hipMalloc((void**)&B_d, sizeof(int)));
|
|
|
|
HIPCHECK(hipMalloc((void**)&C_d, sizeof(int)));
|
|
|
|
// Copy data from host memory to device memory
|
|
HIPCHECK(hipMemcpy(A_d, &A, sizeof(int), hipMemcpyHostToDevice));
|
|
|
|
HIPCHECK(hipMemcpy(B_d, &B, sizeof(int), hipMemcpyHostToDevice));
|
|
|
|
void* Args[] = {&A_d, &B_d, &C_d};
|
|
HIPCHECK(hipLaunchKernel(getKernelFunc(mykernel3), blocks, threads, Args, 0, 0));
|
|
|
|
// Get the result back to host memory
|
|
HIPCHECK(hipMemcpy(&C, C_d, sizeof(int), hipMemcpyDeviceToHost));
|
|
|
|
HIPCHECK(hipFree(A_d));
|
|
HIPCHECK(hipFree(B_d));
|
|
HIPCHECK(hipFree(C_d));
|
|
|
|
if (C != 444) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
bool LaunchKernelArg4() {
|
|
int A = 0;
|
|
int* A_d = NULL;
|
|
dim3 blocks = {1, 1, 1};
|
|
dim3 threads = {1, 1, 1};
|
|
|
|
// Allocate Device memory
|
|
HIPCHECK(hipMalloc((void**)&A_d, sizeof(int)));
|
|
|
|
char c = 1;
|
|
short s = 10;
|
|
int i = 100;
|
|
struct things t = {2, 20, 200};
|
|
|
|
void* Args[] = {&A_d, &c, &s, &i, &t};
|
|
HIPCHECK(hipLaunchKernel(getKernelFunc(mykernel4), blocks, threads, Args, 0, 0));
|
|
|
|
// Get the result back to host memory
|
|
HIPCHECK(hipMemcpy(&A, A_d, sizeof(int), hipMemcpyDeviceToHost));
|
|
|
|
HIPCHECK(hipFree(A_d));
|
|
|
|
if (A != (c + s + i + t.c + t.s + t.i)) return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
int launchKernel() {
|
|
printf("Calling LaunchKernel.c file\n");
|
|
if (LaunchKernelArg() && LaunchKernelArg1() && LaunchKernelArg2() && LaunchKernelArg3() &&
|
|
LaunchKernelArg4()) {
|
|
printf("PASSED!\n");
|
|
return 1;
|
|
} else
|
|
printf("FAILED\n");
|
|
return 0;
|
|
}
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|