From 025d394e11eac85677f31d394851c3457d915753 Mon Sep 17 00:00:00 2001 From: Will Kimmerer Date: Thu, 26 Oct 2023 02:18:22 -0400 Subject: [PATCH 1/3] separate out cmake setting --- Source/GB_jitifyer.c | 73 +++++++++++++++++++++++++++++++++++++++++--- Source/GB_jitifyer.h | 4 +++ 2 files changed, 72 insertions(+), 5 deletions(-) diff --git a/Source/GB_jitifyer.c b/Source/GB_jitifyer.c index e0e66cf95d..06baa6b44b 100644 --- a/Source/GB_jitifyer.c +++ b/Source/GB_jitifyer.c @@ -55,6 +55,9 @@ static size_t GB_jit_error_log_allocated = 0 ; static char *GB_jit_C_compiler = NULL ; static size_t GB_jit_C_compiler_allocated = 0 ; +static char *GB_jit_CMake = NULL ; +static size_t GB_jit_CMake_allocated = 0 ; + // flags for the C compiler: static char *GB_jit_C_flags = NULL ; static size_t GB_jit_C_flags_allocated = 0 ; @@ -1022,6 +1025,62 @@ GrB_Info GB_jitifyer_set_C_compiler_worker (const char *new_C_compiler) return (GB_jitifyer_alloc_space ( )) ; } +//------------------------------------------------------------------------------ +// GB_jitifyer_get_CMake: return the current CMake executable +//------------------------------------------------------------------------------ + +const char *GB_jitifyer_get_CMake (void) +{ + const char *s ; + #pragma omp critical (GB_jitifyer_worker) + { + s = GB_jit_CMake ; + } + return (s) ; +} + +//------------------------------------------------------------------------------ +// GB_jitifyer_set_CMake: set a new CMake executable +//------------------------------------------------------------------------------ + +GrB_Info GB_jitifyer_set_CMake (const char *new_CMake) +{ + + //-------------------------------------------------------------------------- + // check inputs + //-------------------------------------------------------------------------- + + if (new_CMake == NULL) + { + return (GrB_NULL_POINTER) ; + } + + //-------------------------------------------------------------------------- + // set the CMake executable in a critical section + //-------------------------------------------------------------------------- + + GrB_Info info ; + #pragma omp critical (GB_jitifyer_worker) + { + info = GB_jitifyer_set_CMake_worker (new_CMake) ; + } + return (info) ; +} + +//------------------------------------------------------------------------------ +// GB_jitifyer_set_CMake_worker: set CMake executable in a critical section +//------------------------------------------------------------------------------ + +GrB_Info GB_jitifyer_set_CMake_worker (const char *new_CMake) +{ + // free the old C compiler string + GB_FREE_STUFF (GB_jit_CMake) ; + // allocate the new GB_jit_CMake + GB_COPY_STUFF (GB_jit_CMake, new_CMake) ; + // allocate workspace + return (GB_jitifyer_alloc_space ( )) ; +} + //------------------------------------------------------------------------------ // GB_jitifyer_get_C_flags: return the current C flags //------------------------------------------------------------------------------ @@ -2355,7 +2414,7 @@ void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash) // remove any prior build folder for this kernel, and all its contents snprintf (GB_jit_temp, GB_jit_temp_allocated, - GB_SH_C "cmake -E remove_directory \"" GB_BLD_DIR "\" %s %s %s", + GB_SH_C "%s -E remove_directory \"" GB_BLD_DIR "\" %s %s %s", GB_jit_cache_path, hash, // build path burble_stdout, err_redirect, GB_jit_error_log) ; GB_jitifyer_command (GB_jit_temp) ; // OK: see security comment above @@ -2413,8 +2472,9 @@ void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash) // generate the build system for this kernel snprintf (GB_jit_temp, GB_jit_temp_allocated, - GB_SH_C "cmake -S \"" GB_BLD_DIR "\" -B \"" GB_BLD_DIR "\"" + GB_SH_C "%s -S \"" GB_BLD_DIR "\" -B \"" GB_BLD_DIR "\"" " -DCMAKE_C_COMPILER=\"%s\" %s %s %s", + GB_jit_CMake, GB_jit_cache_path, hash, // -S source path GB_jit_cache_path, hash, // -B build path GB_jit_C_compiler, // C compiler to use @@ -2423,22 +2483,25 @@ void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash) // compile the library for this kernel snprintf (GB_jit_temp, GB_jit_temp_allocated, - GB_SH_C "cmake --build \"" GB_BLD_DIR "\" --config Release %s %s %s", + GB_SH_C "%s --build \"" GB_BLD_DIR "\" --config Release %s %s %s", // can add "--verbose" here too + GB_jit_CMake, GB_jit_cache_path, hash, // build path burble_stdout, err_redirect, GB_jit_error_log) ; GB_jitifyer_command (GB_jit_temp) ; // OK: see security comment above // install the library snprintf (GB_jit_temp, GB_jit_temp_allocated, - GB_SH_C "cmake --install \"" GB_BLD_DIR "\" %s %s %s", + GB_SH_C "%s --install \"" GB_BLD_DIR "\" %s %s %s", + GB_jit_CMake, GB_jit_cache_path, hash, // build path burble_stdout, err_redirect, GB_jit_error_log) ; GB_jitifyer_command (GB_jit_temp) ; // OK: see security comment above // remove the build folder and all its contents snprintf (GB_jit_temp, GB_jit_temp_allocated, - GB_SH_C "cmake -E remove_directory \"" GB_BLD_DIR "\" %s %s %s", + GB_SH_C "%s -E remove_directory \"" GB_BLD_DIR "\" %s %s %s", + GB_jit_CMake, GB_jit_cache_path, hash, // build path burble_stdout, err_redirect, GB_jit_error_log) ; GB_jitifyer_command (GB_jit_temp) ; // OK: see security comment above diff --git a/Source/GB_jitifyer.h b/Source/GB_jitifyer.h index 82da326310..9773c595a7 100644 --- a/Source/GB_jitifyer.h +++ b/Source/GB_jitifyer.h @@ -376,6 +376,10 @@ const char *GB_jitifyer_get_C_compiler (void) ; GrB_Info GB_jitifyer_set_C_compiler (const char *new_C_compiler) ; GrB_Info GB_jitifyer_set_C_compiler_worker (const char *new_C_compiler) ; +const char *GB_jitifyer_get_CMake (void) ; +GrB_Info GB_jitifyer_set_CMake (const char *new_CMake) ; +GrB_Info GB_jitifyer_set_CMake_worker (const char *new_CMake) ; + const char *GB_jitifyer_get_C_flags (void) ; GrB_Info GB_jitifyer_set_C_flags (const char *new_C_flags) ; GrB_Info GB_jitifyer_set_C_flags_worker (const char *new_C_flags) ; From 3c3264ffe94b90676b3b02353b22f4a9a3c4f8af Mon Sep 17 00:00:00 2001 From: Will Kimmerer Date: Wed, 10 Jan 2024 18:04:21 -0500 Subject: [PATCH 2/3] first jit re-commit --- CMakeLists.txt | 5 + Config/GraphBLAS.h.in | 1 + Demo/Program/wildadd.c | 20 ++ Demo/Program/wildtype_demo_obj.c | 474 +++++++++++++++++++++++++++++++ Demo/demo | 2 + GraphBLAS/rename/GB_rename.h | 1 + Include/GraphBLAS.h | 1 + Source/GB_jitifyer.c | 34 ++- Source/GB_jitifyer.h | 9 +- Source/GB_macrofy_binop.c | 12 +- Source/GB_macrofy_decl.c | 57 ++++ Source/GB_macrofy_unop.c | 25 +- Source/GB_macrofy_user_op.c | 41 +-- Source/GB_stringify.h | 9 + Source/GrB_Global_set.c | 5 + 15 files changed, 660 insertions(+), 36 deletions(-) create mode 100644 Demo/Program/wildadd.c create mode 100644 Demo/Program/wildtype_demo_obj.c create mode 100644 Source/GB_macrofy_decl.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ad6e01c173..a6b8c8eb8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -522,6 +522,7 @@ if ( SUITESPARSE_DEMOS ) add_executable ( wathen_demo "Demo/Program/wathen_demo.c" ) add_executable ( context_demo "Demo/Program/context_demo.c" ) add_executable ( gauss_demo "Demo/Program/gauss_demo.c" ) + add_executable ( wildtype_demo_obj "Demo/Program/wildtype_demo_obj.c" ) # Libraries required for Demo programs if ( BUILD_SHARED_LIBS ) @@ -536,6 +537,8 @@ if ( SUITESPARSE_DEMOS ) target_link_libraries ( wathen_demo PUBLIC GraphBLAS ) target_link_libraries ( context_demo PUBLIC GraphBLAS ) target_link_libraries ( gauss_demo PUBLIC GraphBLAS ) + target_link_libraries ( wildtype_demo_obj PUBLIC GraphBLAS ) + else ( ) target_link_libraries ( openmp_demo PUBLIC GraphBLAS_static ) target_link_libraries ( openmp2_demo PUBLIC GraphBLAS_static ) @@ -548,6 +551,7 @@ if ( SUITESPARSE_DEMOS ) target_link_libraries ( wathen_demo PUBLIC GraphBLAS_static ) target_link_libraries ( context_demo PUBLIC GraphBLAS_static ) target_link_libraries ( gauss_demo PUBLIC GraphBLAS_static ) + target_link_libraries ( wildtype_demo_obj PUBLIC GraphBLAS_static) endif ( ) target_link_libraries ( openmp_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) @@ -556,6 +560,7 @@ if ( SUITESPARSE_DEMOS ) target_link_libraries ( kron_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) target_link_libraries ( simple_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) target_link_libraries ( wildtype_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) + target_link_libraries ( wildtype_demo_obj PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) target_link_libraries ( reduce_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) target_link_libraries ( import_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) target_link_libraries ( wathen_demo PUBLIC ${GB_M} ${GB_CUDA} ${GB_RMM} ) diff --git a/Config/GraphBLAS.h.in b/Config/GraphBLAS.h.in index 30a0cecd00..046dfb666e 100644 --- a/Config/GraphBLAS.h.in +++ b/Config/GraphBLAS.h.in @@ -1424,6 +1424,7 @@ typedef enum // for global options or matrix options GxB_JIT_C_CMAKE_LIBS = 7031, // CPU JIT C libraries when using cmake GxB_JIT_USE_CMAKE = 7032, // CPU JIT: use cmake or direct compile GxB_JIT_ERROR_LOG = 7033, // CPU JIT: error log file + GxB_JIT_CMAKE = 7034, // CPU JIT: cmake / location GxB_JIT_CUDA_PREFACE = 7100, // CUDA JIT C++ preface diff --git a/Demo/Program/wildadd.c b/Demo/Program/wildadd.c new file mode 100644 index 0000000000..5bb4d01c3f --- /dev/null +++ b/Demo/Program/wildadd.c @@ -0,0 +1,20 @@ +typedef struct +{ + double stuff [4][4] ; + char whatstuff [64] ; +} +wildtype ; // C version of wildtype + +void wildadd (wildtype *z, wildtype *x, wildtype *y) +{ + for (int i = 0 ; i < 4 ; i++) + { + for (int j = 0 ; j < 4 ; j++) + { + z->stuff [i][j] = x->stuff [i][j] + y->stuff [i][j] ; + } + } + const char *psrc = "this was added" ; + char *pdst = z->whatstuff ; + while ((*pdst++ = *psrc++)) ; +} diff --git a/Demo/Program/wildtype_demo_obj.c b/Demo/Program/wildtype_demo_obj.c new file mode 100644 index 0000000000..29cdbd8f94 --- /dev/null +++ b/Demo/Program/wildtype_demo_obj.c @@ -0,0 +1,474 @@ +//------------------------------------------------------------------------------ +// GraphBLAS/Demo/Program/wildtype_demo: an arbitrary user-defined type +//------------------------------------------------------------------------------ + +// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2023, All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +//------------------------------------------------------------------------------ + +// Each "scalar" entry of this type consists of a 4x4 matrix and a string of +// length 64. + +#include "GraphBLAS.h" + +#if defined __INTEL_COMPILER +#pragma warning (disable: 58 167 144 177 181 186 188 589 593 869 981 1418 1419 1572 1599 2259 2282 2557 2547 3280 ) +#elif defined __GNUC__ +#pragma GCC diagnostic ignored "-Wunused-parameter" +#if defined ( __cplusplus ) +#pragma GCC diagnostic ignored "-Wwrite-strings" +#else +#pragma GCC diagnostic ignored "-Wincompatible-pointer-types" +#endif +#endif + +//------------------------------------------------------------------------------ +// the wildtype +//------------------------------------------------------------------------------ + +typedef struct +{ + double stuff [4][4] ; + char whatstuff [64] ; +} +wildtype ; // C version of wildtype + +// repeat the typedef as a string, to give to GraphBLAS +#define WILDTYPE_DEFN \ +"typedef struct " \ +"{ " \ + "double stuff [4][4] ; " \ + "char whatstuff [64] ; " \ +"} " \ +"wildtype ;" + +GrB_Type WildType ; // GraphBLAS version of wildtype + +//------------------------------------------------------------------------------ +// wildtype_print: print a "scalar" value of wildtype +//------------------------------------------------------------------------------ + +void wildtype_print (const wildtype *x, const char *name) +{ + printf ("\na wildtype scalar: %s [%s]\n", name, x->whatstuff) ; + for (int i = 0 ; i < 4 ; i++) + { + for (int j = 0 ; j < 4 ; j++) + { + printf ("%10.1f ", x->stuff [i][j]) ; + } + printf ("\n") ; + } +} + +//------------------------------------------------------------------------------ +// wildtype_print_matrix: print a matrix of wildtype scalars +//------------------------------------------------------------------------------ + +// This examines each entry of A, which is costly if A is very large. A better +// method would extract all the tuples via GrB_Matrix_extractTuples, and then +// to print those, or to use the GxB_*print methods. This function is just to +// illustrate the GrB_Matrix_extractElement_UDT method. + +void wildtype_print_matrix (GrB_Matrix A, char *name) +{ + printf ("\nPrinting the matrix with GxB_Matrix_fprint:\n") ; + GxB_Matrix_fprint (A, name, GxB_COMPLETE, stdout) ; + GrB_Type type ; + GxB_Matrix_type (&type, A) ; + if (type != WildType) + { + printf ("\nThe matrix %s is not wild enough to print.\n", name) ; + return ; + } + GrB_Index nvals, nrows, ncols ; + GrB_Matrix_nvals (&nvals, A) ; + GrB_Matrix_nrows (&nrows, A) ; + GrB_Matrix_ncols (&ncols, A) ; + printf ("\n============= printing the WildType matrix: %s (%d-by-%d" + " with %d entries)\n", name, (int) nrows, (int) ncols, (int) nvals) ; + for (int i = 0 ; i < (int) nrows ; i++) + { + for (int j = 0 ; j < (int) ncols ; j++) + { + wildtype scalar ; + GrB_Info info = GrB_Matrix_extractElement_UDT (&scalar, A, i, j) ; + if (info == GrB_SUCCESS) + { + printf ("\n----------- %s(%d,%d):\n", name, i, j) ; + wildtype_print (&scalar, "") ; + } + } + } + printf ("\n============= that was the WildType matrix %s\n", name) ; +} + +//------------------------------------------------------------------------------ +// add two wildtype "scalars" +//------------------------------------------------------------------------------ + +// strcpy is not available for use in a GPU kernel, so a while loop is used. + +// void wildadd (wildtype *z, const wildtype *x, const wildtype *y) +// { +// for (int i = 0 ; i < 4 ; i++) +// { +// for (int j = 0 ; j < 4 ; j++) +// { +// z->stuff [i][j] = x->stuff [i][j] + y->stuff [i][j] ; +// } +// } +// const char *psrc = "this was added" ; +// char *pdst = z->whatstuff ; +// while ((*pdst++ = *psrc++)) ; +// } + +// The newlines (\n) in the definition below are optional. They just make +// GxB_print output readable. This example defines wildadd as either a +// macro or as a function. + +// #define WILDADD_DEFN \ +// "void wildadd (wildtype *z, const wildtype *x, const wildtype *y) \n" \ +// "{ \n" \ +// " for (int i = 0 ; i < 4 ; i++) \n" \ +// " { \n" \ +// " for (int j = 0 ; j < 4 ; j++) \n" \ +// " { \n" \ +// " z->stuff [i][j] = x->stuff [i][j] + y->stuff [i][j] ; \n" \ +// " } \n" \ +// " } \n" \ +// " const char *psrc = \"this was added\" ; \n" \ +// " char *pdst = z->whatstuff ; \n" \ +// " while ((*pdst++ = *psrc++)) ; \n" \ +// "}" +// Given in stdin for the demo: +#define WILDADD_DEFN "GB_ISOBJ /Users/raykimm/GraphBLAS/Demo/wildadd.o" + +//------------------------------------------------------------------------------ +// multiply two wildtypes "scalars" +//------------------------------------------------------------------------------ + +void wildmult (wildtype *z, const wildtype *x, const wildtype *y) +{ + for (int i = 0 ; i < 4 ; i++) + { + for (int j = 0 ; j < 4 ; j++) + { + z->stuff [i][j] = 0 ; + for (int k = 0 ; k < 4 ; k++) + { + z->stuff [i][j] += (x->stuff [i][k] * y->stuff [k][j]) ; + } + } + } + const char *psrc = "this was multiplied" ; + char *pdst = z->whatstuff ; + while ((*pdst++ = *psrc++)) ; +} + +#define WILDMULT_DEFN \ +"void wildmult (wildtype *z, const wildtype *x, const wildtype *y) \n" \ +"{ \n" \ +" for (int i = 0 ; i < 4 ; i++) \n" \ +" { \n" \ +" for (int j = 0 ; j < 4 ; j++) \n" \ +" { \n" \ +" z->stuff [i][j] = 0 ; \n" \ +" for (int k = 0 ; k < 4 ; k++) \n" \ +" { \n" \ +" z->stuff [i][j] += (x->stuff [i][k] * y->stuff [k][j]) ;\n" \ +" } \n" \ +" } \n" \ +" } \n" \ +" const char *psrc = \"this was multiplied\" ; \n" \ +" char *pdst = z->whatstuff ; \n" \ +" while ((*pdst++ = *psrc++)) ; \n" \ +"}" + +//------------------------------------------------------------------------------ +// wildtype main program +//------------------------------------------------------------------------------ + +#define LINE \ +"----------------------------------------------------------------------------\n" +#define LINE2 \ +"============================================================================\n" + +int main (void) +{ + + // start GraphBLAS + #if 1 + GrB_init (GrB_NONBLOCKING) ; + #else + GxB_init (GxB_NONBLOCKING_GPU, NULL, NULL, NULL, NULL, NULL) ; + GxB_set (GxB_GPU_ID, 0) ; + GB_Global_hack_set (2, 1) ; // always use the GPU + #endif + + GxB_Global_Option_set (GxB_BURBLE, true) ; + int nthreads ; + GxB_Global_Option_get (GxB_GLOBAL_NTHREADS, &nthreads) ; + fprintf (stderr, "wildtype demo: nthreads %d\n", nthreads) ; + + /* via #defines: + fprintf (stderr, LINE2 "SuiteSparse:GraphBLAS Version %d.%d.%d, %s\n" LINE2 + "%s" LINE "License: %s" LINE "GraphBLAS API Version %d.%d.%d, %s" + " (http://graphblas.org)\n%s" LINE2, GxB_IMPLEMENTATION_MAJOR, + GxB_IMPLEMENTATION_MINOR, GxB_IMPLEMENTATION_SUB, + GxB_IMPLEMENTATION_DATE, GxB_IMPLEMENTATION_ABOUT, + GxB_IMPLEMENTATION_LICENSE, GxB_SPEC_MAJOR, GxB_SPEC_MINOR, + GxB_SPEC_SUB, GxB_SPEC_DATE, GxB_SPEC_ABOUT) ; + */ + + char *library ; GxB_Global_Option_get (GxB_LIBRARY_NAME, &library) ; + int version [3] ; GxB_Global_Option_get (GxB_LIBRARY_VERSION, version) ; + char *date ; GxB_Global_Option_get (GxB_LIBRARY_DATE, &date) ; + char *about ; GxB_Global_Option_get (GxB_LIBRARY_ABOUT, &about) ; + char *url ; GxB_Global_Option_get (GxB_LIBRARY_URL, &url) ; + char *license ; GxB_Global_Option_get (GxB_LIBRARY_LICENSE, &license) ; + char *cdate ; GxB_Global_Option_get (GxB_LIBRARY_COMPILE_DATE, &cdate) ; + char *ctime ; GxB_Global_Option_get (GxB_LIBRARY_COMPILE_TIME, &ctime) ; + int api_ver [3] ; GxB_Global_Option_get (GxB_API_VERSION, api_ver) ; + char *api_date ; GxB_Global_Option_get (GxB_API_DATE, &api_date) ; + char *api_about ; GxB_Global_Option_get (GxB_API_ABOUT, &api_about) ; + char *api_url ; GxB_Global_Option_get (GxB_API_URL, &api_url) ; + + fprintf (stderr, LINE2 "%s Version %d.%d.%d, %s\n" LINE2 "%s" + "(%s)\n" LINE "License:\n%s" LINE "GraphBLAS API Version %d.%d.%d, %s" + " (%s)\n%s" LINE2, + library, version [0], version [1], version [2], date, about, url, + license, api_ver [0], api_ver [1], api_ver [2], api_date, api_url, + api_about) ; + fprintf (stderr, "compiled: %s %s\n", cdate, ctime) ; + + double hyper_switch ; + GxB_Global_Option_get (GxB_HYPER_SWITCH, &hyper_switch) ; + fprintf (stderr, "hyper switch: %g\n", hyper_switch) ; + + GxB_Format_Value format ; + GxB_Global_Option_get (GxB_FORMAT, &format) ; + fprintf (stderr, "format: %s\n", (format == GxB_BY_ROW) ? "CSR" : "CSC") ; + + GrB_Mode mode ; + GxB_Global_Option_get (GxB_MODE, &mode) ; + fprintf (stderr, "mode: %s\n", (mode == GrB_BLOCKING) ? + "blocking" : "non-blocking") ; + + int nthreads_max ; + GxB_Global_Option_get (GxB_GLOBAL_NTHREADS, &nthreads_max) ; + fprintf (stderr, "max # of threads used internally: %d\n", nthreads_max) ; + + // create the WildType + GxB_Type_new (&WildType, sizeof (wildtype), "wildtype", WILDTYPE_DEFN) ; + GxB_Type_fprint (WildType, "WildType", GxB_COMPLETE, stdout) ; + + // get its properties + size_t s ; + GxB_Type_size (&s, WildType) ; + printf ("WildType size: %d\n", (int) s) ; + GxB_Type_fprint (WildType, "WildType", GxB_COMPLETE, stdout) ; + + // create a 10-by-10 WildType matrix, each entry is a 'scalar' WildType + GrB_Matrix A ; + GrB_Matrix_new (&A, WildType, 10, 10) ; + + wildtype scalar1, scalar2 ; + memset (&scalar1, 0, sizeof (wildtype)) ; + memset (&scalar2, 0, sizeof (wildtype)) ; + for (int i = 0 ; i < 4 ; i++) + { + for (int j = 0 ; j < 4 ; j++) + { + scalar1.stuff [i][j] = 100*i + j ; + } + } + strcpy (scalar1.whatstuff, "this is from scalar1") ; + wildtype_print (&scalar1, "scalar1") ; + + // A(2,7) = scalar1 + strcpy (scalar1.whatstuff, "this is A(2,7)") ; + GrB_Matrix_setElement_UDT (A, &scalar1, 2, 7) ; + + // A(3,7) = scalar1 modified + scalar1.stuff [2][3] = 909 ; + strcpy (scalar1.whatstuff, "this is A(3,7)") ; + GrB_Matrix_setElement_UDT (A, &scalar1, 3, 7) ; + + // A(2,4) = scalar1 modified again + scalar1.stuff [3][3] = 42 ; + strcpy (scalar1.whatstuff, "this is A(2,4)") ; + GrB_Matrix_setElement_UDT (A, &scalar1, 2, 4) ; + + // C = A' + GrB_Matrix C ; + GrB_Matrix_new (&C, WildType, 10, 10) ; + GrB_transpose (C, NULL, NULL, A, NULL) ; + + // scalar2 = C(7,2) + GrB_Info info = GrB_Matrix_extractElement_UDT (&scalar2, C, 7, 2) ; + if (info == GrB_SUCCESS) + { + wildtype_print (&scalar2, "got scalar2 = C(7,2)") ; + } + strcpy (scalar2.whatstuff, "here is scalar2") ; + + // char *lineptr = NULL; + // size_t n = 0; + // getline(&lineptr, &n, stdin) ; + // if (lineptr == NULL || n == 0) + // { + // printf ("\nInvalid Input String\n") ; + // } + // create the WildAdd operator + GrB_BinaryOp WildAdd ; + GxB_BinaryOp_new (&WildAdd, + NULL, WildType, WildType, WildType, + "wildadd", WILDADD_DEFN) ; + GxB_BinaryOp_fprint (WildAdd, "WildAdd", GxB_COMPLETE, stdout) ; + + // create the WildMult operator + GrB_BinaryOp WildMult ; + GxB_BinaryOp_new (&WildMult, + (GxB_binary_function) wildmult, WildType, WildType, WildType, + "wildmult", WILDMULT_DEFN) ; + GxB_BinaryOp_fprint (WildMult, "WildMult", GxB_COMPLETE, stdout) ; + + // create a matrix B with B (7,2) = scalar2 + GrB_Matrix B ; + GrB_Matrix_new (&B, WildType, 10, 10) ; + for (int i = 0 ; i < 4 ; i++) + { + for (int j = 0 ; j < 4 ; j++) + { + scalar2.stuff [i][j] = (double) (j - i) + 0.5 ; + } + } + wildtype_print (&scalar2, "scalar2") ; + + // B(7,2) = scalar2 + strcpy (scalar2.whatstuff, "this is B(7,2)") ; + GrB_Matrix_setElement_UDT (B, &scalar2, 7, 2) ; + + // B(7,5) = scalar2 modified + scalar2.stuff [0][0] = -1 ; + strcpy (scalar2.whatstuff, "here is B(7,5)") ; + GrB_Matrix_setElement_UDT (B, &scalar2, 7, 5) ; + + // B(4,2) = scalar2 changed + scalar2.stuff [0][3] = 77 ; + strcpy (scalar2.whatstuff, "finally, B(4,2)") ; + GrB_Matrix_setElement_UDT (B, &scalar2, 4, 2) ; + + // create the WildAdder monoid + GrB_Monoid WildAdder ; + wildtype scalar_identity ; + memset (&scalar_identity, 0, sizeof (wildtype)) ; + for (int i = 0 ; i < 4 ; i++) + { + for (int j = 0 ; j < 4 ; j++) + { + scalar_identity.stuff [i][j] = 0 ; + } + } + strcpy (scalar_identity.whatstuff, "identity") ; + wildtype_print (&scalar_identity, "scalar_identity for the monoid") ; + GrB_Monoid_new_UDT (&WildAdder, WildAdd, &scalar_identity) ; + + // create and print the InTheWild semiring + GrB_Semiring InTheWild ; + GrB_Semiring_new (&InTheWild, WildAdder, WildMult) ; + GxB_Semiring_fprint (InTheWild, "InTheWild", GxB_COMPLETE, stdout) ; + + printf ("\nmultiplication C=A*B InTheWild semiring:\n") ; + + wildtype_print_matrix (A, "input A") ; + wildtype_print_matrix (B, "input B") ; + + // C = A*B + // Since there is no accum operator, this overwrites C with A*B; the old + // content of C is gone. + GrB_mxm (C, NULL, NULL, InTheWild, A, B, NULL) ; + wildtype_print_matrix (C, "output C") ; + + // C = C*C' + printf ("\n------ C=C*C'----------------------------------------\n") ; + GrB_Matrix M ; + GrB_Matrix_new (&M, GrB_BOOL, 10, 10) ; + GrB_Matrix_setElement_BOOL (M, true, 2, 2) ; + GrB_Matrix_setElement_BOOL (M, true, 2, 3) ; + GrB_Matrix_setElement_BOOL (M, true, 3, 2) ; + GrB_Matrix_setElement_BOOL (M, true, 3, 3) ; + printf ("\nThe mask matrix M:\n") ; + GxB_Matrix_fprint (M, "M", GxB_COMPLETE, stdout) ; + +// GxB_Global_Option_set (GxB_BURBLE, true) ; + GrB_mxm (C, M, NULL, InTheWild, C, C, GrB_DESC_RST1) ; + wildtype_print_matrix (C, "output C") ; + + // reduce C to a scalar using the WildAdder monoid + wildtype sum ; + memset (&sum, 0, sizeof (wildtype)) ; + GrB_Matrix_reduce_UDT (&sum, NULL, WildAdder, C, NULL) ; + wildtype_print (&sum, "sum (first time)") ; + + // again, to test the JIT lookup + memset (&sum, 0, sizeof (wildtype)) ; + GrB_Matrix_reduce_UDT (&sum, NULL, WildAdder, C, NULL) ; + wildtype_print (&sum, "sum (again)") ; +// GxB_Global_Option_set (GxB_BURBLE, false) ; + +// for (int k = 0 ; k < 100 ; k++) +// { +// GrB_Matrix_reduce_UDT (&sum, NULL, WildAdder, C, NULL) ; +// } + + // set C to column-oriented format + GxB_Matrix_Option_set (C, GxB_FORMAT, GxB_BY_COL) ; + printf ("\nC is now stored by column, but it looks just the same to the\n" + "GraphBLAS user application. The difference is opaque, in the\n" + "internal data structure.\n") ; + wildtype_print_matrix (C, "output C") ; + + // create a non-wild matrix D and try to print it + GrB_Matrix D ; + GrB_Matrix_new (&D, GrB_FP32, 10, 10) ; + wildtype_print_matrix (D, "D") ; + + // apply some positional operators + GrB_Matrix E ; + GrB_Matrix_new (&E, GrB_INT64, 10, 10) ; + + GrB_Matrix_apply (E, NULL, NULL, GxB_POSITIONI_INT64, A, NULL) ; + GxB_Matrix_fprint (E, "E (positional i)", GxB_COMPLETE, NULL) ; + + GrB_Matrix_apply (E, NULL, NULL, GxB_POSITIONJ_INT64, A, NULL) ; + GxB_Matrix_fprint (E, "E (positional j)", GxB_COMPLETE, NULL) ; + + // do something invalid + info = GrB_Matrix_eWiseAdd_BinaryOp (C, NULL, NULL, WildAdd, A, D, NULL) ; + if (info != GrB_SUCCESS) + { + const char *s ; + GrB_Matrix_error (&s, C) ; + printf ("\nThis is supposed to fail, as a demo of GrB_error:\n%s\n", s); + } + + // free everyting + GrB_Matrix_free (&C) ; + GrB_Matrix_free (&A) ; + GrB_Matrix_free (&B) ; + GrB_Matrix_free (&D) ; + GrB_Matrix_free (&E) ; + GrB_Matrix_free (&M) ; + GrB_Semiring_free (&InTheWild) ; + GrB_Monoid_free (&WildAdder) ; + GrB_BinaryOp_free (&WildAdd) ; + GrB_BinaryOp_free (&WildMult) ; + GrB_Type_free (&WildType) ; + // free (lineptr) ; + + GrB_finalize ( ) ; +} + diff --git a/Demo/demo b/Demo/demo index db8d2fa7aa..3c9aa37cab 100755 --- a/Demo/demo +++ b/Demo/demo @@ -10,6 +10,8 @@ ../build/import_demo < Matrix/west0067 > ../build/import_demo.out ../build/wildtype_demo > ../build/wildtype_demo.out +cc -c Program/wildadd.c +../build/wildtype_demo_obj > ../build/wildtype_demo_obj.out ../build/gauss_demo > ../build/gauss_demo1.out ../build/gauss_demo > ../build/gauss_demo.out diff --git a/GraphBLAS/rename/GB_rename.h b/GraphBLAS/rename/GB_rename.h index d3362f4ee5..213d325db1 100644 --- a/GraphBLAS/rename/GB_rename.h +++ b/GraphBLAS/rename/GB_rename.h @@ -902,6 +902,7 @@ #define GB_macrofy_cast_input GM_macrofy_cast_input #define GB_macrofy_cast_output GM_macrofy_cast_output #define GB_macrofy_defn GM_macrofy_defn +#define GB_macrofy_decl GM_macrofy_decl #define GB_macrofy_ewise GM_macrofy_ewise #define GB_macrofy_family GM_macrofy_family #define GB_macrofy_id GM_macrofy_id diff --git a/Include/GraphBLAS.h b/Include/GraphBLAS.h index 6db995b69e..e434ecb2ab 100644 --- a/Include/GraphBLAS.h +++ b/Include/GraphBLAS.h @@ -1424,6 +1424,7 @@ typedef enum // for global options or matrix options GxB_JIT_C_CMAKE_LIBS = 7031, // CPU JIT C libraries when using cmake GxB_JIT_USE_CMAKE = 7032, // CPU JIT: use cmake or direct compile GxB_JIT_ERROR_LOG = 7033, // CPU JIT: error log file + GxB_JIT_CMAKE = 7034, // CPU JIT: cmake command / path GxB_JIT_CUDA_PREFACE = 7100, // CUDA JIT C++ preface diff --git a/Source/GB_jitifyer.c b/Source/GB_jitifyer.c index 06baa6b44b..5383f72ccc 100644 --- a/Source/GB_jitifyer.c +++ b/Source/GB_jitifyer.c @@ -56,7 +56,7 @@ static char *GB_jit_C_compiler = NULL ; static size_t GB_jit_C_compiler_allocated = 0 ; static char *GB_jit_CMake = NULL ; -static size_t GB_jit_CMake_allocated = 0 ; +static size_t GB_jit_CMake_allocated = 0 ; // flags for the C compiler: static char *GB_jit_C_flags = NULL ; @@ -362,6 +362,7 @@ GrB_Info GB_jitifyer_init (void) GB_COPY_STUFF (GB_jit_C_cmake_libs, GB_CMAKE_LIBRARIES) ; GB_COPY_STUFF (GB_jit_C_preface, "") ; GB_COPY_STUFF (GB_jit_CUDA_preface, "") ; + GB_COPY_STUFF (GB_jit_CMake, "cmake") ; OK (GB_jitifyer_alloc_space ( )) ; //-------------------------------------------------------------------------- @@ -1919,6 +1920,7 @@ GrB_Info GB_jitifyer_load_worker GB_jit_cache_path, bucket, GB_LIB_PREFIX, kernel_name, GB_LIB_SUFFIX) ; void *dl_handle = GB_file_dlopen (GB_jit_temp) ; GB_jit_kcode kcode = encoding->kcode ; + char *object_paths [3] ; //-------------------------------------------------------------------------- // check if the kernel was found, but needs to be compiled anyway @@ -1976,6 +1978,13 @@ GrB_Info GB_jitifyer_load_worker snprintf (GB_jit_temp, GB_jit_temp_allocated, "%s/c/%02x/%s.%s", GB_jit_cache_path, bucket, kernel_name, kernel_filetype) ; FILE *fp = fopen (GB_jit_temp, "w") ; + object_paths [0] = (op != NULL && op->defn != NULL && (GB_STRNCMP(op->defn, GB_jit_isobj_symbol) == 0)) ? + op->defn + strlen(GB_jit_isobj_symbol) : "" ; + object_paths [1] = (op1 != NULL && op1->defn != NULL && op1 != op && (GB_STRNCMP(op1->defn, GB_jit_isobj_symbol) == 0)) ? + op1->defn + strlen(GB_jit_isobj_symbol) : "" ; + object_paths [2] = (op2 != NULL && op2->defn != NULL && op2 != op1 && op2 != op && (GB_STRNCMP(op2->defn, GB_jit_isobj_symbol) == 0)) ? + op2->defn + strlen(GB_jit_isobj_symbol) : "" ; + if (fp != NULL) { // create the preface @@ -1999,7 +2008,6 @@ GrB_Info GB_jitifyer_load_worker type3, hash, kcode) ; fclose (fp) ; } - // if the source file was not created above, the compilation will // gracefully fail. @@ -2012,12 +2020,12 @@ GrB_Info GB_jitifyer_load_worker else if (GB_jit_use_cmake) { // use cmake to compile the CPU kernel - GB_jitifyer_cmake_compile (kernel_name, hash) ; + GB_jitifyer_cmake_compile (kernel_name, hash, object_paths) ; } else { // use the compiler to directly compile the CPU kernel - GB_jitifyer_direct_compile (kernel_name, bucket) ; + GB_jitifyer_direct_compile (kernel_name, bucket, object_paths) ; } // load the kernel from the lib*.so file @@ -2396,7 +2404,7 @@ static void GB_jitifyer_command (char *command) #define GB_BLD_DIR "%s/tmp/%016" PRIx64 -void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash) +void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash, char **object_paths) { #ifndef NJIT @@ -2448,12 +2456,15 @@ void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash) "add_library ( %s SHARED \"%s/c/%02x/%s.c\" )\n", kernel_name, // target name for add_library command GB_jit_cache_path, bucket, kernel_name) ; // source file for add_library - if (GB_STRLEN (GB_jit_C_cmake_libs) > 0) + if (GB_STRLEN (GB_jit_C_cmake_libs) > 0 || GB_STRLEN (object_paths[0]) > 0 || GB_STRLEN (object_paths[1]) > 0 || GB_STRLEN (object_paths[2]) > 0) { fprintf (fp, - "target_link_libraries ( %s PUBLIC %s )\n", + "target_link_libraries ( %s PUBLIC %s%s%s%s )\n", kernel_name, // target name of the library - GB_jit_C_cmake_libs) ; // libraries to link against + GB_jit_C_cmake_libs, + object_paths[0], + object_paths[1], + object_paths[2]) ; // libraries and/or object files to link against } fprintf (fp, @@ -2611,7 +2622,7 @@ void GB_jitifyer_nvcc_compile (char *kernel_name, uint32_t bucket) // FUTURE: get this method to work in MSVC, since it's much faster than using // cmake on Windows. -void GB_jitifyer_direct_compile (char *kernel_name, uint32_t bucket) +void GB_jitifyer_direct_compile (char *kernel_name, uint32_t bucket, char **object_paths) { #ifndef NJIT @@ -2638,7 +2649,7 @@ void GB_jitifyer_direct_compile (char *kernel_name, uint32_t bucket) "%s " // C flags "%s " // C link flags "-o %s/lib/%02x/%s%s%s " // lib*.so output file - "%s/c/%02x/%s%s " // *.o input file + "%s/c/%02x/%s%s%s%s%s " // *.o input file "%s " // libraries to link with "%s " // burble stdout "%s %s\"", // error log file @@ -2659,7 +2670,8 @@ void GB_jitifyer_direct_compile (char *kernel_name, uint32_t bucket) GB_jit_C_link_flags, // C link flags GB_jit_cache_path, bucket, GB_LIB_PREFIX, kernel_name, GB_LIB_SUFFIX, // lib*.so file - GB_jit_cache_path, bucket, kernel_name, GB_OBJ_SUFFIX, // *.o input file + GB_jit_cache_path, bucket, kernel_name, GB_OBJ_SUFFIX, // *.o input file, + object_paths[0], object_paths[1], object_paths[2], // possible object file paths GB_jit_C_libraries, // libraries to link with burble_stdout, // burble stdout err_redirect, GB_jit_error_log) ; // error log file diff --git a/Source/GB_jitifyer.h b/Source/GB_jitifyer.h index 9773c595a7..1b164fd33a 100644 --- a/Source/GB_jitifyer.h +++ b/Source/GB_jitifyer.h @@ -10,7 +10,11 @@ #ifndef GB_JITIFYER_H #define GB_JITIFYER_H + #include "GB_jit_kernel_proto.h" +#include "GB_config.h" + +static const char GB_jit_isobj_symbol[] = "GB_ISOBJ"; //------------------------------------------------------------------------------ // get list of PreJIT kernels: function pointers and names @@ -347,8 +351,9 @@ bool GB_jitifyer_query GrB_Type type3 ) ; -void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash) ; -void GB_jitifyer_direct_compile (char *kernel_name, uint32_t bucket) ; +// Raye: I'm not yet sure if nvcc will do LTO easily. So I will leave off object_paths for now. +void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash, char **object_paths) ; +void GB_jitifyer_direct_compile (char *kernel_name, uint32_t bucket, char **object_paths) ; void GB_jitifyer_nvcc_compile (char *kernel_name, uint32_t bucket) ; GrB_Info GB_jitifyer_init (void) ; // initialize the JIT diff --git a/Source/GB_macrofy_binop.c b/Source/GB_macrofy_binop.c index 08cb51d91a..d21dcf4f3c 100644 --- a/Source/GB_macrofy_binop.c +++ b/Source/GB_macrofy_binop.c @@ -11,6 +11,8 @@ #include "GB_math.h" #include "GB_stringify.h" #include +#include "GB_config.h" +#include "GB_jitifyer.h" void GB_macrofy_binop ( @@ -64,7 +66,15 @@ void GB_macrofy_binop //---------------------------------------------------------------------- ASSERT (op != NULL) ; - GB_macrofy_defn (fp, 3, op->name, op->defn) ; + if (op->defn != NULL && GB_STRNCMP(op->defn, GB_jit_isobj_symbol) == 0) + { + GB_macrofy_decl (fp, 3, (GB_Operator) op) ; + } + else + { + GB_macrofy_defn (fp, 3, op->name, op->defn) ; + } + if (is_monoid_or_build) { diff --git a/Source/GB_macrofy_decl.c b/Source/GB_macrofy_decl.c new file mode 100644 index 0000000000..d1dac825e7 --- /dev/null +++ b/Source/GB_macrofy_decl.c @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +// GB_macrofy_decl: construct defn for an operator +//------------------------------------------------------------------------------ + +// SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2023, All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +//------------------------------------------------------------------------------ + +#include "GB.h" +#include "GB_stringify.h" +#include "GB_opaque.h" + +void GB_macrofy_decl // construct a decl for an operator +( + FILE *fp, + int kind, // 0: built-in function + // 3: user-defined function + GB_Operator op +) +{ + if (op->name != NULL && op->defn != NULL) + { + // construct the guard to prevent duplicate definitions + fprintf (fp, + "#ifndef GB_GUARD_%s_DEFINED\n" + "#define GB_GUARD_%s_DEFINED\n", + op->name, op->name) ; + if (op->opcode == GB_USER_unop_code) // user-defined GrB_UnaryOp + { + fprintf (fp, + "extern void %s (%s *z, %s *x) ;\n", + op->name, op->ztype->name, op->xtype->name) ; + } + else if (op->opcode == GB_USER_idxunop_code) // user-defined GrB_IndexUnaryOp + { + fprintf (fp, + "extern void %s (%s *z, %s *x, int64_t i, int64_t j, %s *thunk) ;\n", + op->name, op->ztype->name, op->xtype->name, op->ytype->name) ; + } + else if (op->opcode == GB_USER_binop_code) + { + fprintf (fp, + "extern void %s (%s *z, %s *x, %s *y) ;\n", + op->name, op->ztype->name, op->xtype->name, op->ytype->name) ; + } + + if (kind == 3) + { + // define the user-defined function as a string + GB_macrofy_string (fp, op->name, op->defn) ; + } + // end the guard + fprintf (fp, "#endif\n") ; + } +} + diff --git a/Source/GB_macrofy_unop.c b/Source/GB_macrofy_unop.c index 2c8658c627..835e7ce28b 100644 --- a/Source/GB_macrofy_unop.c +++ b/Source/GB_macrofy_unop.c @@ -19,6 +19,8 @@ #include "GB_math.h" #include "GB_stringify.h" #include +#include "GB_config.h" +#include "GB_jitifyer.h" void GB_macrofy_unop ( @@ -30,10 +32,10 @@ void GB_macrofy_unop GB_Operator op // GrB_UnaryOp or GrB_IndexUnaryOp ) { - + bool justdecl ; const char *f = "" ; const char *ij = (flipij) ? "j,i" : "i,j" ; - + justdecl = !(op->defn != NULL ? GB_STRNCMP(op->defn, GB_jit_isobj_symbol) : true) ; if (ecode == 0) { @@ -42,20 +44,33 @@ void GB_macrofy_unop //---------------------------------------------------------------------- ASSERT (op != NULL) ; - GB_macrofy_defn (fp, 3, op->name, op->defn) ; + if (justdecl) + { + GB_macrofy_decl (fp, 3, op) ; + } + else + { + GB_macrofy_defn (fp, 3, op->name, op->defn) ; + } fprintf (fp, "#define %s(z,x,%s,y) %s (&(z), &(x))\n", macro_name, ij, op->name) ; } else if (ecode == 254) { - //---------------------------------------------------------------------- // user-defined GrB_IndexUnaryOp //---------------------------------------------------------------------- ASSERT (op != NULL) ; - GB_macrofy_defn (fp, 3, op->name, op->defn) ; + if (justdecl) + { + GB_macrofy_decl (fp, 3, op) ; + } + else + { + GB_macrofy_defn (fp, 3, op->name, op->defn) ; + } fprintf (fp, "#define %s(z,x,%s,y) %s (&(z), &(x), i, j, &(y))\n", macro_name, ij, op->name) ; diff --git a/Source/GB_macrofy_user_op.c b/Source/GB_macrofy_user_op.c index b3038e0b8f..4a3d0bd6db 100644 --- a/Source/GB_macrofy_user_op.c +++ b/Source/GB_macrofy_user_op.c @@ -9,6 +9,8 @@ #include "GB.h" #include "GB_stringify.h" +#include "GB_config.h" +#include "GB_jitifyer.h" void GB_macrofy_user_op // construct a user-defined operator ( @@ -33,8 +35,6 @@ void GB_macrofy_user_op // construct a user-defined operator // construct the name //-------------------------------------------------------------------------- - fprintf (fp, "#define GB_USER_OP_FUNCTION %s\n", op->name) ; - //-------------------------------------------------------------------------- // construct the typedefs //-------------------------------------------------------------------------- @@ -45,24 +45,31 @@ void GB_macrofy_user_op // construct a user-defined operator //-------------------------------------------------------------------------- // construct the function prototype //-------------------------------------------------------------------------- - - for (char *p = op->defn ; *p ; p++) + if (op->defn != NULL && GB_STRNCMP(op->defn, GB_jit_isobj_symbol) == 0) { - int c = (int) (*p) ; - if (c == '{') - { - fprintf (fp, ";\n") ; - break ; - } - fputc (c, fp) ; + fprintf(stderr, "We made it here!: %i\n %s vs. %s\n", GB_STRNCMP(op->defn, GB_jit_isobj_symbol), op->defn, GB_jit_isobj_symbol) ; + GB_macrofy_decl(fp, 3, op) ; } + else + { + for (char *p = op->defn ; *p ; p++) + { + int c = (int) (*p) ; + if (c == '{') + { + fprintf (fp, ";\n") ; + break ; + } + fputc (c, fp) ; + } - //-------------------------------------------------------------------------- - // construct the user function itself - //-------------------------------------------------------------------------- - - fprintf (fp, "\n%s\n", op->defn) ; - GB_macrofy_string (fp, op->name, op->defn) ; + //---------------------------------------------------------------------- + // construct the user function itself + //---------------------------------------------------------------------- + fprintf (fp, "\n%s\n", op->defn) ; + GB_macrofy_string (fp, op->name, op->defn) ; + } fprintf (fp, "#define GB_USER_OP_DEFN GB_%s_USER_DEFN\n", op->name) ; + fprintf (fp, "#define GB_USER_OP_FUNCTION %s\n", op->name) ; } diff --git a/Source/GB_stringify.h b/Source/GB_stringify.h index 630fcac01b..bfc7a57c56 100644 --- a/Source/GB_stringify.h +++ b/Source/GB_stringify.h @@ -34,6 +34,7 @@ void GB_macrofy_preface #define GB_LSHIFT(x,k) (((uint64_t) x) << k) #define GB_RSHIFT(x,k,b) ((x >> k) & ((((uint64_t)0x00000001) << b) -1)) +#define GB_STRNCMP(s1, s2) strncmp(s1, s2, strlen(s2)-1) //------------------------------------------------------------------------------ // GB_macrofy_name: create the kernel name //------------------------------------------------------------------------------ @@ -729,6 +730,14 @@ void GB_macrofy_defn // construct a defn for an operator const char *defn ) ; +void GB_macrofy_decl // construct a decl for an operator +( + FILE *fp, + int kind, // 0: built-in function + // 3: user-defined function + GB_Operator op +) ; + void GB_macrofy_string ( FILE *fp, diff --git a/Source/GrB_Global_set.c b/Source/GrB_Global_set.c index 80c659333a..f635c4ff2e 100644 --- a/Source/GrB_Global_set.c +++ b/Source/GrB_Global_set.c @@ -229,6 +229,11 @@ GrB_Info GrB_Global_set_String info = GB_jitifyer_set_cache_path (value) ; break ; + + case GxB_JIT_CMAKE : + + return (GB_jitifyer_set_CMake (value)) ; + break ; default : From 4fd0da0cd6255cd6c7b94f395d91b190d88181eb Mon Sep 17 00:00:00 2001 From: Raye Kimmerer Date: Mon, 20 May 2024 13:41:27 -0400 Subject: [PATCH 3/3] Missed commits fixing rebase --- Demo/Program/wildtype_demo_obj.c | 2 +- Demo/README.txt | 1 + Include/GraphBLAS.h | 4 ++-- Source/GB_jitifyer.c | 2 +- Source/GB_macrofy_user_op.c | 1 - Source/GrB_Global_set.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Demo/Program/wildtype_demo_obj.c b/Demo/Program/wildtype_demo_obj.c index 29cdbd8f94..768f7bcc08 100644 --- a/Demo/Program/wildtype_demo_obj.c +++ b/Demo/Program/wildtype_demo_obj.c @@ -210,7 +210,7 @@ int main (void) GxB_Global_Option_set (GxB_BURBLE, true) ; int nthreads ; GxB_Global_Option_get (GxB_GLOBAL_NTHREADS, &nthreads) ; - fprintf (stderr, "wildtype demo: nthreads %d\n", nthreads) ; + fprintf (stderr, "wildtype_obj demo: nthreads %d\n", nthreads) ; /* via #defines: fprintf (stderr, LINE2 "SuiteSparse:GraphBLAS Version %d.%d.%d, %s\n" LINE2 diff --git a/Demo/README.txt b/Demo/README.txt index 0fbd48ed8a..87b237d7d2 100644 --- a/Demo/README.txt +++ b/Demo/README.txt @@ -29,6 +29,7 @@ in Demo/Program: kron_demo.c demo program to test GrB_kronecker simple_demo.c demo program to test simple_rand wildtype_demo.c demo program, arbitrary struct as user-defined type + wildtype_demo_obj.c demo program, same as wildtype_demo using obj files openmp_demo.c demo program using OpenMP -------------------------------------------------------------------------------- diff --git a/Include/GraphBLAS.h b/Include/GraphBLAS.h index e434ecb2ab..e94e5f0543 100644 --- a/Include/GraphBLAS.h +++ b/Include/GraphBLAS.h @@ -158,7 +158,7 @@ extern "C" //------------------------------------------------------------------------------ #ifndef GRAPHBLAS_HAS_CUDA -#define GRAPHBLAS_HAS_CUDA +/* #undef GRAPHBLAS_HAS_CUDA */ #endif //------------------------------------------------------------------------------ @@ -1424,7 +1424,7 @@ typedef enum // for global options or matrix options GxB_JIT_C_CMAKE_LIBS = 7031, // CPU JIT C libraries when using cmake GxB_JIT_USE_CMAKE = 7032, // CPU JIT: use cmake or direct compile GxB_JIT_ERROR_LOG = 7033, // CPU JIT: error log file - GxB_JIT_CMAKE = 7034, // CPU JIT: cmake command / path + GxB_JIT_CMAKE = 7034, // CPU JIT: cmake / location GxB_JIT_CUDA_PREFACE = 7100, // CUDA JIT C++ preface diff --git a/Source/GB_jitifyer.c b/Source/GB_jitifyer.c index 5383f72ccc..adb1c3f085 100644 --- a/Source/GB_jitifyer.c +++ b/Source/GB_jitifyer.c @@ -2423,7 +2423,7 @@ void GB_jitifyer_cmake_compile (char *kernel_name, uint64_t hash, char **object_ // remove any prior build folder for this kernel, and all its contents snprintf (GB_jit_temp, GB_jit_temp_allocated, GB_SH_C "%s -E remove_directory \"" GB_BLD_DIR "\" %s %s %s", - GB_jit_cache_path, hash, // build path + GB_jit_CMake, GB_jit_cache_path, hash, // build path burble_stdout, err_redirect, GB_jit_error_log) ; GB_jitifyer_command (GB_jit_temp) ; // OK: see security comment above diff --git a/Source/GB_macrofy_user_op.c b/Source/GB_macrofy_user_op.c index 4a3d0bd6db..9adb4b41a4 100644 --- a/Source/GB_macrofy_user_op.c +++ b/Source/GB_macrofy_user_op.c @@ -47,7 +47,6 @@ void GB_macrofy_user_op // construct a user-defined operator //-------------------------------------------------------------------------- if (op->defn != NULL && GB_STRNCMP(op->defn, GB_jit_isobj_symbol) == 0) { - fprintf(stderr, "We made it here!: %i\n %s vs. %s\n", GB_STRNCMP(op->defn, GB_jit_isobj_symbol), op->defn, GB_jit_isobj_symbol) ; GB_macrofy_decl(fp, 3, op) ; } else diff --git a/Source/GrB_Global_set.c b/Source/GrB_Global_set.c index f635c4ff2e..30fc24c60b 100644 --- a/Source/GrB_Global_set.c +++ b/Source/GrB_Global_set.c @@ -232,7 +232,7 @@ GrB_Info GrB_Global_set_String case GxB_JIT_CMAKE : - return (GB_jitifyer_set_CMake (value)) ; + info = GB_jitifyer_set_CMake (value) ; break ; default :