Skip to content

Commit 3b0ef11

Browse files
jimmytweigta
and
gta
authored
Fixes memory allocation crash when work_group_size * compute_units is larger than max integer size (#1218)
* Makefile changes to support sse3 for icpx * Removed long filename * Reverted back to old README.md * Reverted back to old README.md * Deleted unused folders * Fixed overflow when compute_units * work_group_size is larger than maximum integer size * Fix Co-authored-by: gta <[email protected]>
1 parent b99bb50 commit 3b0ef11

File tree

1 file changed

+10
-2
lines changed
  • DirectProgramming/DPC++/SparseLinearAlgebra/merge-spmv/src

1 file changed

+10
-2
lines changed

DirectProgramming/DPC++/SparseLinearAlgebra/merge-spmv/src/spmv.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,16 @@ int main() {
384384

385385
// Find max number of compute/execution units and max number of threads per
386386
// compute unit.
387-
auto compute_units = device.get_info<info::device::max_compute_units>();
388-
auto work_group_size = device.get_info<info::device::max_work_group_size>();
387+
int compute_units = device.get_info<info::device::max_compute_units>();
388+
int work_group_size = device.get_info<info::device::max_work_group_size>();
389+
390+
int thread_count = compute_units * work_group_size;
391+
392+
// Detect overflow
393+
if ((size_t)thread_count > (size_t)INT_MAX) {
394+
// Scale down work_group_size so within maximum integer range
395+
work_group_size /= 2;
396+
}
389397

390398
cout << "Compute units: " << compute_units << "\n";
391399
cout << "Work group size: " << work_group_size << "\n";

0 commit comments

Comments
 (0)