Skip to content

Commit e03181d

Browse files
Esteban Padilla Cerdiofacebook-github-bot
authored andcommitted
Refactor and class split (#4432)
Summary: Pull Request resolved: #4432 Big classes are scary ☹️ This diff subdivides the tests into categories, places them as functions inside the gpuinfo namespace, instead of as part of the App class, and the App class is now only for persisting device information and configuration. Reviewed By: jorgep31415 Differential Revision: D60290882 fbshipit-source-id: b57f6e824be33320c01eebc5d5b72cbd2ad4c0cf
1 parent 5867129 commit e03181d

File tree

8 files changed

+859
-791
lines changed

8 files changed

+859
-791
lines changed

backends/vulkan/tools/gpuinfo/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"nunroll": 16,
2424
"niter": 10
2525
},
26-
"shared_mem_bandwidth": {
26+
"shared_bandwidth": {
2727
"enabled": true,
2828
"nflush": 4,
2929
"nunroll": 16,
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
#pragma once
10+
11+
#include <executorch/backends/vulkan/runtime/api/api.h>
12+
#include <folly/json.h>
13+
#include <fstream>
14+
#include <iostream>
15+
16+
#include "utils.h"
17+
18+
namespace gpuinfo {
19+
20+
class App {
21+
private:
22+
folly::dynamic config_;
23+
24+
public:
25+
size_t buf_cache_size;
26+
uint32_t max_shared_mem_size;
27+
uint32_t sm_count;
28+
uint32_t nthread_logic;
29+
uint32_t subgroup_size;
30+
uint32_t max_tex_width;
31+
uint32_t max_tex_height;
32+
uint32_t max_tex_depth;
33+
34+
App() {
35+
context()->initialize_querypool();
36+
37+
std::cout << context()->adapter_ptr()->stringize() << std::endl
38+
<< std::endl;
39+
40+
auto cl_device = get_cl_device();
41+
42+
sm_count = cl_device.getInfo<CL_DEVICE_MAX_COMPUTE_UNITS>();
43+
nthread_logic = cl_device.getInfo<CL_DEVICE_MAX_WORK_GROUP_SIZE>();
44+
buf_cache_size = cl_device.getInfo<CL_DEVICE_GLOBAL_MEM_CACHE_SIZE>();
45+
max_shared_mem_size = cl_device.getInfo<CL_DEVICE_LOCAL_MEM_SIZE>();
46+
max_tex_width = cl_device.getInfo<CL_DEVICE_IMAGE3D_MAX_WIDTH>();
47+
max_tex_height = cl_device.getInfo<CL_DEVICE_IMAGE3D_MAX_HEIGHT>();
48+
max_tex_depth = cl_device.getInfo<CL_DEVICE_IMAGE3D_MAX_DEPTH>();
49+
50+
VkPhysicalDeviceSubgroupProperties subgroup_props{};
51+
VkPhysicalDeviceProperties2 props2{};
52+
53+
props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2;
54+
props2.pNext = &subgroup_props;
55+
subgroup_props.sType =
56+
VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_PROPERTIES;
57+
vkGetPhysicalDeviceProperties2(
58+
context()->adapter_ptr()->physical_handle(), &props2);
59+
subgroup_size = subgroup_props.subgroupSize;
60+
61+
std::cout << std::endl;
62+
std::cout << "SM count," << sm_count << std::endl;
63+
std::cout << "Logic Thread Count," << nthread_logic << std::endl;
64+
std::cout << "Cache Size," << buf_cache_size << std::endl;
65+
std::cout << "Shared Memory Size," << max_shared_mem_size << std::endl;
66+
std::cout << "SubGroup Size," << subgroup_size << std::endl;
67+
std::cout << "MaxTexWidth," << max_tex_width << std::endl;
68+
std::cout << "MaxTexHeight," << max_tex_height << std::endl;
69+
std::cout << "MaxTexDepth," << max_tex_depth << std::endl;
70+
}
71+
72+
float get_config(const std::string& test, const std::string& key) const {
73+
if (config_[test].empty()) {
74+
throw std::runtime_error("Missing config for " + test);
75+
}
76+
77+
if (!config_[test][key].isNumber()) {
78+
throw std::runtime_error(
79+
"Config for " + test + "." + key + " is not a number");
80+
}
81+
82+
float value;
83+
if (config_[test][key].isDouble()) {
84+
value = config_[test][key].getDouble();
85+
} else {
86+
value = config_[test][key].getInt();
87+
}
88+
89+
std::cout << "Read value for " << test << "." << key << " = " << value
90+
<< std::endl;
91+
return value;
92+
}
93+
94+
bool enabled(const std::string& test) const {
95+
if (config_.empty() || config_[test].empty() ||
96+
!config_[test]["enabled"].isBool()) {
97+
return true;
98+
}
99+
return config_[test]["enabled"].getBool();
100+
}
101+
102+
void load_config(std::string file_path) {
103+
std::ifstream file(file_path);
104+
std::stringstream buffer;
105+
buffer << file.rdbuf();
106+
const std::string json_str = buffer.str();
107+
if (json_str.empty()) {
108+
throw std::runtime_error(
109+
"Failed to read config file from " + file_path + ".");
110+
}
111+
config_ = folly::parseJson(json_str);
112+
}
113+
};
114+
} // namespace gpuinfo

0 commit comments

Comments
 (0)