Skip to content

Commit 7875f38

Browse files
Check if malloc_device return nullptr (#1493)
1 parent 6c57d2b commit 7875f38

File tree

1 file changed

+25
-1
lines changed
  • dpctl/tensor/libtensor/include/kernels/linalg_functions

1 file changed

+25
-1
lines changed

dpctl/tensor/libtensor/include/kernels/linalg_functions/gemm.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2024,6 +2024,9 @@ sycl::event gemm_tree_k_impl(sycl::queue &exec_q,
20242024
if (reduction_nelems < wg) {
20252025
resTy *tmp = sycl::malloc_device<resTy>(
20262026
iter_nelems * reduction_nelems, exec_q);
2027+
if (!tmp) {
2028+
throw std::runtime_error("Unable to allocate device memory");
2029+
}
20272030
sycl::event gemm_ev = exec_q.submit([&](sycl::handler &cgh) {
20282031
cgh.depends_on(depends);
20292032

@@ -2144,7 +2147,7 @@ sycl::event gemm_tree_k_impl(sycl::queue &exec_q,
21442147
resTy *partially_reduced_tmp2 = nullptr;
21452148

21462149
if (partially_reduced_tmp == nullptr) {
2147-
throw std::runtime_error("Unable to allocate device_memory");
2150+
throw std::runtime_error("Unable to allocate device memory");
21482151
}
21492152
else {
21502153
partially_reduced_tmp2 =
@@ -2360,6 +2363,9 @@ sycl::event gemm_tree_nm_impl(sycl::queue &exec_q,
23602363
if (reduction_nelems < wg) {
23612364
resTy *tmp = sycl::malloc_device<resTy>(
23622365
iter_nelems * reduction_nelems, exec_q);
2366+
if (!tmp) {
2367+
throw std::runtime_error("Unable to allocate device memory");
2368+
}
23632369
sycl::event gemm_ev = exec_q.submit([&](sycl::handler &cgh) {
23642370
cgh.depends_on(depends);
23652371

@@ -2768,6 +2774,9 @@ sycl::event gemm_contig_tree_k_impl(sycl::queue &exec_q,
27682774
if (reduction_nelems < wg) {
27692775
resTy *tmp = sycl::malloc_device<resTy>(
27702776
iter_nelems * reduction_nelems, exec_q);
2777+
if (!tmp) {
2778+
throw std::runtime_error("Unable to allocate device memory");
2779+
}
27712780
sycl::event gemm_ev = exec_q.submit([&](sycl::handler &cgh) {
27722781
cgh.depends_on(depends);
27732782

@@ -3092,6 +3101,9 @@ sycl::event gemm_contig_tree_nm_impl(sycl::queue &exec_q,
30923101
if (reduction_nelems < wg) {
30933102
resTy *tmp = sycl::malloc_device<resTy>(
30943103
iter_nelems * reduction_nelems, exec_q);
3104+
if (!tmp) {
3105+
throw std::runtime_error("Unable to allocate device memory");
3106+
}
30953107
sycl::event gemm_ev = exec_q.submit([&](sycl::handler &cgh) {
30963108
cgh.depends_on(depends);
30973109

@@ -5254,6 +5266,9 @@ gemm_batch_tree_k_impl(sycl::queue &exec_q,
52545266
if (reduction_nelems < wg) {
52555267
resTy *tmp = sycl::malloc_device<resTy>(
52565268
iter_nelems * reduction_nelems, exec_q);
5269+
if (!tmp) {
5270+
throw std::runtime_error("Unable to allocate device memory");
5271+
}
52575272
sycl::event gemm_ev = exec_q.submit([&](sycl::handler &cgh) {
52585273
cgh.depends_on(depends);
52595274

@@ -5647,6 +5662,9 @@ gemm_batch_tree_nm_impl(sycl::queue &exec_q,
56475662
if (reduction_nelems < wg) {
56485663
resTy *tmp = sycl::malloc_device<resTy>(
56495664
iter_nelems * reduction_nelems, exec_q);
5665+
if (!tmp) {
5666+
throw std::runtime_error("Unable to allocate device memory");
5667+
}
56505668
sycl::event gemm_ev = exec_q.submit([&](sycl::handler &cgh) {
56515669
cgh.depends_on(depends);
56525670

@@ -6124,6 +6142,9 @@ gemm_batch_contig_tree_k_impl(sycl::queue &exec_q,
61246142
if (reduction_nelems < wg) {
61256143
resTy *tmp = sycl::malloc_device<resTy>(
61266144
iter_nelems * reduction_nelems, exec_q);
6145+
if (!tmp) {
6146+
throw std::runtime_error("Unable to allocate device memory");
6147+
}
61276148
sycl::event gemm_ev = exec_q.submit([&](sycl::handler &cgh) {
61286149
cgh.depends_on(depends);
61296150

@@ -6493,6 +6514,9 @@ gemm_batch_contig_tree_nm_impl(sycl::queue &exec_q,
64936514
if (reduction_nelems < wg) {
64946515
resTy *tmp = sycl::malloc_device<resTy>(
64956516
iter_nelems * reduction_nelems, exec_q);
6517+
if (!tmp) {
6518+
throw std::runtime_error("Unable to allocate device memory");
6519+
}
64966520
sycl::event gemm_ev = exec_q.submit([&](sycl::handler &cgh) {
64976521
cgh.depends_on(depends);
64986522

0 commit comments

Comments
 (0)