From 30a3d6dc147b6040add92f2e419c4ade17ab2984 Mon Sep 17 00:00:00 2001 From: Tim Davis Date: Fri, 7 Jun 2024 08:17:22 -0500 Subject: [PATCH] sync with GraphBLAS repo --- GraphBLAS/Config/GraphBLAS.h.in | 2 +- GraphBLAS/Include/GraphBLAS.h | 2 +- GraphBLAS/JITpackage/CMakeLists.txt | 10 ++- GraphBLAS/JITpackage/Source/grb_jitpackage.c | 73 ++++++++++++++++--- GraphBLAS/Source/builtin/include/GB_matrix.h | 10 ++- .../Source/iterator/GB_Iterator_rc_seek.c | 3 +- .../Source/iterator/GxB_Matrix_Iterator.c | 27 +++---- 7 files changed, 94 insertions(+), 33 deletions(-) diff --git a/GraphBLAS/Config/GraphBLAS.h.in b/GraphBLAS/Config/GraphBLAS.h.in index 1b35318903..009f3ab73a 100644 --- a/GraphBLAS/Config/GraphBLAS.h.in +++ b/GraphBLAS/Config/GraphBLAS.h.in @@ -11856,7 +11856,7 @@ GrB_Info GxB_Vector_Iterator_seek (GxB_Iterator iterator, GrB_Index p) ; #define GB_Vector_Iterator_seek(iterator, q) \ ( \ - (q >= iterator->pmax) ? \ + (((int64_t) q) >= iterator->pmax) ? \ ( \ /* the iterator is exhausted */ \ iterator->p = iterator->pmax, \ diff --git a/GraphBLAS/Include/GraphBLAS.h b/GraphBLAS/Include/GraphBLAS.h index 2d07b926e1..6c4b5865c2 100644 --- a/GraphBLAS/Include/GraphBLAS.h +++ b/GraphBLAS/Include/GraphBLAS.h @@ -11856,7 +11856,7 @@ GrB_Info GxB_Vector_Iterator_seek (GxB_Iterator iterator, GrB_Index p) ; #define GB_Vector_Iterator_seek(iterator, q) \ ( \ - (q >= iterator->pmax) ? \ + (((int64_t) q) >= iterator->pmax) ? \ ( \ /* the iterator is exhausted */ \ iterator->p = iterator->pmax, \ diff --git a/GraphBLAS/JITpackage/CMakeLists.txt b/GraphBLAS/JITpackage/CMakeLists.txt index d31cd51b49..f0ded1b552 100644 --- a/GraphBLAS/JITpackage/CMakeLists.txt +++ b/GraphBLAS/JITpackage/CMakeLists.txt @@ -82,11 +82,17 @@ if ( TARGET grb_jitpackage ) "../Source/*/include/*" "../Source/include/*" ) + # write list of source files for generator to file + file ( WRITE ${PROJECT_BINARY_DIR}/grb_source_file_list "" ) + foreach ( src_file ${GRB_SOURCE_FILES} ) + file ( APPEND ${PROJECT_BINARY_DIR}/grb_source_file_list ${src_file}\n ) + endforeach ( ) + add_custom_command ( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/GB_JITpackage.c COMMAND $ - ARGS ${GRB_SOURCE_FILES} + ARGS @${PROJECT_BINARY_DIR}/grb_source_file_list WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - DEPENDS ${GRB_SOURCE_FILES} + DEPENDS ${GRB_SOURCE_FILES} ${PROJECT_BINARY_DIR}/grb_source_file_list COMMENT "Generating compressed sources for JIT compiler..." ) # target to make sure the file exists when building libgraphblas diff --git a/GraphBLAS/JITpackage/Source/grb_jitpackage.c b/GraphBLAS/JITpackage/Source/grb_jitpackage.c index 992a92d2eb..2d6d5551dc 100644 --- a/GraphBLAS/JITpackage/Source/grb_jitpackage.c +++ b/GraphBLAS/JITpackage/Source/grb_jitpackage.c @@ -2,7 +2,7 @@ // grb_jitpackage: package GraphBLAS source code for the JIT //------------------------------------------------------------------------------ -// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2023, All Rights Reserved. +// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2024, All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 //------------------------------------------------------------------------------ @@ -11,6 +11,7 @@ #include #include #include +#include //------------------------------------------------------------------------------ // zstd.h include file @@ -112,14 +113,61 @@ bool match_prefix (char *string, char *prefix) int main (int argc, char **argv) { + //-------------------------------------------------------------------------- + // get list of files to be processed + //-------------------------------------------------------------------------- + + char **file_list = NULL; + size_t nfiles = 0; + + if (argc == 2 && argv[1][0] == '@') + { + // input argument is a "response file" containing the file list + + // open file + FILE *fr = fopen (argv[1]+1, "rb") ; + OK (fr != NULL) ; + + // get number of lines in file + char ch; + do + { + ch = fgetc (fr); + if (ch == '\n') + nfiles++; + } while (ch != EOF); + + // read file list from response file + rewind (fr); + file_list = malloc ( (nfiles+1) * sizeof (file_list) ); + // prepend empty element for compatibility with argv + file_list[0] = malloc (1); + file_list[0][0] = '\0'; + char temp[200]; + size_t length; + for (size_t i = 1 ; i < nfiles+1 ; i++) + { + fscanf (fr, "%s\n", temp); + length = strlen (temp); + file_list[i] = malloc (length+1); + strncpy (file_list[i], temp, length); + file_list[i][length] = '\0'; + } + } + else + { + // input argument list is the file list + nfiles = argc - 1 ; + file_list = argv; + } + //-------------------------------------------------------------------------- // start the GB_JITpackage.c file //-------------------------------------------------------------------------- FILE *fp = fopen ("GB_JITpackage.c", "wb") ; OK (fp != NULL) ; - int nfiles = argc - 1 ; - printf ("Processing %d input files ...\n", nfiles) ; + printf ("Processing %zu input files ...\n", nfiles) ; fprintf (fp, "//------------------------------------------------------------------------------\n" @@ -139,7 +187,7 @@ int main (int argc, char **argv) "GB_JITpackage_index_struct GB_JITpackage_index [1] " "= {{0, 0, NULL, NULL}} ;\n" "#else\n" - "int GB_JITpackage_nfiles = %d ;\n\n", argc-1) ; + "int GB_JITpackage_nfiles = %zu ;\n\n", nfiles) ; //-------------------------------------------------------------------------- // allocate the index @@ -156,14 +204,14 @@ int main (int argc, char **argv) // compress each file //-------------------------------------------------------------------------- - for (int k = 1 ; k < argc ; k++) + for (size_t k = 1 ; k < nfiles+1 ; k++) { //---------------------------------------------------------------------- // read the input file //---------------------------------------------------------------------- - FILE *ff = fopen (argv [k], "r") ; + FILE *ff = fopen (file_list [k], "r") ; OK (ff != NULL) ; fseek (ff, 0, SEEK_END) ; size_t inputsize = ftell (ff) ; @@ -189,8 +237,8 @@ int main (int argc, char **argv) // append the bytes to the output file //---------------------------------------------------------------------- - fprintf (fp, "// %s:\n", argv [k]) ; - fprintf (fp, "uint8_t GB_JITpackage_%d [%zu] = {\n", k-1, dsize) ; + fprintf (fp, "// %s:\n", file_list [k]) ; + fprintf (fp, "uint8_t GB_JITpackage_%zu [%zu] = {\n", k-1, dsize) ; for (int64_t k = 0 ; k < dsize ; k++) { fprintf (fp, "%3d,", dst [k]) ; @@ -219,15 +267,15 @@ int main (int argc, char **argv) printf ("Compression: %g\n", (double) total_compressed_size / (double) total_uncompressed_size) ; - fprintf (fp, "\nGB_JITpackage_index_struct GB_JITpackage_index [%d] =\n{\n", + fprintf (fp, "\nGB_JITpackage_index_struct GB_JITpackage_index [%zu] =\n{\n", nfiles) ; - for (int k = 1 ; k < argc ; k++) + for (int k = 1 ; k < nfiles+1 ; k++) { // get the filename - char *fullname = argv [k] ; + char *fullname = file_list [k] ; char *filename = fullname ; int len = (int) strlen (fullname) ; -// for (char *p = argv [k] ; *p != '\0' ; p++) +// for (char *p = file_list [k] ; *p != '\0' ; p++) for (int i = 0 ; i < len ; i++) { @@ -249,5 +297,6 @@ int main (int argc, char **argv) fclose (fp) ; free (Uncompressed_size) ; free (Compressed_size) ; + return (0) ; } diff --git a/GraphBLAS/Source/builtin/include/GB_matrix.h b/GraphBLAS/Source/builtin/include/GB_matrix.h index 26b5e0518e..441621bff6 100644 --- a/GraphBLAS/Source/builtin/include/GB_matrix.h +++ b/GraphBLAS/Source/builtin/include/GB_matrix.h @@ -585,7 +585,9 @@ bool iso ; // true if all entries have the same value { j = k ; // operate on column A(:,j) - for (p = Ap [k] ; p < Ap [k+1] ; p++) + int64_t pA_start = Ap [k] + int64_t pA_end = Ap [k+1] ; + for (p = pA_start ; p < pA_end ; p++) { // entry A(i,j) with row index i and value aij int64_t i = Ai [p] ; @@ -594,13 +596,15 @@ bool iso ; // true if all entries have the same value } //-------------------- - // (4) hypersparse // A->h is non-NULL, A->nvec <= A->dim + // (4) hypersparse // A->h is non-NULL, A->nvec <= A->vdim for (k = 0 ; k < A->nvec ; k++) { j = A->h [k] // operate on column A(:,j) - for (p = Ap [k] ; p < Ap [k+1] ; p++) + int64_t pA_start = Ap [k] + int64_t pA_end = Ap [k+1] ; + for (p = pA_start ; p < pA_end ; p++) { // entry A(i,j) with row index i and value aij int64_t i = Ai [p] ; diff --git a/GraphBLAS/Source/iterator/GB_Iterator_rc_seek.c b/GraphBLAS/Source/iterator/GB_Iterator_rc_seek.c index 1a64ac0c41..79e25922ce 100644 --- a/GraphBLAS/Source/iterator/GB_Iterator_rc_seek.c +++ b/GraphBLAS/Source/iterator/GB_Iterator_rc_seek.c @@ -18,7 +18,7 @@ GrB_Info GB_Iterator_rc_seek ( GxB_Iterator iterator, - GrB_Index j, + GrB_Index j_input, bool jth_vector ) { @@ -27,6 +27,7 @@ GrB_Info GB_Iterator_rc_seek // check if the iterator is exhausted //-------------------------------------------------------------------------- + int64_t j = (int64_t) j_input ; if (j >= ((jth_vector) ? iterator->anvec : iterator->avdim)) { iterator->pstart = 0 ; diff --git a/GraphBLAS/Source/iterator/GxB_Matrix_Iterator.c b/GraphBLAS/Source/iterator/GxB_Matrix_Iterator.c index afeeec51fe..daac48e640 100644 --- a/GraphBLAS/Source/iterator/GxB_Matrix_Iterator.c +++ b/GraphBLAS/Source/iterator/GxB_Matrix_Iterator.c @@ -161,9 +161,10 @@ GrB_Info GxB_Matrix_Iterator_next (GxB_Iterator iterator) GrB_Info GxB_Matrix_Iterator_seek ( GxB_Iterator iterator, - GrB_Index p + GrB_Index p_input ) { + int64_t p = (int64_t) p_input ; if (p >= iterator->pmax) { // the iterator is exhausted @@ -262,13 +263,13 @@ void GxB_Matrix_Iterator_getIndex { if (iterator->by_col) { - (*row) = iterator->Ai [iterator->p] ; - (*col) = iterator->k ; + (*row) = (GrB_Index) (iterator->Ai [iterator->p]) ; + (*col) = (GrB_Index) (iterator->k) ; } else { - (*row) = iterator->k ; - (*col) = iterator->Ai [iterator->p] ; + (*row) = (GrB_Index) (iterator->k) ; + (*col) = (GrB_Index) (iterator->Ai [iterator->p]) ; } } break ; @@ -277,13 +278,13 @@ void GxB_Matrix_Iterator_getIndex { if (iterator->by_col) { - (*row) = iterator->Ai [iterator->p] ; - (*col) = iterator->Ah [iterator->k] ; + (*row) = (GrB_Index) (iterator->Ai [iterator->p]) ; + (*col) = (GrB_Index) (iterator->Ah [iterator->k]) ; } else { - (*row) = iterator->Ah [iterator->k] ; - (*col) = iterator->Ai [iterator->p] ; + (*row) = (GrB_Index) (iterator->Ah [iterator->k]) ; + (*col) = (GrB_Index) (iterator->Ai [iterator->p]) ; } } break ; @@ -293,13 +294,13 @@ void GxB_Matrix_Iterator_getIndex { if (iterator->by_col) { - (*row) = iterator->p - iterator->pstart ; - (*col) = iterator->k ; + (*row) = (GrB_Index) (iterator->p - iterator->pstart) ; + (*col) = (GrB_Index) (iterator->k) ; } else { - (*row) = iterator->k ; - (*col) = iterator->p - iterator->pstart ; + (*row) = (GrB_Index) (iterator->k) ; + (*col) = (GrB_Index) (iterator->p - iterator->pstart) ; } } break ;