-
Notifications
You must be signed in to change notification settings - Fork 33
/
ipc.hip
127 lines (110 loc) · 3.45 KB
/
ipc.hip
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
##############################################################################bl
# MIT License
#
# Copyright (c) 2021 - 2023 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
##############################################################################el
An example to explore IPC and divergence, written by Nicholas Curtis [AMD].
This example may not work on all CDNA accelerators, but has been verified on MI2XX.
*/
#include "common.h"
template<int N=1000>
__device__ void vrcp_op() {
int dummy;
if constexpr (N >= 1) {
asm volatile("v_rcp_f64 v[0:1], v[0:1]\n" : : "{v31}"(dummy));
vrcp_op<N - 1>();
}
}
template<int N=1000>
__global__ void vrcp() {
vrcp_op<N>();
}
template<int N=1000>
__device__ void vmov_op() {
int dummy;
if constexpr (N >= 1) {
asm volatile("v_mov_b32 v0, v1\n" : : "{v31}"(dummy));
vmov_op<N - 1>();
}
}
template<int N=1000>
__global__ void vmov() {
vmov_op<N>();
}
template<int N=1000>
__device__ void mfma_op() {
int dummy;
if constexpr (N >= 1) {
asm volatile("v_mfma_f32_32x32x8bf16_1k v[0:15], v[16:17], v[18:19], v[0:15]\n" : : "{v31}"(dummy));
mfma_op<N - 1>();
}
}
template<int N=1000>
__global__ void mfma() {
mfma_op<N>();
}
template<int N=1000>
__device__ void snop_op() {
int dummy;
if constexpr (N >= 1) {
asm volatile("s_nop 0x0\n" : : "{v31}"(dummy));
snop_op<N - 1>();
}
}
template<int N=1000>
__global__ void snop() {
snop_op<N>();
}
template<int N=1000>
__device__ void smov_op() {
int dummy;
if constexpr (N >= 1) {
asm volatile("s_mov_b32 s0, s1\n" : : "{s31}"(dummy));
smov_op<N - 1>();
}
}
template<int N=1000>
__global__ void smov() {
smov_op<N>();
}
template<int N=1000>
__global__ void vmov_with_divergence() {
if (threadIdx.x % 64 == 0)
vmov_op<N>();
}
int main() {
// warmups, spam to all CUs
vrcp<<<1024 * 1024, 1024>>>();
vmov<<<1024 * 1024, 1024>>>();
mfma<<<1024 * 1024, 1024>>>();
snop<<<1024 * 1024, 1024>>>();
smov<<<1024 * 1024, 1024>>>();
vmov_with_divergence<<<1024 * 1024, 1024>>>();
hipCheck(hipDeviceSynchronize());
vrcp<<<1024 * 1024, 1024>>>();
vmov<<<1024 * 1024, 1024>>>();
mfma<<<1024 * 1024, 1024>>>();
snop<<<1024 * 1024, 1024>>>();
smov<<<1024 * 1024, 1024>>>();
vmov_with_divergence<<<1024 * 1024, 1024>>>();
hipCheck(hipDeviceSynchronize());
}