rocm_bandwidth_test_print.cpp 15.6 KB
Newer Older
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
////////////////////////////////////////////////////////////////////////////////
//
// The University of Illinois/NCSA
// Open Source License (NCSA)
// 
// Copyright (c) 2014-2015, Advanced Micro Devices, Inc. All rights reserved.
// 
// Developed by:
// 
//                 AMD Research and AMD HSA Software Development
// 
//                 Advanced Micro Devices, Inc.
// 
//                 www.amd.com
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal with 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:
// 
//  - Redistributions of source code must retain the above copyright notice,
//    this list of conditions and the following disclaimers.
//  - Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimers in
//    the documentation and/or other materials provided with the distribution.
//  - Neither the names of Advanced Micro Devices, Inc,
//    nor the names of its contributors may be used to endorse or promote
//    products derived from this Software without specific prior written
//    permission.
// 
// 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 CONTRIBUTORS 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 WITH THE SOFTWARE.
//
////////////////////////////////////////////////////////////////////////////////

#include "common.hpp"
#include "rocm_bandwidth_test.hpp"

46
47
48
49
50
#include <assert.h>
#include <iostream>
#include <string>
#include <sstream>

51
52
53
54
55
56
57
// @Brief: Print Help Menu Screen
void RocmBandwidthTest::PrintHelpScreen() {

  std::cout << std::endl;
  std::cout << "Supported arguments:" << std::endl;
  std::cout << std::endl;
  std::cout << "\t -h    Prints the help screen" << std::endl;
58
  std::cout << "\t -q    Query version of the test" << std::endl;
59
  std::cout << "\t -v    Run the test in validation mode" << std::endl;
60
  std::cout << "\t -l    Run test to collect Latency data" << std::endl;
61
  std::cout << "\t -c    Time the operation using CPU Timers" << std::endl;
62
  std::cout << "\t -i    Initialize copy buffer with specified 'long double' pattern" << std::endl;
63
64
65
66
67
68
69
70
  std::cout << "\t -t    Prints system topology and allocatable memory info" << std::endl;
  std::cout << "\t -m    List of buffer sizes to use, specified in Megabytes" << std::endl;
  std::cout << "\t -b    List devices to use in bidirectional copy operations" << std::endl;
  std::cout << "\t -s    List of source devices to use in copy unidirectional operations" << std::endl;
  std::cout << "\t -d    List of destination devices to use in unidirectional copy operations" << std::endl;
  std::cout << "\t -a    Perform Unidirectional Copy involving all device combinations" << std::endl;
  std::cout << "\t -A    Perform Bidirectional Copy involving all device combinations" << std::endl;
  std::cout << std::endl;
71
72
  
  std::cout << "\t NOTE: Mixing following options is illegal/unsupported" << std::endl;
73
74
75
76
  std::cout << "\t\t Case 1: rocm_bandwidth_test -a with {lm}{1,}" << std::endl;
  std::cout << "\t\t Case 2: rocm_bandwidth_test -b with {clv}{1,}" << std::endl;
  std::cout << "\t\t Case 3: rocm_bandwidth_test -A with {clmv}{1,}" << std::endl;
  std::cout << "\t\t Case 4: rocm_bandwidth_test -s x -d y with {lmv}{2,}" << std::endl;
77
78
  std::cout << std::endl;

Ramesh Errabolu's avatar
Ramesh Errabolu committed
79
80
81
82
83
84
85
86
87
  std::cout << std::endl;

}

// @brief: Print the cmdline used to run the test
void RocmBandwidthTest::PrintLaunchCmd() const {

  uint32_t format = 10;
  std::cout.setf(ios::left);
88
89

  std::cout << std::endl;
Ramesh Errabolu's avatar
Ramesh Errabolu committed
90
91
92
93
94
95
  std::cout.width(format);
  std::cout << "";
  std::cout << "Launch Command is: ";

  // Print the exe value
  std::cout << usr_argv_[0];
96

Ramesh Errabolu's avatar
Ramesh Errabolu committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
  // Return for default run
  if (bw_default_run_ != NULL) {
    std::cout << " (rocm_bandwidth -a + rocm_bandwidth -A)";
    std::cout << std::endl;
    std::cout << std::endl;
    return;
  }

  // Print launch parameters for non-default runs
  for (uint32_t idx = 1; idx < usr_argc_; idx++) {
    std::cout << " " << usr_argv_[idx];
  }
  
  std::cout << std::endl;
  std::cout << std::endl;
112
113
}

