]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.rocm/simple.cpp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.rocm / simple.cpp
CommitLineData
18b4d073
SM
1/* This testcase is part of GDB, the GNU debugger.
2
1d506c26 3 Copyright 2022-2024 Free Software Foundation, Inc.
18b4d073
SM
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
18#include "hip/hip_runtime.h"
19#include <cassert>
20
21__global__ void
22do_an_addition (int a, int b, int *out)
23{
24 *out = a + b;
25}
26
27int
28main ()
29{
30 int *result_ptr, result;
31
32 /* Allocate memory for the device to write the result to. */
33 hipError_t error = hipMalloc (&result_ptr, sizeof (int));
34 assert (error == hipSuccess);
35
36 /* Run `do_an_addition` on one workgroup containing one work item. */
37 do_an_addition<<<dim3(1), dim3(1), 0, 0>>> (1, 2, result_ptr);
38
39 /* Copy result from device to host. Note that this acts as a synchronization
40 point, waiting for the kernel dispatch to complete. */
41 error = hipMemcpyDtoH (&result, result_ptr, sizeof (int));
42 assert (error == hipSuccess);
43
44 printf ("result is %d\n", result);
45 assert (result == 3);
46
47 return 0;
48}