Commit | Line | Data |
---|---|---|
c38914e1 MJ |
1 | // SPDX-FileCopyrightText: 2015-2016 Advanced Micro Devices, Inc. All rights reserved. |
2 | // SPDX-FileCopyrightText: 2024 EfficiOS, Inc. | |
3 | // | |
4 | // SPDX-License-Identifier: MIT | |
74c0b9b3 OD |
5 | |
6 | #include <rocprofiler-sdk-roctx/roctx.h> | |
7 | #include <hip/hip_runtime.h> | |
8 | #include <string.h> | |
9 | #include <stdio.h> | |
10 | #include <stdlib.h> | |
11 | #include <iostream> | |
12 | #include <string> | |
13 | #include <fstream> | |
14 | ||
15 | #define SAMPLE_VERSION "HIP-Examples-Application-v1.0" | |
16 | #define SUCCESS 0 | |
17 | #define FAILURE 1 | |
18 | ||
19 | using namespace std; | |
20 | ||
21 | __global__ void helloworld(char* in, char* out) | |
22 | { | |
23 | int num = hipThreadIdx_x + hipBlockDim_x * hipBlockIdx_x; | |
24 | out[num] = in[num] + 1; | |
25 | } | |
26 | ||
27 | int main(int argc, char* argv[]) | |
28 | { | |
29 | ||
30 | hipDeviceProp_t devProp; | |
31 | ||
32 | roctx_range_id_t range = roctxRangeStart("hello"); | |
33 | ||
34 | hipGetDeviceProperties(&devProp, 0); | |
35 | cout << " System minor " << devProp.minor << endl; | |
36 | cout << " System major " << devProp.major << endl; | |
37 | cout << " agent prop name " << devProp.name << endl; | |
38 | ||
39 | /* Initial input,output for the host and create memory objects for the kernel*/ | |
40 | const char* input = "GdkknVnqkc"; | |
41 | size_t strlength = strlen(input); | |
42 | cout << "input string:" << endl; | |
43 | cout << input << endl; | |
44 | char *output = (char*) malloc(strlength + 1); | |
45 | ||
46 | char* inputBuffer; | |
47 | char* outputBuffer; | |
48 | hipMalloc((void**)&inputBuffer, (strlength + 1) * sizeof(char)); | |
49 | hipMalloc((void**)&outputBuffer, (strlength + 1) * sizeof(char)); | |
50 | ||
51 | hipMemcpy(inputBuffer, input, (strlength + 1) * sizeof(char), hipMemcpyHostToDevice); | |
52 | ||
53 | hipLaunchKernelGGL(helloworld, | |
54 | dim3(1), | |
55 | dim3(strlength), | |
56 | 0, 0, | |
57 | inputBuffer ,outputBuffer ); | |
58 | ||
59 | hipMemcpy(output, outputBuffer,(strlength + 1) * sizeof(char), hipMemcpyDeviceToHost); | |
60 | ||
61 | hipFree(inputBuffer); | |
62 | hipFree(outputBuffer); | |
63 | ||
64 | output[strlength] = '\0'; //Add the terminal character to the end of output. | |
65 | cout << "\noutput string:" << endl; | |
66 | cout << output << endl; | |
67 | ||
68 | free(output); | |
69 | ||
70 | std::cout<<"Passed!\n"; | |
71 | roctxRangeStop(range); | |
72 | return SUCCESS; | |
73 | } |