Skip to content

Commit 89ac878

Browse files
committed
[Code] Add time profiling feature into C API and Python wrapper
1 parent 423abdf commit 89ac878

32 files changed

+402
-150
lines changed

cubool/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ set(CUBOOL_SOURCES
2525
sources/io/logger.cpp
2626
sources/io/logger.hpp
2727
sources/utils/exclusive_scan.hpp
28+
sources/utils/timer.hpp
2829
)
2930

3031
set(CUBOOL_C_API_SOURCES

cubool/include/cubool/cubool.h

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_SetupLogging(
176176
* This function must be called before any other library function is called,
177177
* except first get-info functions.
178178
*
179-
* @note Pass CUBOOL_HINT_RELAXED_FINALIZE for library setup within python.
179+
* @note Pass `CUBOOL_HINT_RELAXED_FINALIZE` for library setup within python.
180180
*
181181
* @param hints Init hints.
182182
*
@@ -190,7 +190,7 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Initialize(
190190
* Finalize library state and all objects, which were created on this library context.
191191
* This function always must be called as the last library function in the application.
192192
*
193-
* @note Pass CUBOOL_HINT_RELAXED_FINALIZE for library init call, if relaxed finalize is required.
193+
* @note Pass `CUBOOL_HINT_RELAXED_FINALIZE` for library init call, if relaxed finalize is required.
194194
* @note Invalidates all handle to the resources, created within this library instance
195195
*
196196
* @return Error code on this operation
@@ -230,8 +230,8 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_New(
230230
* as (rows[i],cols[i]) for pair with i-th index.
231231
*
232232
* @note This function automatically reduces duplicates
233-
* @note Pass CUBOOL_HINT_VALUES_SORTED if values already in the row-col order.
234-
* @note Pass CUBOOL_HINT_NO_DUPLICATES if values has no duplicates
233+
* @note Pass `CUBOOL_HINT_VALUES_SORTED` if values already in the row-col order.
234+
* @note Pass `CUBOOL_HINT_NO_DUPLICATES` if values has no duplicates
235235
*
236236
* @param matrix Matrix handle to perform operation on
237237
* @param rows Array of pairs row indices
@@ -329,13 +329,15 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_ExtractPairs(
329329
*
330330
* @note Provided sub-matrix region must be within the input matrix.
331331
*
332+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
333+
*
332334
* @param result[out] Matrix handle where to store result of the operation
333335
* @param matrix Input matrix to extract values from
334336
* @param i First row id to extract
335337
* @param j First column id to extract
336338
* @param nrows Number of rows to extract
337339
* @param ncols Number of columns to extract
338-
* @param hints Optional hints, pass CUBOOL_HINT_NO
340+
* @param hints Hints for the operation
339341
*
340342
* @return Error code on this operation
341343
*/
@@ -366,14 +368,18 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Duplicate(
366368
* Transpose source matrix and store result of this operation in result matrix.
367369
* Formally: result = matrix ^ T.
368370
*
371+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
372+
*
369373
* @param result[out] Matrix handle to store result of the operation
370374
* @param matrix The source matrix
375+
* @param hints Hints for the operation
371376
*
372377
* @return Error code on this operation
373378
*/
374379
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Transpose(
375380
cuBool_Matrix result,
376-
cuBool_Matrix matrix
381+
cuBool_Matrix matrix,
382+
cuBool_Hints hints
377383
);
378384

379385
/**
@@ -434,14 +440,18 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Free(
434440
* dim(matrix) = M x N
435441
* dim(result) = M x 1
436442
*
443+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
444+
*
437445
* @param result[out] Matrix hnd where to store result
438446
* @param matrix Source matrix to reduce
447+
* @param hints Hints for the operation
439448
*
440449
* @return Error code on this operation
441450
*/
442451
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce(
443452
cuBool_Matrix result,
444-
cuBool_Matrix matrix
453+
cuBool_Matrix matrix,
454+
cuBool_Hints hints
445455
);
446456

447457
/**
@@ -452,16 +462,20 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_Reduce(
452462
* dim(left) = M x N
453463
* dim(right) = M x N
454464
*
465+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
466+
*
455467
* @param result[out] Destination matrix for add-and-assign operation
456468
* @param left Source matrix to be added
457469
* @param right Source matrix to be added
470+
* @param hints Hints for the operation
458471
*
459472
* @return Error code on this operation
460473
*/
461474
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseAdd(
462475
cuBool_Matrix result,
463476
cuBool_Matrix left,
464-
cuBool_Matrix right
477+
cuBool_Matrix right,
478+
cuBool_Hints hints
465479
);
466480

467481
/**
@@ -473,12 +487,13 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Matrix_EWiseAdd(
473487
* dim(right) = T x N
474488
* dim(result) = M x N
475489
*
476-
* @note Pass CUBOOL_HINT_ACCUMULATE hint to add result of the left x right operation.
490+
* @note Pass `CUBOOL_HINT_ACCUMULATE` hint to add result of the left x right operation.
491+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
477492
*
478493
* @param result[out] Matrix handle where to store operation result
479494
* @param left Input left matrix
480495
* @param right Input right matrix
481-
* @param hints Hints for the operation.
496+
* @param hints Hints for the operation
482497
*
483498
* @return Error code on this operation
484499
*/
@@ -497,16 +512,20 @@ CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_MxM(
497512
* dim(right) = K x T
498513
* dim(result) = MK x NT
499514
*
515+
* @note Pass `CUBOOL_HINT_TIME_CHECK` hint to measure operation time
516+
*
500517
* @param result[out] Matrix handle where to store operation result
501518
* @param left Input left matrix
502519
* @param right Input right matrix
520+
* @param hints Hints for the operation
503521
*
504522
* @return Error code on this operation
505523
*/
506524
CUBOOL_EXPORT CUBOOL_API cuBool_Status cuBool_Kronecker(
507525
cuBool_Matrix result,
508526
cuBool_Matrix left,
509-
cuBool_Matrix right
527+
cuBool_Matrix right,
528+
cuBool_Hint hints
510529
);
511530

512531
#endif //CUBOOL_CUBOOL_H

cubool/sources/backend/matrix_base.hpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ namespace cubool {
4040
virtual void setElement(index i, index j) = 0;
4141
virtual void build(const index *rows, const index *cols, size_t nvals, bool isSorted, bool noDuplicates) = 0;
4242
virtual void extract(index* rows, index* cols, size_t &nvals) = 0;
43-
virtual void extractSubMatrix(const MatrixBase& otherBase, index i, index j, index nrows, index ncols) = 0;
43+
virtual void
44+
extractSubMatrix(const MatrixBase &otherBase, index i, index j, index nrows, index ncols, bool checkTime) = 0;
4445

4546
virtual void clone(const MatrixBase& otherBase) = 0;
46-
virtual void transpose(const MatrixBase &otherBase) = 0;
47-
virtual void reduce(const MatrixBase& otherBase) = 0;
47+
virtual void transpose(const MatrixBase &otherBase, bool checkTime) = 0;
48+
virtual void reduce(const MatrixBase &otherBase, bool checkTime) = 0;
4849

49-
virtual void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate) = 0;
50-
virtual void kronecker(const MatrixBase& aBase, const MatrixBase& bBase) = 0;
51-
virtual void eWiseAdd(const MatrixBase& aBase, const MatrixBase& bBase) = 0;
50+
virtual void multiply(const MatrixBase &aBase, const MatrixBase &bBase, bool accumulate, bool checkTime) = 0;
51+
virtual void kronecker(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0;
52+
virtual void eWiseAdd(const MatrixBase &aBase, const MatrixBase &bBase, bool checkTime) = 0;
5253

5354
virtual index getNrows() const = 0;
5455
virtual index getNcols() const = 0;

cubool/sources/core/library.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -228,23 +228,24 @@ namespace cubool {
228228
cuBool_DeviceCaps caps;
229229
queryCapabilities(caps);
230230

231-
std::stringstream ss;
231+
LogStream stream(*getLogger());
232+
stream << Logger::Level::Info;
232233

233234
if (caps.cudaSupported) {
234-
ss << "Cuda device capabilities" << std::endl
235-
<< " name: " << caps.name << std::endl
236-
<< " major: " << caps.major << std::endl
237-
<< " minor: " << caps.minor << std::endl
238-
<< " warp size: " << caps.warp << std::endl
239-
<< " globalMemoryKiBs: " << caps.globalMemoryKiBs << std::endl
240-
<< " sharedMemoryPerMultiProcKiBs: " << caps.sharedMemoryPerMultiProcKiBs << std::endl
241-
<< " sharedMemoryPerBlockKiBs: " << caps.sharedMemoryPerBlockKiBs;
235+
stream << "Cuda device capabilities:"
236+
<< " name: " << caps.name << ","
237+
<< " major: " << caps.major << ","
238+
<< " minor: " << caps.minor << ","
239+
<< " warp size: " << caps.warp << ","
240+
<< " globalMemoryKiBs: " << caps.globalMemoryKiBs << ","
241+
<< " sharedMemoryPerMultiProcKiBs: " << caps.sharedMemoryPerMultiProcKiBs << ","
242+
<< " sharedMemoryPerBlockKiBs: " << caps.sharedMemoryPerBlockKiBs;
242243
}
243244
else {
244-
ss << "Cuda device is not presented";
245+
stream << "Cuda device is not presented";
245246
}
246247

247-
mLogger->logInfo(ss.str());
248+
stream << LogStream::cmt;
248249
}
249250

250251
bool Library::isBackedInitialized() {

0 commit comments

Comments
 (0)