114
115
116
117
118
119
120
121
122
123
// @brief: Print the version of the test
void RocmBandwidthTest::PrintVersion() const {

  uint32_t format = 10;
  std::cout.setf(ios::left);

  std::cout << std::endl;
  std::cout.width(format);
  std::cout << "";
  std::cout << "RocmBandwidthTest Version: " << GetVersion() << std::endl;
Ramesh Errabolu's avatar
Ramesh Errabolu committed
124
125
126
  
  // Print launch command
  PrintLaunchCmd();
127
128
}

129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// @brief: Print the topology of Memory Pools and Devices present in system
void RocmBandwidthTest::PrintTopology() {

  uint32_t format = 10;
  size_t count = agent_pool_list_.size();
  std::cout << std::endl;
  for (uint32_t idx = 0; idx < count; idx++) {
    agent_pool_info_t node = agent_pool_list_.at(idx);
    
    std::cout.width(format);
    std::cout << "";
    std::cout.width(format);

    // Print device info
    std::cout << "Device Index:                             "
              << node.agent.index_ << std::endl;
    
    std::cout.width(format);
    std::cout << "";
    std::cout.width(format);
    
150
    if (HSA_DEVICE_TYPE_CPU == node.agent.device_type_) {
151
      std::cout << "  Device Type:                            CPU" << std::endl;
152
153
154
155
      std::cout.width(format);
      std::cout << "";
      std::cout.width(format);
      std::cout << "  Device Name:                            " << node.agent.name_ << std::endl;
156
    } else if (HSA_DEVICE_TYPE_GPU == node.agent.device_type_) {
157
      std::cout << "  Device Type:                            GPU" << std::endl;
158
159
160
      std::cout.width(format);
      std::cout << "";
      std::cout.width(format);
161
162
163
164
      std::cout << "  Device Name:                            " << node.agent.name_ << std::endl;
      std::cout.width(format);
      std::cout << "";
      std::cout.width(format);
165
166
      std::cout << "  Device  BDF:                            " << node.agent.bdf_id_ << std::endl;
    }
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

    // Print pool info
    size_t pool_count = node.pool_list.size();
    for (uint32_t jdx = 0; jdx < pool_count; jdx++) {
      
      std::cout.width(format);
      std::cout << "";
      std::cout.width(format);
      
      std::cout << "    Allocatable Memory Size (KB):         "
           << node.pool_list.at(jdx).allocable_size_ / 1024 << std::endl;
    }
    std::cout << std::endl;
  }
  std::cout << std::endl;
}

184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
std::string GetValueAsString(uint32_t key, uint32_t value) {

  std::stringstream ss;

  switch(key) {
    case RocmBandwidthTest::LINK_PROP_ACCESS:
      ss << value;
      return ss.str();
      break;
    case RocmBandwidthTest::LINK_PROP_HOPS:
    case RocmBandwidthTest::LINK_PROP_WEIGHT:
      ss << value;
      return (value == 0xFFFFFFFF) ? std::string("N/A") :  ss.str();
      break;
    case RocmBandwidthTest::LINK_PROP_TYPE:
      if ((value == RocmBandwidthTest::LINK_TYPE_SELF) ||
          (value == RocmBandwidthTest::LINK_TYPE_NO_PATH) ||
          (value == RocmBandwidthTest::LINK_TYPE_IGNORED)) {
        return std::string("N/A");
      } else if (value == RocmBandwidthTest::LINK_TYPE_XGMI) {
        return std::string("X");
      } else if (value == RocmBandwidthTest::LINK_TYPE_PCIE) {
        return std::string("P");
207
      }
208
      break;
209
  }
210
211
  std::cout << "An illegal key to get value for" << std::endl;
  assert(false);
212
  return "";
213
214
}

