Skip to content

Commit 65d9911

Browse files
committed
Use string_view
1 parent 1ae14e0 commit 65d9911

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

ggml/src/ggml-sycl/common.hpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -539,27 +539,37 @@ inline void debug_print_tensor(const std::string & prefix, const ggml_tensor * t
539539
GGML_SYCL_DEBUG("%s", suffix.c_str());
540540
}
541541

542+
// Use scope_op_debug_print to log operations coming from running a model
542543
struct scope_op_debug_print {
543-
scope_op_debug_print(const std::string & func, const ggml_tensor * dst, std::size_t num_src,
544-
const std::string & suffix = "") :
545-
func(func) {
544+
// Use string_views to avoid the cost of creating a string and concatenating them
545+
// string_views must be alive for as long as the object is alive
546+
// scope_op_debug_print are used with string literals in practice which are stored in constant space so always accessible
547+
scope_op_debug_print(const std::string_view & func, const std::string_view & func_suffix, const ggml_tensor * dst,
548+
std::size_t num_src, const std::string_view & suffix = "") :
549+
func(func),
550+
func_suffix(func_suffix) {
546551
if (LIKELY(!g_ggml_sycl_debug)) {
547552
return;
548553
}
549-
GGML_SYCL_DEBUG("[SYCL][OP] call %s:", func.c_str());
554+
GGML_SYCL_DEBUG("[SYCL][OP] call %s%s:", func.data(), func_suffix.data());
550555
debug_print_tensor(" dst", dst);
551556
if (dst) {
552557
for (std::size_t i = 0; i < num_src; ++i) {
553558
debug_print_tensor("\tsrc" + std::to_string(i), dst->src[i]);
554559
}
555560
}
556-
GGML_SYCL_DEBUG("%s\n", suffix.c_str());
561+
GGML_SYCL_DEBUG("%s\n", suffix.data());
557562
}
558563

559-
~scope_op_debug_print() { GGML_SYCL_DEBUG("[SYCL][OP] call %s done\n", func.c_str()); }
564+
scope_op_debug_print(const std::string_view & func, const ggml_tensor * dst, std::size_t num_src,
565+
const std::string_view & suffix = "") :
566+
scope_op_debug_print(func, "", dst, num_src, suffix) {}
567+
568+
~scope_op_debug_print() { GGML_SYCL_DEBUG("[SYCL][OP] call %s%s done\n", func.data(), func_suffix.data()); }
560569

561570
private:
562-
std::string func;
571+
std::string_view func;
572+
std::string_view func_suffix;
563573
};
564574

565575
#endif // GGML_SYCL_COMMON_HPP

ggml/src/ggml-sycl/dmmv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ void ggml_sycl_op_dequantize_mul_mat_vec(
10921092
src0->type == GGML_TYPE_Q8_0 || src0->type == GGML_TYPE_F16;
10931093

10941094
if (src1_convert_f16) {
1095-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "to_fp16_sycl", dst, /*num_src=*/2,
1095+
scope_op_debug_print scope_dbg_print(__func__, "/to_fp16_sycl", dst, /*num_src=*/2,
10961096
" : converting src1 to fp16");
10971097
src1_dfloat = src1_dfloat_a.alloc(ne00);
10981098
const to_fp16_sycl_t to_fp16_sycl = ggml_get_to_fp16_sycl(src1->type, dst);

ggml/src/ggml-sycl/ggml-sycl.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2040,7 +2040,7 @@ inline void ggml_sycl_op_mul_mat_sycl(
20402040
row_diff == src0->ne[1] && dst->op_params[0] == GGML_PREC_DEFAULT) {
20412041
ggml_sycl_pool_alloc<sycl::half> src0_as_f16(ctx.pool());
20422042
if (src0->type != GGML_TYPE_F16) {
2043-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/to_fp16_sycl", dst, /*num_src=*/2,
2043+
scope_op_debug_print scope_dbg_print(__func__, "/to_fp16_sycl", dst, /*num_src=*/2,
20442044
" : converting src0 to fp16");
20452045
const to_fp16_sycl_t to_fp16_sycl = ggml_get_to_fp16_sycl(src0->type, dst);
20462046
GGML_ASSERT(to_fp16_sycl != nullptr);
@@ -2054,7 +2054,7 @@ inline void ggml_sycl_op_mul_mat_sycl(
20542054

20552055
ggml_sycl_pool_alloc<sycl::half> src1_as_f16(ctx.pool());
20562056
if (src1->type != GGML_TYPE_F16) {
2057-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/to_fp16_sycl", dst, /*num_src=*/2,
2057+
scope_op_debug_print scope_dbg_print(__func__, "/to_fp16_sycl", dst, /*num_src=*/2,
20582058
" : converting src1 to fp16");
20592059
const to_fp16_sycl_t to_fp16_sycl = ggml_get_to_fp16_sycl(src1->type, dst);
20602060
GGML_ASSERT(to_fp16_sycl != nullptr);
@@ -2072,7 +2072,7 @@ inline void ggml_sycl_op_mul_mat_sycl(
20722072
DnnlGemmWrapper::row_gemm(ctx, src1_ncols, row_diff, ne10, src1_ptr,
20732073
DnnlGemmWrapper::to_dt<sycl::half>(), src0_ptr, DnnlGemmWrapper::to_dt<sycl::half>(),
20742074
dst_f16.get(), DnnlGemmWrapper::to_dt<sycl::half>(), stream);
2075-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/to_fp32_sycl", dst, /*num_src=*/2,
2075+
scope_op_debug_print scope_dbg_print(__func__, "/to_fp32_sycl", dst, /*num_src=*/2,
20762076
" : converting dst to fp32");
20772077
const to_fp32_sycl_t to_fp32_sycl = ggml_get_to_fp32_sycl(GGML_TYPE_F16, dst);
20782078
to_fp32_sycl(dst_f16.get(), dst_dd_i, row_diff* src1_ncols, stream);
@@ -2089,7 +2089,7 @@ inline void ggml_sycl_op_mul_mat_sycl(
20892089
src1_ptr, dpct::library_data_t::real_half, ne10, &beta_f16,
20902090
dst_f16.get(), dpct::library_data_t::real_half, ldc,
20912091
dpct::library_data_t::real_half)));
2092-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/to_fp32_sycl", dst, /*num_src=*/2,
2092+
scope_op_debug_print scope_dbg_print(__func__, "/to_fp32_sycl", dst, /*num_src=*/2,
20932093
" : converting dst to fp32");
20942094
const to_fp32_sycl_t to_fp32_sycl = ggml_get_to_fp32_sycl(GGML_TYPE_F16, dst);
20952095
to_fp32_sycl(dst_f16.get(), dst_dd_i, row_diff*src1_ncols, stream);
@@ -2098,15 +2098,15 @@ inline void ggml_sycl_op_mul_mat_sycl(
20982098
ggml_sycl_pool_alloc<float> src0_ddq_as_f32(ctx.pool());
20992099
ggml_sycl_pool_alloc<float> src1_ddq_as_f32(ctx.pool());
21002100
if (src0->type != GGML_TYPE_F32) {
2101-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/to_fp32_sycl", dst, /*num_src=*/2,
2101+
scope_op_debug_print scope_dbg_print(__func__, "/to_fp32_sycl", dst, /*num_src=*/2,
21022102
" : converting src0 to fp32");
21032103
const to_fp32_sycl_t to_fp32_sycl = ggml_get_to_fp32_sycl(src0->type, dst);
21042104
GGML_ASSERT(to_fp32_sycl != nullptr);
21052105
src0_ddq_as_f32.alloc(row_diff*ne00);
21062106
to_fp32_sycl(src0_dd_i, src0_ddq_as_f32.get(), row_diff*ne00, stream);
21072107
}
21082108
if (src1->type != GGML_TYPE_F32) {
2109-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/to_fp32_sycl", dst, /*num_src=*/2,
2109+
scope_op_debug_print scope_dbg_print(__func__, "/to_fp32_sycl", dst, /*num_src=*/2,
21102110
" : converting src1 to fp32");
21112111
const to_fp32_sycl_t to_fp32_sycl = ggml_get_to_fp32_sycl(src1->type, dst);
21122112
GGML_ASSERT(to_fp32_sycl != nullptr);
@@ -2445,7 +2445,7 @@ static void ggml_sycl_op_mul_mat(ggml_backend_sycl_context & ctx, const ggml_ten
24452445
dev[i].src1_ddq = dev[i].src1_ddq_alloc.alloc(ctx.pool(i), nrows1*src1_padded_col_size*q8_1_ts/q8_1_bs);
24462446

24472447
if (src1_on_device && src1_is_contiguous) {
2448-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/quantize_row_q8_1_sycl", dst,
2448+
scope_op_debug_print scope_dbg_print(__func__, "/quantize_row_q8_1_sycl", dst,
24492449
/*num_src=*/2, " : converting src1 to Q8_1");
24502450
quantize_row_q8_1_sycl(dev[i].src1_ddf, dev[i].src1_ddq, ne10, nrows1, src1_padded_col_size, stream);
24512451
/*
@@ -2551,7 +2551,7 @@ static void ggml_sycl_op_mul_mat(ggml_backend_sycl_context & ctx, const ggml_ten
25512551
}
25522552

25532553
if (convert_src1_to_q8_1 && !src1_is_contiguous) {
2554-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/quantize_row_q8_1_sycl", dst,
2554+
scope_op_debug_print scope_dbg_print(__func__, "/quantize_row_q8_1_sycl", dst,
25552555
/*num_src=*/2, " : converting src1 to Q8_1");
25562556
quantize_row_q8_1_sycl(src1_ddf_i, src1_ddq_i, ne10, src1_ncols, src1_padded_col_size, stream);
25572557
/*
@@ -2796,7 +2796,7 @@ static void ggml_sycl_mul_mat_batched_sycl(ggml_backend_sycl_context & ctx, cons
27962796

27972797
// convert src1 to fp16
27982798
if (src1->type != GGML_TYPE_F16) {
2799-
scope_op_debug_print scope_dbg_print(std::string(__func__) + "/to_fp16_nc_sycl", dst, /*num_src=*/2,
2799+
scope_op_debug_print scope_dbg_print(__func__, "/to_fp16_nc_sycl", dst, /*num_src=*/2,
28002800
" : converting src1 to fp16");
28012801
const to_fp16_nc_sycl_t to_fp16_nc_sycl = get_to_fp16_nc_sycl(src1->type);
28022802
GGML_ASSERT(to_fp16_nc_sycl != nullptr);

0 commit comments

Comments
 (0)