Commit | Line | Data |
---|---|---|
74c0b9b3 OD |
1 | /* |
2 | Copyright (c) 2015-2016 Advanced Micro Devices, Inc. All rights reserved. | |
3 | ||
4 | Permission is hereby granted, free of charge, to any person obtaining a copy | |
5 | of this software and associated documentation files (the "Software"), to deal | |
6 | in the Software without restriction, including without limitation the rights | |
7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
8 | copies of the Software, and to permit persons to whom the Software is | |
9 | furnished to do so, subject to the following conditions: | |
10 | ||
11 | The above copyright notice and this permission notice shall be included in | |
12 | all copies or substantial portions of the Software. | |
13 | ||
14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
20 | THE SOFTWARE. | |
21 | */ | |
22 | ||
23 | #include <rocprofiler-sdk-roctx/roctx.h> | |
24 | #include <hip/hip_runtime.h> | |
25 | #include <string.h> | |
26 | #include <stdio.h> | |
27 | #include <stdlib.h> | |
28 | #include <iostream> | |
29 | #include <string> | |
30 | #include <fstream> | |
31 | ||
32 | #define SAMPLE_VERSION "HIP-Examples-Application-v1.0" | |
33 | #define SUCCESS 0 | |
34 | #define FAILURE 1 | |
35 | ||
36 | using namespace std; | |
37 | ||
38 | __global__ void helloworld(char* in, char* out) | |
39 | { | |
40 | int num = hipThreadIdx_x + hipBlockDim_x * hipBlockIdx_x; | |
41 | out[num] = in[num] + 1; | |
42 | } | |
43 | ||
44 | int main(int argc, char* argv[]) | |
45 | { | |
46 | ||
47 | hipDeviceProp_t devProp; | |
48 | ||
49 | roctx_range_id_t range = roctxRangeStart("hello"); | |
50 | ||
51 | hipGetDeviceProperties(&devProp, 0); | |
52 | cout << " System minor " << devProp.minor << endl; | |
53 | cout << " System major " << devProp.major << endl; | |
54 | cout << " agent prop name " << devProp.name << endl; | |
55 | ||
56 | /* Initial input,output for the host and create memory objects for the kernel*/ | |
57 | const char* input = "GdkknVnqkc"; | |
58 | size_t strlength = strlen(input); | |
59 | cout << "input string:" << endl; | |
60 | cout << input << endl; | |
61 | char *output = (char*) malloc(strlength + 1); | |
62 | ||
63 | char* inputBuffer; | |
64 | char* outputBuffer; | |
65 | hipMalloc((void**)&inputBuffer, (strlength + 1) * sizeof(char)); | |
66 | hipMalloc((void**)&outputBuffer, (strlength + 1) * sizeof(char)); | |
67 | ||
68 | hipMemcpy(inputBuffer, input, (strlength + 1) * sizeof(char), hipMemcpyHostToDevice); | |
69 | ||
70 | hipLaunchKernelGGL(helloworld, | |
71 | dim3(1), | |
72 | dim3(strlength), | |
73 | 0, 0, | |
74 | inputBuffer ,outputBuffer ); | |
75 | ||
76 | hipMemcpy(output, outputBuffer,(strlength + 1) * sizeof(char), hipMemcpyDeviceToHost); | |
77 | ||
78 | hipFree(inputBuffer); | |
79 | hipFree(outputBuffer); | |
80 | ||
81 | output[strlength] = '\0'; //Add the terminal character to the end of output. | |
82 | cout << "\noutput string:" << endl; | |
83 | cout << output << endl; | |
84 | ||
85 | free(output); | |
86 | ||
87 | std::cout<<"Passed!\n"; | |
88 | roctxRangeStop(range); | |
89 | return SUCCESS; | |
90 | } |