215
void RocmBandwidthTest::PrintLinkPropsMatrix(uint32_t key) const {
216
217
218
219
220
221
222

  uint32_t format = 10;
  std::cout.setf(ios::left);

  std::cout.width(format);
  std::cout << "";
  std::cout.width(format);
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
  
  switch(key) {
    case LINK_PROP_ACCESS:
      std::cout << "Inter-Device Access";
      break;
    case LINK_PROP_TYPE:
      std::cout << "Inter-Device Link Type: P = PCIe, X = xGMI, N/A = Not Applicable";
      break;
    case LINK_PROP_HOPS:
      std::cout << "Inter-Device Link Hops";
      break;
    case LINK_PROP_WEIGHT:
      std::cout << "Inter-Device Numa Distance";
      break;
    default:
      std::cout << "An illegal key to print matrix" << std::endl;
      assert(false);
  }
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
  std::cout << std::endl;
  std::cout << std::endl;

  std::cout.width(format);
  std::cout << "";
  std::cout.width(format);
  std::cout << "D/D";
  for (uint32_t idx0 = 0; idx0 < agent_index_; idx0++) {
    std::cout.width(format);
    std::cout << idx0;
  }
  std::cout << std::endl;
  std::cout << std::endl;

  for (uint32_t src_idx = 0; src_idx < agent_index_; src_idx++) {
    std::cout.width(format);
    std::cout << "";
    std::cout.width(format);
    std::cout << src_idx;
    for (uint32_t dst_idx = 0; dst_idx < agent_index_; dst_idx++) {
261
262
263
264
265
266
267
268
269
270
271
272
273
274
      uint32_t value = 0x00;
      switch(key) {
        case LINK_PROP_ACCESS:
          value = direct_access_matrix_[(src_idx * agent_index_) + dst_idx];
          break;
        case LINK_PROP_TYPE:
          value = link_type_matrix_[(src_idx * agent_index_) + dst_idx];
          break;
        case LINK_PROP_HOPS:
          value = link_hops_matrix_[(src_idx * agent_index_) + dst_idx];
          break;
        case LINK_PROP_WEIGHT:
          value = link_weight_matrix_[(src_idx * agent_index_) + dst_idx];
          break;
275
      }
276
277
      std::cout.width(format);
      std::cout << GetValueAsString(key, value);
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
    }
    std::cout << std::endl;
    std::cout << std::endl;
  }
  std::cout << std::endl;
}

// @brief: Print info on Devices in system
void RocmBandwidthTest::PrintAgentsList() {

  size_t count = agent_pool_list_.size();
  for (uint32_t idx = 0; idx < count; idx++) {
    std::cout << std::endl;
    agent_pool_info_t node = agent_pool_list_.at(idx);
    std::cout << "Device Index:                             "
              << node.agent.index_ << std::endl;
294
    if (HSA_DEVICE_TYPE_CPU == node.agent.device_type_) {
295
      std::cout << "  Device Type:                            CPU" << std::endl;
296
    } else if (HSA_DEVICE_TYPE_GPU == node.agent.device_type_) {
297
      std::cout << "  Device Type:                            GPU" << std::endl;
298
299
      std::cout << "  Device  BDF:                            " << node.agent.bdf_id_ << std::endl;
    }
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
  }
  std::cout << std::endl;
}

// @brief: Print info on memory pools in system
void RocmBandwidthTest::PrintPoolsList() {

  size_t pool_count = pool_list_.size();
  for (uint32_t jdx = 0; jdx < pool_count; jdx++) {
    std::cout << std::endl;
    std::cout << "Memory Pool Idx:                          "
         << pool_list_.at(jdx).index_ << std::endl;
    std::cout << "  max allocable size in KB:               "
         << pool_list_.at(jdx).allocable_size_ / 1024 << std::endl;
    std::cout << "  segment id:                             "
         << pool_list_.at(jdx).segment_ << std::endl;
    std::cout << "  is kernarg:                             "
         << pool_list_.at(jdx).is_kernarg_ << std::endl;
    std::cout << "  is fine-grained:                        "
         << pool_list_.at(jdx).is_fine_grained_ << std::endl;
    std::cout << "  accessible to owner:                    "
         << pool_list_.at(jdx).owner_access_ << std::endl;
    std::cout << "  accessible to all by default:           "
         << pool_list_.at(jdx).access_to_all_ << std::endl;
  }
  std::cout << std::endl;

}

