Skip to content

Commit 1017f48

Browse files
committed
opencl: add opfilter regex for debugging
1 parent 5207d12 commit 1017f48

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <memory>
2929
#include <charconv>
3030
#include <mutex>
31+
#include <regex>
3132

3233
#undef MIN
3334
#undef MAX
@@ -396,6 +397,8 @@ struct ggml_backend_opencl_context {
396397
bool has_vector_subgroup_broadcast;
397398
bool disable_fusion;
398399

400+
std::regex opfilter; // regex of ops to not claim
401+
399402
bool adreno_has_large_buffer;
400403
bool adreno_use_large_buffer;
401404
ggml_cl_compiler_version adreno_cl_compiler_version;
@@ -3494,6 +3497,12 @@ static ggml_backend_opencl_context * ggml_cl2_init(ggml_backend_dev_t dev) {
34943497

34953498
backend_ctx->disable_fusion = getenv("GGML_OPENCL_DISABLE_FUSION") != nullptr;
34963499

3500+
const char * str_opfilter = getenv("GGML_OPENCL_OPFILTER");
3501+
if (str_opfilter) {
3502+
backend_ctx->opfilter = std::regex(str_opfilter, std::regex_constants::icase);
3503+
GGML_LOG_INFO("ggml_opencl: opfilter regex = \"%s\"\n", str_opfilter);
3504+
}
3505+
34973506
dev_ctx->backend_ctx = backend_ctx.release();
34983507
return dev_ctx->backend_ctx;
34993508
}
@@ -4143,6 +4152,11 @@ static bool ggml_opencl_supports_op(ggml_backend_dev_t dev, const struct ggml_te
41434152
ggml_backend_opencl_device_context * dev_ctx = (ggml_backend_opencl_device_context *)dev->context;
41444153
ggml_backend_opencl_context * backend_ctx = dev_ctx->backend_ctx;
41454154

4155+
// reject ops that match the opfilter regex
4156+
if (std::regex_match(std::string(ggml_op_desc(op)), backend_ctx->opfilter)) {
4157+
return false;
4158+
}
4159+
41464160
switch (op->op) {
41474161
case GGML_OP_NONE:
41484162
return true;

0 commit comments

Comments
 (0)