Skip to content

Commit

Permalink
sync with GraphBLAS repo
Browse files Browse the repository at this point in the history
  • Loading branch information
DrTimothyAldenDavis committed Jun 7, 2024
1 parent 5411c96 commit 30a3d6d
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 33 deletions.
2 changes: 1 addition & 1 deletion GraphBLAS/Config/GraphBLAS.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down
2 changes: 1 addition & 1 deletion GraphBLAS/Include/GraphBLAS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down
10 changes: 8 additions & 2 deletions GraphBLAS/JITpackage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE:grb_jitpackage>
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
Expand Down
73 changes: 61 additions & 12 deletions GraphBLAS/JITpackage/Source/grb_jitpackage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

//------------------------------------------------------------------------------
Expand All @@ -11,6 +11,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>

//------------------------------------------------------------------------------
// zstd.h include file
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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) ;
Expand All @@ -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]) ;
Expand Down Expand Up @@ -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++)
{
Expand All @@ -249,5 +297,6 @@ int main (int argc, char **argv)
fclose (fp) ;
free (Uncompressed_size) ;
free (Compressed_size) ;
return (0) ;
}

10 changes: 7 additions & 3 deletions GraphBLAS/Source/builtin/include/GB_matrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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] ;
Expand All @@ -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] ;
Expand Down
3 changes: 2 additions & 1 deletion GraphBLAS/Source/iterator/GB_Iterator_rc_seek.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
GrB_Info GB_Iterator_rc_seek
(
GxB_Iterator iterator,
GrB_Index j,
GrB_Index j_input,
bool jth_vector
)
{
Expand All @@ -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 ;
Expand Down
27 changes: 14 additions & 13 deletions GraphBLAS/Source/iterator/GxB_Matrix_Iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ;
Expand All @@ -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 ;
Expand All @@ -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 ;
Expand Down

0 comments on commit 30a3d6d

Please sign in to comment.