mkl_graph.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. /*******************************************************************************
  2. * Copyright 2020-2022 Intel Corporation.
  3. *
  4. * This software and the related documents are Intel copyrighted materials, and
  5. * your use of them is governed by the express license under which they were
  6. * provided to you (License). Unless the License provides otherwise, you may not
  7. * use, modify, copy, publish, distribute, disclose or transmit this software or
  8. * the related documents without Intel's prior written permission.
  9. *
  10. * This software and the related documents are provided as is, with no express
  11. * or implied warranties, other than those that are expressly stated in the
  12. * License.
  13. *******************************************************************************/
  14. #ifndef _MKL_GRAPHBLAS_H_
  15. #define _MKL_GRAPHBLAS_H_
  16. #include <stddef.h>
  17. #include <stdint.h>
  18. #include "mkl_types.h"
  19. #define GRAPH_DEPRECATION_MESSAGE "WARNING: Intel oneMKL Graph APIs will be removed in the 2024.0 Beta and Gold releases."
  20. #ifdef __GNUC__
  21. #define MKL_GRAPH_DEPRECATED __attribute__((deprecated(GRAPH_DEPRECATION_MESSAGE)))
  22. #elif defined(_MSC_VER)
  23. #define MKL_GRAPH_DEPRECATED __declspec(deprecated(GRAPH_DEPRECATION_MESSAGE))
  24. #else
  25. #pragma message(GRAPH_DEPRECATION_MESSAGE)
  26. #define MKL_GRAPH_DEPRECATED
  27. #endif
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif /* __cplusplus */
  31. /*
  32. * Contents:
  33. * Objects, part 1: Opaque objects
  34. * Objects, part 2: Structures, enums and non-opaque objects
  35. * Methods, part 1: Creating amd destroying opaque objects
  36. * Methods, part 2: Manipulating objects and getting object properties
  37. * Methods, part 3: Main functionality
  38. */
  39. /******************************************************************************
  40. * Objects, part 1: Opaque objects
  41. ******************************************************************************/
  42. struct mkl_graph_matrix;
  43. typedef struct mkl_graph_matrix *mkl_graph_matrix_t;
  44. struct mkl_graph_vector;
  45. typedef struct mkl_graph_vector *mkl_graph_vector_t;
  46. struct mkl_graph_descriptor;
  47. typedef struct mkl_graph_descriptor *mkl_graph_descriptor_t;
  48. /******************************************************************************
  49. * Objects, part 2: Structures, enums and non-opaque objects
  50. ******************************************************************************/
  51. typedef enum
  52. {
  53. MKL_GRAPH_STATUS_SUCCESS = 0, /* the operation was successful */
  54. MKL_GRAPH_STATUS_NOT_INITIALIZED = 1, /* empty object passed in */
  55. MKL_GRAPH_STATUS_ALLOC_FAILED = 2, /* internal error: memory allocation failed */
  56. MKL_GRAPH_STATUS_INVALID_VALUE = 3, /* invalid input value */
  57. MKL_GRAPH_STATUS_INTERNAL_ERROR = 4, /* internal error */
  58. MKL_GRAPH_STATUS_NOT_SUPPORTED = 5 /* e.g. operation for double precision doesn't support other types */
  59. } mkl_graph_status_t;
  60. typedef enum
  61. {
  62. MKL_GRAPH_SEMIRING_PLUS_TIMES_FP32 = 0, /* standard +.x semiring for single precision */
  63. MKL_GRAPH_SEMIRING_PLUS_TIMES_FP64 = 1, /* standard +.x semiring for double precision */
  64. MKL_GRAPH_SEMIRING_PLUS_TIMES_INT32 = 2, /* standard +.x semiring for 32-bit integers */
  65. MKL_GRAPH_SEMIRING_PLUS_TIMES_INT64 = 3, /* standard +.x semiring for 64-bit integers */
  66. MKL_GRAPH_SEMIRING_PLUS_FIRST_FP32 = 4, /* standard +.x semiring ignoring the values of the second operand for single precision */
  67. MKL_GRAPH_SEMIRING_PLUS_SECOND_FP32 = 5, /* standard +.x semiring ignoring the values of the left operand for single precision */
  68. MKL_GRAPH_SEMIRING_LOR_LAND_BOOL = 6, /* for simple BFS */
  69. MKL_GRAPH_SEMIRING_MIN_PLUS_INT32 = 7, /* */
  70. MKL_GRAPH_SEMIRING_MIN_PLUS_INT64 = 8, /* */
  71. MKL_GRAPH_SEMIRING_MIN_PLUS_FP32 = 9, /* */
  72. MKL_GRAPH_SEMIRING_MIN_PLUS_FP64 = 10, /* */
  73. MKL_GRAPH_SEMIRING_MAX_FIRST_INT32 = 11, /* */
  74. MKL_GRAPH_SEMIRING_MAX_FIRST_INT64 = 12, /* */
  75. MKL_GRAPH_SEMIRING_MAX_FIRST_FP32 = 13, /* */
  76. MKL_GRAPH_SEMIRING_MAX_FIRST_FP64 = 14, /* */
  77. MKL_GRAPH_SEMIRING_ANY_FIRST_FP32 = 15, /* early-exit kernels without values of the second operand */
  78. MKL_GRAPH_SEMIRING_ANY_FIRST_INT32 = 16, /* early-exit kernels without values of the second operand */
  79. MKL_GRAPH_SEMIRING_ANY_SECOND_FP32 = 17, /* early-exit kernels without values of the first operand */
  80. MKL_GRAPH_SEMIRING_ANY_SECOND_FP64 = 18, /* early-exit kernels without values of the first operand */
  81. MKL_GRAPH_SEMIRING_ANY_SECOND_INT32 = 19, /* early-exit kernels without values of the first operand */
  82. MKL_GRAPH_SEMIRING_ANY_SECOND_INT64 = 20, /* early-exit kernels without values of the first operand */
  83. MKL_GRAPH_SEMIRING_ANY_PAIR_BOOL = 21, /* early-exit kernels without any values read */
  84. MKL_GRAPH_SEMIRING_PLUS_PAIR_INT32 = 22, /* */
  85. MKL_GRAPH_SEMIRING_PLUS_PAIR_INT64 = 23, /* */
  86. MKL_GRAPH_SEMIRING_MIN_SECOND_INT32 = 24, /* early-exit kernels without values of the first operand */
  87. MKL_GRAPH_SEMIRING_MIN_SECOND_INT64 = 25, /* early-exit kernels without values of the first operand */
  88. MKL_GRAPH_SEMIRING_MIN_FIRST_INT32 = 26, /* early-exit kernels without values of the second operand */
  89. MKL_GRAPH_SEMIRING_MIN_FIRST_INT64 = 27 /* early-exit kernels without values of the second operand */
  90. } mkl_graph_semiring_t;
  91. typedef enum
  92. {
  93. MKL_GRAPH_ACCUMULATOR_NONE = 0, /* */
  94. MKL_GRAPH_ACCUMULATOR_PLUS = 1, /* */
  95. MKL_GRAPH_ACCUMULATOR_LOR = 2, /* */
  96. MKL_GRAPH_ACCUMULATOR_MIN = 3 /* */
  97. } mkl_graph_accumulator_t;
  98. typedef enum
  99. {
  100. MKL_GRAPH_TYPE_UNSET = -1, /* "no type was set" */
  101. MKL_GRAPH_TYPE_BOOL = 0, /* */
  102. MKL_GRAPH_TYPE_INT32 = 1, /* */
  103. MKL_GRAPH_TYPE_INT64 = 2, /* */
  104. MKL_GRAPH_TYPE_FP32 = 3, /* */
  105. MKL_GRAPH_TYPE_FP64 = 4 /* */
  106. } mkl_graph_type_t;
  107. typedef enum
  108. {
  109. MKL_GRAPH_PROPERTY_NROWS = 0, /* */
  110. MKL_GRAPH_PROPERTY_NCOLS = 1, /* */
  111. MKL_GRAPH_PROPERTY_NNZ = 2, /* */
  112. MKL_GRAPH_PROPERTY_MATRIX_HAS_CSR = 3, /* */
  113. MKL_GRAPH_PROPERTY_MATRIX_HAS_CSC = 4, /* */
  114. MKL_GRAPH_PROPERTY_VECTOR_HAS_DENSE = 5, /* */
  115. MKL_GRAPH_PROPERTY_VECTOR_HAS_SPARSE = 6 /* */
  116. } mkl_graph_property_t;
  117. typedef enum
  118. {
  119. MKL_GRAPH_FIELD_OUTPUT = 0, /* Field for the output modifiers */
  120. MKL_GRAPH_FIELD_FIRST_INPUT = 1, /* Field for the first input modifiers */
  121. MKL_GRAPH_FIELD_SECOND_INPUT = 2, /* Field for the second input modifiers */
  122. MKL_GRAPH_FIELD_MASK = 3 /* Field for mask modifiers */
  123. } mkl_graph_descriptor_field_t;
  124. typedef enum
  125. {
  126. MKL_GRAPH_MOD_NONE = 0, /* */
  127. MKL_GRAPH_MOD_COMPLEMENT = 1, /* */
  128. MKL_GRAPH_MOD_TRANSPOSE = 2, /* */
  129. MKL_GRAPH_MOD_REPLACE = 3, /* */
  130. MKL_GRAPH_MOD_ONLY_STRUCTURE = 4, /* */
  131. MKL_GRAPH_MOD_KEEP_MASK_STRUCTURE = 5 /* */
  132. } mkl_graph_descriptor_field_value_t;
  133. typedef enum
  134. {
  135. MKL_GRAPH_METHOD_AUTO = 0, /* automatic choice */
  136. MKL_GRAPH_METHOD_DOT = 1, /* dot product */
  137. MKL_GRAPH_METHOD_GUSTAVSON = 2, /* Gustavson */
  138. MKL_GRAPH_METHOD_HASH = 3 /* not yet supported */
  139. } mkl_graph_method_t;
  140. typedef enum
  141. {
  142. MKL_GRAPH_REQUEST_COMPUTE_ALL = 0, /* Compute all in a single stage */
  143. MKL_GRAPH_REQUEST_FILL_NNZ = 1, /* First of two stages. Calculate nnz and fill related user-allocated buffer (rowStart or colStart for a matrix) */
  144. MKL_GRAPH_REQUEST_FILL_ENTRIES = 2 /* Second of two stages. Fill user-allocated buffers for indices and values of the entries */
  145. } mkl_graph_request_t;
  146. /******************************************************************************
  147. * Methods, part 1: Creating and destroying opaque graph objects
  148. ******************************************************************************/
  149. /*
  150. [mkl_graph_<name>_create] Allocates the memory for an internal
  151. representation of a graph object and initializes
  152. it to default values.
  153. [mkl_graph_<name>_destroy] Deallocates all internally allocated memory for an
  154. object.
  155. */
  156. /* For matrices */
  157. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_matrix_create (mkl_graph_matrix_t *A_pt);
  158. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_matrix_destroy(mkl_graph_matrix_t *A_pt);
  159. /* For vectors */
  160. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_vector_create (mkl_graph_vector_t *v_pt);
  161. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_vector_destroy(mkl_graph_vector_t *v_pt);
  162. /* For descriptors */
  163. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_descriptor_create (mkl_graph_descriptor_t *desc_pt);
  164. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_descriptor_destroy(mkl_graph_descriptor_t *desc_pt);
  165. /******************************************************************************
  166. * Methods, part 2: Manipulating objects and getting object properties
  167. ******************************************************************************/
  168. /* For matrices */
  169. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_matrix_set_csr(mkl_graph_matrix_t A,
  170. int64_t nrows, int64_t ncols,
  171. void *rows_start, mkl_graph_type_t rows_start_type,
  172. void *col_indx, mkl_graph_type_t col_indx_type,
  173. void *values, mkl_graph_type_t values_type);
  174. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_matrix_get_csr(mkl_graph_matrix_t A,
  175. int64_t *nrows_pt, int64_t *ncols_pt,
  176. void **rows_start_pt, mkl_graph_type_t *rows_start_type_pt,
  177. void **col_indx_pt, mkl_graph_type_t *col_indx_type_pt,
  178. void **values_pt, mkl_graph_type_t *values_type_pt);
  179. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_matrix_set_csc(mkl_graph_matrix_t A,
  180. int64_t nrows, int64_t ncols,
  181. void *cols_start, mkl_graph_type_t cols_start_type,
  182. void *row_indx, mkl_graph_type_t row_indx_type,
  183. void *values, mkl_graph_type_t values_type);
  184. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_matrix_get_csc(mkl_graph_matrix_t A, int64_t *nrows_pt, int64_t *ncols_pt,
  185. void **cols_start_pt, mkl_graph_type_t *cols_start_type_pt,
  186. void **row_indx_pt, mkl_graph_type_t *row_indx_type_pt,
  187. void **values_pt, mkl_graph_type_t *values_type_pt);
  188. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_matrix_get_property(mkl_graph_matrix_t A,
  189. mkl_graph_property_t property,
  190. void *value_pt);
  191. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_optimize_mxv(mkl_graph_vector_t mask, mkl_graph_semiring_t semiring, mkl_graph_matrix_t A,
  192. mkl_graph_vector_t v, mkl_graph_descriptor_t desc, int64_t ncalls);
  193. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_optimize_mxm(mkl_graph_matrix_t Mask, mkl_graph_semiring_t semiring, mkl_graph_matrix_t A,
  194. mkl_graph_matrix_t B, mkl_graph_descriptor_t desc, int64_t ncalls);
  195. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_transpose(mkl_graph_matrix_t C, mkl_graph_matrix_t Mask,
  196. mkl_graph_accumulator_t accum, mkl_graph_matrix_t A,
  197. mkl_graph_descriptor_t desc);
  198. /* For vectors */
  199. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_vector_set_dense(mkl_graph_vector_t v,
  200. int64_t dim, void *values,
  201. mkl_graph_type_t values_type);
  202. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_vector_get_dense(mkl_graph_vector_t v,
  203. int64_t *dim_pt, void **values_pt,
  204. mkl_graph_type_t *values_type_pt);
  205. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_vector_set_sparse (mkl_graph_vector_t v,
  206. int64_t dim, int64_t nnz,
  207. void *indices, mkl_graph_type_t indices_type,
  208. void *values, mkl_graph_type_t values_type);
  209. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_vector_get_sparse (mkl_graph_vector_t v, int64_t *dim_pt, int64_t *nnz_pt,
  210. void **indices_pt, mkl_graph_type_t* indices_type_pt,
  211. void **values_pt, mkl_graph_type_t* values_type_pt);
  212. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_vector_get_property(mkl_graph_vector_t v,
  213. mkl_graph_property_t property,
  214. void *value_pt);
  215. /* For descriptors */
  216. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_descriptor_set_field(mkl_graph_descriptor_t desc,
  217. mkl_graph_descriptor_field_t field,
  218. mkl_graph_descriptor_field_value_t value);
  219. /******************************************************************************
  220. * Methods, part 3: Main functionality
  221. ******************************************************************************/
  222. /* mxm: computes C<M> = accum(C, A +.x B) with A, B and M possibly modified via
  223. * descriptor desc */
  224. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_mxm (mkl_graph_matrix_t C, mkl_graph_matrix_t M,
  225. mkl_graph_accumulator_t accum,
  226. mkl_graph_semiring_t semiring,
  227. mkl_graph_matrix_t A, mkl_graph_matrix_t B,
  228. mkl_graph_descriptor_t desc,
  229. mkl_graph_request_t request,
  230. mkl_graph_method_t method);
  231. /* mxv: computes w<mask> = accum(w, A +.x u) */
  232. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_mxv (mkl_graph_vector_t w, mkl_graph_vector_t mask,
  233. mkl_graph_accumulator_t accum,
  234. mkl_graph_semiring_t semiring,
  235. mkl_graph_matrix_t A, mkl_graph_vector_t u,
  236. mkl_graph_descriptor_t desc,
  237. mkl_graph_request_t request,
  238. mkl_graph_method_t method);
  239. /* vxm: computes w<mask> = accum(w, u +.x A) */
  240. MKL_GRAPH_DEPRECATED mkl_graph_status_t mkl_graph_vxm (mkl_graph_vector_t w, mkl_graph_vector_t mask,
  241. mkl_graph_accumulator_t accum,
  242. mkl_graph_semiring_t semiring,
  243. mkl_graph_vector_t u, mkl_graph_matrix_t A,
  244. mkl_graph_descriptor_t desc,
  245. mkl_graph_request_t request,
  246. mkl_graph_method_t method);
  247. #ifdef __cplusplus
  248. }
  249. #endif /*__cplusplus */
  250. #endif /*_MKL_GRAPHBLAS_H_ */