Skip to content

Commit 85401cd

Browse files
committed
[Code] Proxy matrix tmp matrix-leak fixes:
- Fix tmp matrix lost release call in commitCache() method of core matrix class - Minor fixes in cmake version - Update py package
1 parent 7a5a5d8 commit 85401cd

File tree

12 files changed

+56
-50
lines changed

12 files changed

+56
-50
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CuBool library Cmake config file
22
# Add this file as sub-directory to your project to use library functionality
33

4-
cmake_minimum_required(VERSION 3.17 FATAL_ERROR)
4+
cmake_minimum_required(VERSION 3.15 FATAL_ERROR)
55
project(cubool LANGUAGES CXX)
66

77
# Exposed to the user build options

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ These steps are required if you want to build library for your specific platform
7878
### Requirements
7979

8080
- Linux Ubuntu (tested on 20.04)
81-
- CMake Version 3.17 or higher
81+
- CMake Version 3.15 or higher
8282
- CUDA Compatible GPU device
8383
- GCC Compiler
8484
- NVIDIA CUDA toolkit

cubool/CMakeLists.txt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ if (CUBOOL_WITH_CUDA)
146146
set_target_properties(cubool PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
147147

148148
# Settings: https://arnon.dk/matching-sm-architectures-arch-and-gencode-for-various-nvidia-cards/
149-
target_compile_options(cubool PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:
150-
# todo: fix this flag later -arch=sm_30 ?
151-
# todo: can we omit arch flag?
152-
-gencode=arch=compute_30,code=sm_30
153-
-gencode=arch=compute_50,code=sm_50
154-
-gencode=arch=compute_52,code=sm_52
155-
-gencode=arch=compute_60,code=sm_60
156-
-gencode=arch=compute_61,code=sm_61
157-
-gencode=arch=compute_61,code=compute_61>)
149+
#target_compile_options(cubool PRIVATE $<$<COMPILE_LANGUAGE:CUDA>:
150+
# # todo: fix this flag later -arch=sm_30 ?
151+
# # todo: can we omit arch flag?
152+
# -gencode=arch=compute_30,code=sm_30
153+
# -gencode=arch=compute_50,code=sm_50
154+
# -gencode=arch=compute_52,code=sm_52
155+
# -gencode=arch=compute_60,code=sm_60
156+
# -gencode=arch=compute_61,code=sm_61
157+
# -gencode=arch=compute_61,code=compute_61>)
158158

159159
target_compile_options(cubool PRIVATE $<$<COMPILE_LANGUAGE:CUDA>: -use_fast_math -Xptxas -O2>)
160160

cubool/sources/core/matrix.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -364,17 +364,17 @@ namespace cubool {
364364
bool isSorted = false;
365365
bool noDuplicates = false;
366366

367-
// We will have to join old and new values
368367
if (mHnd->getNvals() > 0) {
369-
// Build tmp matrix with new values
368+
// We will have to join old and new values
369+
// Create tmp matrix and merge values
370+
370371
MatrixBase* tmp = mProvider->createMatrix(getNrows(), getNcols());
371372
tmp->build(mCachedI.data(), mCachedJ.data(), cachedNvals, isSorted, noDuplicates);
372-
373-
// Add new values to current matrix content
374373
mHnd->eWiseAdd(*mHnd, *tmp, false);
374+
mProvider->releaseMatrix(tmp);
375375
}
376-
// Otherwise, new values are used to build matrix content
377376
else {
377+
// Otherwise, new values are used to build matrix content
378378
mHnd->build(mCachedI.data(), mCachedJ.data(), cachedNvals, isSorted, noDuplicates);
379379
}
380380

cubool/sources/cuda/cuda_backend.cu

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525
#include <cuda/cuda_backend.hpp>
2626
#include <cuda/matrix_csr.hpp>
27+
#include <core/library.hpp>
28+
#include <io/logger.hpp>
2729

2830
namespace cubool {
2931

@@ -36,6 +38,14 @@ namespace cubool {
3638
}
3739

3840
void CudaBackend::finalize() {
41+
assert(mMatCount == 0);
42+
43+
if (mMatCount > 0) {
44+
LogStream stream(*Library::getLogger());
45+
stream << Logger::Level::Error
46+
<< "Lost some (" << mMatCount << ") matrix objects" << LogStream::cmt;
47+
}
48+
3949
if (mInstance) {
4050
delete mInstance;
4151
mInstance = nullptr;
@@ -47,10 +57,12 @@ namespace cubool {
4757
}
4858

4959
MatrixBase *CudaBackend::createMatrix(size_t nrows, size_t ncols) {
60+
mMatCount++;
5061
return new MatrixCsr(nrows, ncols, getInstance());
5162
}
5263

5364
void CudaBackend::releaseMatrix(MatrixBase *matrixBase) {
65+
mMatCount--;
5466
delete matrixBase;
5567
}
5668

cubool/sources/cuda/cuda_backend.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ namespace cubool {
4949

5050
private:
5151
Instance* mInstance;
52+
size_t mMatCount = 0;
5253
};
5354

5455
}

cubool/sources/cuda/instance.cpp

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,13 @@ namespace cubool {
4444
void Instance::allocate(void* &ptr, size_t size) const {
4545
ptr = malloc(size);
4646
CHECK_RAISE_ERROR(ptr != nullptr, MemOpFailed, "Failed to allocate memory on the CPU");
47+
mHostAllocCount++;
4748
}
4849

4950
void Instance::deallocate(void* ptr) const {
5051
CHECK_RAISE_ERROR(ptr != nullptr, InvalidArgument, "Passed null ptr to free");
5152
free(ptr);
52-
}
53-
54-
void Instance::printDeviceCapabilities() const {
55-
static const size_t BUFFER_SIZE = 1024;
56-
57-
cuBool_DeviceCaps deviceCaps;
58-
queryDeviceCapabilities(deviceCaps);
59-
60-
char deviceInfo[BUFFER_SIZE];
61-
snprintf(deviceInfo, BUFFER_SIZE, "Device name: %s version: %i.%i",
62-
deviceCaps.name, deviceCaps.major, deviceCaps.major);
63-
64-
char memoryInfo[BUFFER_SIZE];
65-
snprintf(memoryInfo, BUFFER_SIZE, "Global memory: %llu KiB",
66-
(unsigned long long) deviceCaps.globalMemoryKiBs);
67-
68-
char sharedMemoryInfo[BUFFER_SIZE];
69-
snprintf(sharedMemoryInfo, BUFFER_SIZE, "Shared memory: multi-proc %llu KiB block %llu KiB",
70-
(unsigned long long) deviceCaps.sharedMemoryPerMultiProcKiBs, (unsigned long long) deviceCaps.sharedMemoryPerBlockKiBs);
71-
72-
char structInfo[BUFFER_SIZE];
73-
snprintf(structInfo, BUFFER_SIZE, "Kernel: warp %llu", (unsigned long long) deviceCaps.warp);
74-
75-
// todo
53+
mHostAllocCount--;
7654
}
7755

7856
Instance& Instance::getInstanceRef() {

cubool/sources/cuda/instance.cu

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
namespace cubool {
3232

3333
Instance::~Instance() {
34+
assert(mHostAllocCount == 0);
35+
assert(mDeviceAllocCount == 0);
36+
3437
gInstance = nullptr;
3538
}
3639

@@ -53,13 +56,7 @@ namespace cubool {
5356
RAISE_ERROR(MemOpFailed, message);
5457
}
5558

56-
#if 0
57-
{
58-
char buffer[2000];
59-
snprintf(buffer, 2000, "============> allocate on gpu %llu", (long long unsigned) size);
60-
this->sendMessage(CUBOOL_STATUS_SUCCESS, buffer);
61-
}
62-
#endif
59+
mDeviceAllocCount++;
6360
}
6461

6562
void Instance::deallocateOnGpu(void* ptr) const {
@@ -69,6 +66,8 @@ namespace cubool {
6966
std::string message = std::string{"Failed to deallocate Gpu memory: "} + cudaGetErrorString(error);
7067
RAISE_ERROR(MemOpFailed, message);
7168
}
69+
70+
mDeviceAllocCount--;
7271
}
7372

7473
void Instance::syncHostDevice() const {

cubool/sources/cuda/instance.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ namespace cubool {
5252
void deallocateOnGpu(void* ptr) const;
5353

5454
void syncHostDevice() const;
55-
void printDeviceCapabilities() const;
5655

5756
static bool isCudaDeviceSupported();
5857
static void queryDeviceCapabilities(cuBool_DeviceCaps& deviceCaps);
@@ -62,6 +61,8 @@ namespace cubool {
6261

6362
private:
6463
MemType mMemoryType = Default;
64+
mutable size_t mHostAllocCount = 0;
65+
mutable size_t mDeviceAllocCount = 0;
6566

6667
static volatile Instance* gInstance;
6768
};

cubool/sources/sequential/sq_backend.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424

2525
#include <sequential/sq_backend.hpp>
2626
#include <sequential/sq_matrix.hpp>
27+
#include <core/library.hpp>
28+
#include <io/logger.hpp>
29+
#include <cassert>
30+
2731

2832
namespace cubool {
2933

@@ -32,18 +36,26 @@ namespace cubool {
3236
}
3337

3438
void SqBackend::finalize() {
35-
// No special actions
39+
assert(mMatCount == 0);
40+
41+
if (mMatCount > 0) {
42+
LogStream stream(*Library::getLogger());
43+
stream << Logger::Level::Error
44+
<< "Lost some (" << mMatCount << ") matrix objects" << LogStream::cmt;
45+
}
3646
}
3747

3848
bool SqBackend::isInitialized() const {
3949
return true;
4050
}
4151

4252
MatrixBase *SqBackend::createMatrix(size_t nrows, size_t ncols) {
53+
mMatCount++;
4354
return new SqMatrix(nrows, ncols);
4455
}
4556

4657
void SqBackend::releaseMatrix(MatrixBase *matrixBase) {
58+
mMatCount--;
4759
delete matrixBase;
4860
}
4961

cubool/sources/sequential/sq_backend.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ namespace cubool {
4444
void releaseMatrix(MatrixBase *matrixBase) override;
4545

4646
void queryCapabilities(cuBool_DeviceCaps& caps) override;
47+
48+
private:
49+
size_t mMatCount = 0;
4750
};
4851

4952
}

deps/nsparse-um/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.17)
1+
cmake_minimum_required(VERSION 3.15)
22
project(nsparse_um LANGUAGES CXX CUDA)
33

44
add_library(nsparse_um INTERFACE)

0 commit comments

Comments
 (0)