-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptimizing-gpu-lab-infra.yml
296 lines (281 loc) · 10.7 KB
/
optimizing-gpu-lab-infra.yml
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
AWSTemplateFormatVersion: '2010-09-09'
Description: >
AWS Innovate AI/ML Data Edition - Lab infra Optimizing-GPU-Utilization-for-AI-ML-Workloads
Parameters:
DeployInfra:
Type: String
Default: "true"
Description: If "true", CloudFormation will deploy the CloudWatch related resources for this lab, together with a simple VPC, Public Subnet and Security Group for the lab EC2 instances to be launched on. If "false", only the CloudWatch related resources will be deployed.
AllowedValues:
- true
- false
Conditions:
WithInfra: !Equals
- !Ref DeployInfra
- true
Resources:
IGW:
Type: AWS::EC2::InternetGateway
Condition: "WithInfra"
IGWAttach:
Type: AWS::EC2::VPCGatewayAttachment
Condition: "WithInfra"
Properties:
VpcId: !Ref VPC
InternetGatewayId: !Ref IGW
VPC:
Type: 'AWS::EC2::VPC'
Condition: "WithInfra"
Properties:
CidrBlock: "10.0.0.0/16"
EnableDnsHostnames: true
EnableDnsSupport: true
PublicSubnet1:
Type: 'AWS::EC2::Subnet'
Condition: "WithInfra"
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select
- '0'
- !GetAZs ''
CidrBlock: !Select [ 0, !Cidr [ !GetAtt VPC.CidrBlock, 1, 8 ]]
MapPublicIpOnLaunch: true
PublicRouteTable1:
Type: 'AWS::EC2::RouteTable'
Condition: "WithInfra"
Properties:
VpcId: !Ref VPC
PublicRoute1:
Type: 'AWS::EC2::Route'
Condition: "WithInfra"
DependsOn:
- IGW
- IGWAttach
Properties:
RouteTableId: !Ref PublicRouteTable1
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref IGW
PublicSubnet1RouteTableAssociation1:
Type: 'AWS::EC2::SubnetRouteTableAssociation'
Condition: "WithInfra"
Properties:
SubnetId: !Ref PublicSubnet1
RouteTableId: !Ref PublicRouteTable1
EC2IAMRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Statement:
- Effect: Allow
Principal:
Service: [ec2.amazonaws.com]
Action: ['sts:AssumeRole']
Path: /
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
- arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
EC2InstanceProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Roles: [!Ref EC2IAMRole]
InstanceSecurityGroup:
Type: AWS::EC2::SecurityGroup
Condition: "WithInfra"
Properties:
GroupDescription: Allow all outbound traffic by default
VpcId: !Ref VPC
SecurityGroupEgress:
- IpProtocol: "-1"
CidrIp: 0.0.0.0/0
CloudWatchAgentConfParameter:
Type: AWS::SSM::Parameter
Properties:
Name: CloudWatch-Agent-Config-GPU-Lab
Type: String
Description: SSM Parameter for configuring the CloudWatch Agent on GPU-enabled instances.
Value: "{
\"agent\": {
\"metrics_collection_interval\": 60,
\"run_as_user\": \"cwagent\"
},
\"metrics\": {
\"namespace\": \"CWAgentGPU\",
\"aggregation_dimensions\": [
[
\"InstanceId\"
]
],
\"append_dimensions\": {
\"AutoScalingGroupName\": \"${aws:AutoScalingGroupName}\",
\"ImageId\": \"${aws:ImageId}\",
\"InstanceId\": \"${aws:InstanceId}\",
\"InstanceType\": \"${aws:InstanceType}\"
},
\"metrics_collected\": {
\"cpu\": {
\"measurement\": [
\"cpu_usage_idle\",
\"cpu_usage_iowait\",
\"cpu_usage_user\",
\"cpu_usage_system\"
],
\"metrics_collection_interval\": 60,
\"resources\": [
\"*\"
],
\"totalcpu\": false
},
\"disk\": {
\"measurement\": [
\"used_percent\",
\"inodes_free\"
],
\"metrics_collection_interval\": 60,
\"resources\": [
\"*\"
]
},
\"diskio\": {
\"measurement\": [
\"io_time\"
],
\"metrics_collection_interval\": 60,
\"resources\": [
\"*\"
]
},
\"mem\": {
\"measurement\": [
\"mem_used_percent\"
],
\"metrics_collection_interval\": 60
},
\"swap\": {
\"measurement\": [
\"swap_used_percent\"
],
\"metrics_collection_interval\": 60
},
\"nvidia_gpu\": {
\"measurement\": [
\"utilization_gpu\",
\"temperature_gpu\",
\"utilization_memory\",
\"fan_speed\",
\"memory_total\",
\"memory_used\",
\"memory_free\",
\"pcie_link_gen_current\",
\"pcie_link_width_current\",
\"encoder_stats_session_count\",
\"encoder_stats_average_fps\",
\"encoder_stats_average_latency\",
\"clocks_current_graphics\",
\"clocks_current_sm\",
\"clocks_current_memory\",
\"clocks_current_video\"
],
\"metrics_collection_interval\": 60
}
}
}
}"
GPUCloudWatchDashboard:
Type: AWS::CloudWatch::Dashboard
Properties:
DashboardName: My-GPU-Usage
DashboardBody: !Sub "{
\"widgets\": [
{
\"height\": 10,
\"width\": 24,
\"y\": 16,
\"x\": 0,
\"type\": \"metric\",
\"properties\": {
\"metrics\": [
[{\"expression\": \"SELECT AVG(nvidia_smi_utilization_gpu) FROM SCHEMA(CWAgentGPU, InstanceId) GROUP BY InstanceId\",\"id\": \"q1\"}]
],
\"view\": \"timeSeries\",
\"stacked\": false,
\"region\": \"${AWS::Region}\",
\"stat\": \"Average\",
\"period\": 300,
\"title\": \"GPU Core Utilization\",
\"yAxis\": {
\"left\": {\"label\": \"Percent\",\"max\": 100,\"min\": 0,\"showUnits\": false}
}
}
},
{
\"height\": 7,
\"width\": 8,
\"y\": 0,
\"x\": 0,
\"type\": \"metric\",
\"properties\": {
\"metrics\": [
[{\"expression\": \"SELECT AVG(nvidia_smi_utilization_gpu) FROM SCHEMA(CWAgentGPU, InstanceId)\", \"label\": \"Utilization\",\"id\": \"q1\"}]
],
\"view\": \"gauge\",
\"stacked\": false,
\"region\": \"${AWS::Region}\",
\"stat\": \"Average\",
\"period\": 300,
\"title\": \"Average GPU Core Utilization\",
\"yAxis\": {\"left\": {\"max\": 100, \"min\": 0}
},
\"liveData\": false
}
},
{
\"height\": 9,
\"width\": 24,
\"y\": 7,
\"x\": 0,
\"type\": \"metric\",
\"properties\": {
\"metrics\": [
[{ \"expression\": \"SEARCH(' MetricName=nvidia_smi_memory_used {CWAgentGPU, InstanceId} ', 'Average')\", \"id\": \"m1\", \"visible\": false }],
[{ \"expression\": \"SEARCH(' MetricName=nvidia_smi_memory_total {CWAgentGPU, InstanceId} ', 'Average')\", \"id\": \"m2\", \"visible\": false }],
[{ \"expression\": \"SEARCH(' MetricName=mem_used_percent {CWAgentGPU, InstanceId} ', 'Average')\", \"id\": \"m3\", \"visible\": false }],
[{ \"expression\": \"100*AVG(m1)/AVG(m2)\", \"label\": \"GPU\", \"id\": \"e2\", \"color\": \"#17becf\" }],
[{ \"expression\": \"AVG(m3)\", \"label\": \"RAM\", \"id\": \"e3\" }]
],
\"view\": \"timeSeries\",
\"stacked\": false,
\"region\": \"${AWS::Region}\",
\"stat\": \"Average\",
\"period\": 300,
\"yAxis\": {
\"left\": {\"min\": 0,\"max\": 100,\"label\": \"Percent\",\"showUnits\": false}
},
\"title\": \"Average Memory Utilization\"
}
},
{
\"height\": 7,
\"width\": 8,
\"y\": 0,
\"x\": 8,
\"type\": \"metric\",
\"properties\": {
\"metrics\": [
[ { \"expression\": \"SEARCH(' MetricName=nvidia_smi_memory_used {CWAgentGPU, InstanceId} ', 'Average')\", \"id\": \"m1\", \"visible\": false } ],
[ { \"expression\": \"SEARCH(' MetricName=nvidia_smi_memory_total {CWAgentGPU, InstanceId} ', 'Average')\", \"id\": \"m2\", \"visible\": false } ],
[ { \"expression\": \"100*AVG(m1)/AVG(m2)\", \"label\": \"Utilization\", \"id\": \"e2\" } ]
],
\"sparkline\": true,
\"view\": \"gauge\",
\"region\": \"${AWS::Region}\",
\"stat\": \"Average\",
\"period\": 300,
\"yAxis\": {
\"left\": {\"min\": 0,\"max\": 100}
},
\"liveData\": false,
\"title\": \"GPU Memory Utilization\"
}
}
]
}"