Skip to content

Commit 5fb23ce

Browse files
committed
opencl: refine Adreno cl compiler version parsing
1 parent a06517e commit 5fb23ce

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

ggml/src/ggml-opencl/ggml-opencl.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,12 @@ struct ggml_cl_version {
6969
cl_uint minor = 0;
7070
};
7171

72+
struct ggml_cl_compiler_version {
73+
int major = -1;
74+
int minor = -1;
75+
int patch = -1;
76+
};
77+
7278
// Parses a version string of form "XX.YY ". On an error returns ggml_cl_version with all zeroes.
7379
static ggml_cl_version parse_cl_version(std::string_view str) {
7480
size_t major_str_begin = 0;
@@ -173,24 +179,28 @@ static ADRENO_GPU_GEN get_adreno_gpu_gen(const char *device_name) {
173179
return ADRENO_GPU_GEN::ADRENO_UNKNOWN;
174180
}
175181

176-
static int get_adreno_cl_compiler_version(const char *driver_version) {
182+
static ggml_cl_compiler_version get_adreno_cl_compiler_version(const char *driver_version) {
177183
std::string driver_ver_str(driver_version);
178184
size_t compiler_ver_pos = driver_ver_str.find("E031");
179185
size_t compiler_ver_len = 13;
180-
size_t compiler_ver_offset = 5;
186+
size_t compiler_major_offset = 5;
187+
size_t compiler_minor_offset = 8;
188+
size_t compiler_patch_offset = 11;
181189

182190
if (compiler_ver_pos == std::string::npos) {
183191
compiler_ver_pos = driver_ver_str.find("DX");
184192
if (compiler_ver_pos == std::string::npos) {
185-
return -1;
193+
return {};
186194
}
187195
compiler_ver_len = 11;
188-
compiler_ver_offset = 3;
196+
compiler_major_offset = 3;
189197
}
190198

191199
std::string compiler_ver_str = driver_ver_str.substr(compiler_ver_pos, compiler_ver_len);
192-
std::string major_ver_str = compiler_ver_str.substr(compiler_ver_offset, 2);
193-
return std::atoi(major_ver_str.c_str());
200+
int major = std::atoi(compiler_ver_str.substr(compiler_major_offset, 2).c_str());
201+
int minor = std::atoi(compiler_ver_str.substr(compiler_minor_offset, 2).c_str());
202+
int patch = std::atoi(compiler_ver_str.substr(compiler_patch_offset, 2).c_str());
203+
return { major, minor, patch };
194204
}
195205

196206
// backend device context
@@ -216,6 +226,7 @@ struct ggml_backend_opencl_context {
216226
size_t max_alloc_size;
217227
bool fp16_support;
218228
bool has_vector_subgroup_broadcast;
229+
ggml_cl_compiler_version adreno_cl_compiler_version;
219230

220231
int adreno_wave_size;
221232

@@ -1308,9 +1319,10 @@ static ggml_backend_opencl_context * ggml_cl2_init(ggml_backend_dev_t dev) {
13081319
GGML_LOG_INFO("ggml_opencl: OpenCL driver: %s\n", driver_version);
13091320
backend_ctx->driver_version = driver_version;
13101321

1311-
int adreno_cl_compiler_version = get_adreno_cl_compiler_version(driver_version);
1322+
backend_ctx->adreno_cl_compiler_version = get_adreno_cl_compiler_version(driver_version);
13121323
backend_ctx->has_vector_subgroup_broadcast =
1313-
adreno_cl_compiler_version >= 47 || adreno_cl_compiler_version == 17;
1324+
backend_ctx->adreno_cl_compiler_version.major >= 47 ||
1325+
backend_ctx->adreno_cl_compiler_version.major == 17;
13141326
GGML_LOG_INFO("ggml_opencl: vector subgroup broadcast support: %s\n",
13151327
backend_ctx->has_vector_subgroup_broadcast ? "true" : "false");
13161328

0 commit comments

Comments
 (0)