Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpGEMM bad_alloc Error #31

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ add_subdirectory(range)
add_subdirectory(saxpy)
add_subdirectory(spmv)
add_subdirectory(spmm)
add_subdirectory(spgemm)
# end /* Add examples' subdirectories */
16 changes: 16 additions & 0 deletions examples/spgemm/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# begin /* Add application */
set(SOURCES
thread_mapped.cu
)

foreach(SOURCE IN LISTS SOURCES)
get_filename_component(TEST_NAME ${SOURCE} NAME_WLE)
add_executable(loops.spgemm.${TEST_NAME} ${SOURCE})
target_link_libraries(loops.spgemm.${TEST_NAME} PRIVATE loops)
set_target_properties(loops.spgemm.${TEST_NAME}
PROPERTIES
CUDA_ARCHITECTURES ${CMAKE_CUDA_ARCHITECTURES}
)
message(STATUS "Example Added: loops.spgemm.${TEST_NAME}")
endforeach()
# end /* Add application */
109 changes: 109 additions & 0 deletions examples/spgemm/filter_zeros.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"import scipy.io\n",
"import scipy.sparse\n",
"\n",
"import os\n",
"from pathlib import Path\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"def remove_zeros_and_save(input_file, output_file):\n",
" matrix = scipy.io.mmread(input_file)\n",
"\n",
" rows, cols, data = zip(*[(r, c, d) for r, c, d in zip(matrix.row, matrix.col, matrix.data) if d != 0])\n",
"\n",
" filtered_matrix = scipy.sparse.coo_matrix((data, (rows, cols)), shape=matrix.shape)\n",
"\n",
" scipy.io.mmwrite(output_file, filtered_matrix)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Processed matrix saved to /home/ychenfei/research/libs/loops/datasets/filtered_zeros/rma10.mtx\n"
]
}
],
"source": [
"remove_zeros_and_save('/data/toodemuy/datasets/floridaMatrices/rma10.mtx','/home/ychenfei/research/libs/loops/datasets/filtered_zeros/rma10.mtx')\n",
"print(f\"Processed matrix saved to {'/home/ychenfei/research/libs/loops/datasets/filtered_zeros/rma10.mtx'}\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"remove_zeros_and_save(input_file, output_file)"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"def filter_zero_in_bulk(dir):\n",
" path = Path(str(dir))\n",
" for file in path.iterdir():\n",
" # print(str(file))\n",
" file = str(file)\n",
" if file.endswith(\".mtx\"):\n",
" new_file = '/home/ychenfei/research/libs/loops/datasets/filtered_zeros/'+os.path.basename(file)\n",
" # print(new_file)\n",
" remove_zeros_and_save(file,new_file)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"filter_zero_in_bulk('/data/toodemuy/datasets/floridaMatrices/')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
78 changes: 78 additions & 0 deletions examples/spgemm/helpers.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/**
* @file helpers.hxx
* @author Muhammad Osama (mosama@ucdavis.edu)
* @brief Header file for SpGEMM.
* @version 0.1
* @copyright Copyright (c) 2022
*
*/

#pragma once

#include <loops/util/generate.hxx>
#include <loops/container/formats.hxx>
#include <loops/container/vector.hxx>
#include <loops/container/market.hxx>
#include <loops/util/filepath.hxx>
#include <loops/util/equal.hxx>
#include <loops/util/device.hxx>
#include <loops/util/timer.hxx>
#include <loops/memory.hxx>
#include <cxxopts.hpp>

#include <algorithm>
#include <iostream>

struct parameters_t {
std::string filename;
bool validate;
bool verbose;
cxxopts::Options options;

/**
* @brief Construct a new parameters object and parse command line arguments.
*
* @param argc Number of command line arguments.
* @param argv Command line arguments.
*/
parameters_t(int argc, char** argv)
: options(argv[0], "Sparse Matrix-Matrix Multiplication") {
// Add command line options
options.add_options()("h,help", "Print help") // help
("m,market", "Matrix file", cxxopts::value<std::string>()) // mtx
("validate", "CPU validation") // validate
("v,verbose", "Verbose output"); // verbose

// Parse command line arguments
auto result = options.parse(argc, argv);

if (result.count("help") || (result.count("market") == 0)) {
std::cout << options.help({""}) << std::endl;
std::exit(0);
}

if (result.count("market") == 1) {
filename = result["market"].as<std::string>();
if (loops::is_market(filename)) {
} else {
std::cout << options.help({""}) << std::endl;
std::exit(0);
}
} else {
std::cout << options.help({""}) << std::endl;
std::exit(0);
}

if (result.count("validate") == 1) {
validate = true;
} else {
validate = false;
}

if (result.count("verbose") == 1) {
verbose = true;
} else {
verbose = false;
}
}
};
70 changes: 70 additions & 0 deletions examples/spgemm/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# /home/ychenfei/research/libs/loops/build/bin/loops.spgemm.thread_mapped -m /home/ychenfei/research/sparse_matrix_perf_analysis/spgemm_dataflow_analysis/test_mtx/s100/ck104.mtx

# filepath="/home/ychenfei/research/sparse_matrix_perf_analysis/spgemm_dataflow_analysis/test_mtx2/bcsstk17.mtx"
# filename=$(basename "$filepath")

# echo "$filename" >> /home/ychenfei/research/libs/loops/examples/spgemm/running_time.txt
# /home/ychenfei/research/libs/loops/build/bin/loops.spgemm.thread_mapped -m /home/ychenfei/research/sparse_matrix_perf_analysis/spgemm_dataflow_analysis/test_mtx2/bcsstk17.mtx >> /home/ychenfei/research/libs/loops/examples/spgemm/running_time.txt

############## Output matrix C in dense format ##############
# export_file="/home/ychenfei/research/libs/loops/examples/spgemm/running_time/dense_C/dense_C_running_time_$(date +%Y-%m-%d).txt"

# export_file="/home/ychenfei/research/libs/loops/examples/spgemm/running_time/dense_C/testing.txt"

# exe="/home/ychenfei/research/libs/loops/build/bin/loops.spgemm.thread_mapped"

# > $export_file

# for f in /data/toodemuy/datasets/floridaMatrices/*.mtx
# do
# filename=$(basename "$f")
# echo "$filename" >> $export_file
# $exe -m $f >> $export_file
# echo >> $export_file
# done


############## Count the nnz of input matrices without explicit zeros ##############
# export_file="/home/ychenfei/research/libs/loops/examples/spgemm/running_time/nnz_C/non_explicit_zeros.txt"

# exe="/home/ychenfei/research/libs/loops/build/bin/loops.spgemm.thread_mapped"

# > $export_file

# for f in /home/ychenfei/research/libs/loops/datasets/non_explicit_zeros/*.mtx
# do
# filename=$(basename "$f")
# echo "$filename" >> $export_file
# $exe -m $f >> $export_file
# echo >> $export_file
# done

############## Count the explicit zeros from the input matrices when applying SpGEMM ##############
export_file="/home/ychenfei/research/libs/loops/examples/spgemm/export_mtx/nnz_C/explicit_zeros.txt"

exe="/home/ychenfei/research/libs/loops/build/bin/loops.spgemm.thread_mapped"

> $export_file

for f in /data/toodemuy/datasets/floridaMatrices/*.mtx
do
filename=$(basename "$f")
echo "$filename" >> $export_file
$exe -m $f >> $export_file
echo >> $export_file
done

############## Count the NNZ of C with input matrices have explicit zeros ##############
# export_file="/home/ychenfei/research/libs/loops/examples/spgemm/export_mtx/nnz_C/nnz_C_explicit_zeros_$(date +%Y-%m-%d).txt"

# exe="/home/ychenfei/research/libs/loops/build/bin/loops.spgemm.thread_mapped"

# > $export_file

# for f in /data/toodemuy/datasets/floridaMatrices/*.mtx
# do
# filename=$(basename "$f")
# echo "$filename" >> $export_file
# $exe -m $f >> $export_file
# echo >> $export_file
# done
7 changes: 7 additions & 0 deletions examples/spgemm/running_time.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
bcsstk17.mtx
Elapsed (ms): 2458.75

cant.mtx
Elapsed (ms): 27056

consph.mtx
20 changes: 20 additions & 0 deletions examples/spgemm/running_time/dense_C/running_time_2023-11-06.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
bcsstk17.mtx
Elapsed (ms): 2130.66

cant.mtx
Elapsed (ms): 23811.8

consph.mtx
Elapsed (ms): 48775.6

mac_econ_fwd500.mtx

pwtk.mtx

rma10.mtx
Elapsed (ms): 14880.4

scircuit.mtx

shipsec1.mtx

20 changes: 20 additions & 0 deletions examples/spgemm/running_time/dense_C/testing.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
bcsstk17.mtx
Elapsed (ms): 0.012288

cant.mtx
Elapsed (ms): 0.01536

consph.mtx
Elapsed (ms): 0.015328

mac_econ_fwd500.mtx

pwtk.mtx

rma10.mtx
Elapsed (ms): 0.018432

scircuit.mtx

shipsec1.mtx

Loading
Loading