-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.cpp
More file actions
53 lines (44 loc) · 1.71 KB
/
Copy pathkernel.cpp
File metadata and controls
53 lines (44 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <hip/hip_runtime.h>
extern "C" int launch_kernel(int device_id);
#define HIP_CALL(call) \
do \
{ \
hipError_t err = call; \
if(err != hipSuccess) \
{ \
std::cerr << hipGetErrorString(err) << std::endl; \
return(-1); \
} \
} while(0)
__global__ void
kernelA(int x, int y)
{
volatile int i, t;
for(i=0; i<1000000; i++){
// for(i=0; i<10000; i++){
t = 173/x;
x = t + y;
}
}
template <typename T>
__global__ void
kernelC(T* C_d, const T* A_d, size_t N)
{
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
for(size_t i = offset; i < N; i += stride)
{
C_d[i] = A_d[i] * A_d[i];
}
}
int launch_kernel(int device_id) {
const int NUM_LAUNCH = 1;
HIP_CALL(hipSetDevice(device_id));
for(int i = 0; i < NUM_LAUNCH; i++)
{
hipLaunchKernelGGL(kernelA, dim3(128), dim3(1), 0, 0, 1, 2);
}
HIP_CALL(hipDeviceSynchronize());
return 0;
}