Skip to content

Commit e82f9e2

Browse files
[SYCL] Fix batched impl for NVidia GPU (ggml-org#6164)
* Fix batched impl * Maintain previous behaviour for igpu * retrigger CI --------- Co-authored-by: Abhilash Majumder <[email protected]>
1 parent cbc8343 commit e82f9e2

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

ggml-sycl.cpp

+25-4
Original file line numberDiff line numberDiff line change
@@ -14986,6 +14986,9 @@ static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
1498614986
SYCL_CHECK(ggml_sycl_set_device(g_main_device));
1498714987
dpct::queue_ptr main_stream = g_syclStreams[g_main_device][0];
1498814988

14989+
bool no_mixed_dtypes = main_stream->get_backend() == sycl::backend::ext_oneapi_cuda ||
14990+
main_stream->get_backend() == sycl::backend::ext_oneapi_hip;
14991+
1498914992
SYCL_CHECK(
1499014993
CHECK_TRY_ERROR(g_sycl_handles[g_main_device] = main_stream));
1499114994

@@ -15016,24 +15019,38 @@ static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
1501615019

1501715020
dpct::library_data_t cu_compute_type = dpct::library_data_t::real_float;
1501815021
dpct::library_data_t cu_data_type = dpct::library_data_t::real_float;
15022+
if (no_mixed_dtypes) {
15023+
cu_compute_type = dpct::library_data_t::real_half;
15024+
cu_data_type = dpct::library_data_t::real_half;
15025+
}
1501915026

1502015027
// dst strides
1502115028
size_t nbd2 = dst->nb[2];
1502215029
size_t nbd3 = dst->nb[3];
1502315030

15031+
const float alpha_f32 = 1.0f;
15032+
const float beta_f32 = 0.0f;
15033+
1502415034
const sycl::half alpha_f16 = 1.0f;
1502515035
const sycl::half beta_f16 = 0.0f;
1502615036

15027-
const float alpha_f32 = 1.0f;
15028-
const float beta_f32 = 0.0f;
15029-
1503015037
const void * alpha = &alpha_f32;
1503115038
const void * beta = &beta_f32;
15039+
if (no_mixed_dtypes) {
15040+
alpha = &alpha_f16;
15041+
beta = &beta_f16;
15042+
}
1503215043

1503315044
// TODO: Renable (dst->op_params[0] =! GGML_PREC_DEFAULT) pathway
15034-
// oneMKL open source supports half, half, float, float: datatypes
15045+
// when oneMKL open source supports half, half, float, float: datatypes
1503515046

1503615047
dst_t = (char *) dst_ddf;
15048+
if (no_mixed_dtypes) {
15049+
dst_t = (char *) dst_f16.alloc(ne_dst);
15050+
15051+
nbd2 /= sizeof(float) / sizeof(sycl::half);
15052+
nbd3 /= sizeof(float) / sizeof(sycl::half);
15053+
}
1503715054

1503815055
GGML_ASSERT(ne12 % ne02 == 0);
1503915056
GGML_ASSERT(ne13 % ne03 == 0);
@@ -15119,6 +15136,10 @@ static void ggml_sycl_mul_mat_batched_sycl(const ggml_tensor *src0,
1511915136
}
1512015137
#endif
1512115138

15139+
if (no_mixed_dtypes) {
15140+
const to_fp32_sycl_t to_fp32_sycl = ggml_get_to_fp32_sycl(GGML_TYPE_F16);
15141+
to_fp32_sycl(dst_f16.get(), dst_ddf, ne_dst, main_stream);
15142+
}
1512215143
}
1512315144
catch (sycl::exception const &exc) {
1512415145
std::cerr << exc.what() << "Exception caught at file:" << __FILE__

0 commit comments

Comments
 (0)