// @brief: Print the list of transactions that will be executed
void RocmBandwidthTest::PrintTransList() {

  size_t count = trans_list_.size();
  for (uint32_t idx = 0; idx < count; idx++) {
    async_trans_t trans = trans_list_.at(idx);
    std::cout << std::endl;
    std::cout << "                 Transaction Id: " << idx << std::endl;
    std::cout << "               Transaction Type: " << trans.req_type_ << std::endl;
    if ((trans.req_type_ == REQ_READ) || (trans.req_type_ == REQ_WRITE)) {
      std::cout << "Rocm Kernel used by Transaction: " << trans.kernel.code_ << std::endl;
      std::cout << "Rocm Buffer index Used by Kernel: " << trans.kernel.pool_idx_ << std::endl;
      std::cout << "  Rocm Device used for Execution: " << trans.kernel.agent_idx_ << std::endl;
    }
    if ((trans.req_type_ == REQ_COPY_BIDIR) || (trans.req_type_ == REQ_COPY_UNIDIR)) {
      std::cout << "   Src Buffer used in Copy: " << trans.copy.src_idx_ << std::endl;
      std::cout << "   Dst Buffer used in Copy: " << trans.copy.dst_idx_ << std::endl;
    }
    if ((trans.req_type_ == REQ_COPY_ALL_BIDIR) || (trans.req_type_ == REQ_COPY_ALL_UNIDIR)) {
      std::cout << "   Src Memory Pool used in Copy: " << trans.copy.src_idx_ << std::endl;
      std::cout << "   Dst Memory Pool used in Copy: " << trans.copy.dst_idx_ << std::endl;
    }
351
352
353
354
355
    if ((trans.req_type_ == REQ_CONCURRENT_COPY_BIDIR) ||
        (trans.req_type_ == REQ_CONCURRENT_COPY_UNIDIR)) {
      std::cout << "   Src Memory Pool used in Copy: " << trans.copy.src_idx_ << std::endl;
      std::cout << "   Dst Memory Pool used in Copy: " << trans.copy.dst_idx_ << std::endl;
    }
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373

  }
  std::cout << std::endl;
}

// @brief: Prints error message when a request to copy between
// source buffer and destination buffer is not possible
void RocmBandwidthTest::PrintCopyAccessError(uint32_t src_idx, uint32_t dst_idx) {

  // Retrieve Roc runtime handles for Src memory pool and devices
  uint32_t src_dev_idx = pool_list_[src_idx].agent_index_;
  hsa_device_type_t src_dev_type = agent_list_[src_dev_idx].device_type_;
    
  // Retrieve Roc runtime handles for Dst memory pool and devices
  uint32_t dst_dev_idx = pool_list_[dst_idx].agent_index_;
  hsa_device_type_t dst_dev_type = agent_list_[dst_dev_idx].device_type_;

  std::cout << std::endl;
374
375
376
377
378
379
380
381
  std::cout << "Src Device: Index "
            << src_dev_idx
            << ", Type: "
            << ((src_dev_type == HSA_DEVICE_TYPE_CPU) ? "CPU" : "GPU") << std::endl;
  std::cout << "Dst Device: Index "
            << dst_dev_idx
            << ", Type: "
            << ((dst_dev_type == HSA_DEVICE_TYPE_CPU) ? "CPU" : "GPU") << std::endl;
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
  std::cout << "Rocm Device hosting Src Memory cannot ACCESS Dst Memory" << std::endl;
  std::cout << std::endl;
}

// @brief: Prints error message when a request to read / write from
// a buffer of a device is not possible
void RocmBandwidthTest::PrintIOAccessError(uint32_t exec_idx, uint32_t pool_idx) {

  // Retrieve device type of executing device
  hsa_device_type_t exec_dev_type = agent_list_[exec_idx].device_type_;
    
  // Retrieve device type of memory pool's device
  uint32_t pool_dev_idx = pool_list_[pool_idx].agent_index_;
  hsa_device_type_t pool_dev_type = agent_list_[pool_dev_idx].device_type_;

  std::cout << std::endl;
  std::cout << "Index of Executing Device: " << exec_idx << std::endl;
  std::cout << "Device Type of Executing Device: " << exec_dev_type << std::endl;

  std::cout << "Index of Buffer: " << pool_idx << std::endl;
  std::cout << "Index of Buffer's Device: " << pool_dev_idx << std::endl;
  std::cout << "Device Type Hosting Buffer: " << pool_dev_type << std::endl;
  std::cout << "Rocm Device executing Read / Write request cannot ACCESS Buffer" << std::endl;
  std::cout << std::endl;
}