Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
openfpm_devices
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sbalzarini Lab
Software
Parallel Computing
OpenFPM
openfpm_devices
Commits
18cad2e7
Commit
18cad2e7
authored
9 years ago
by
Pietro Incardona
Browse files
Options
Downloads
Patches
Plain Diff
Memleak_check move
parent
55db8122
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
src/Makefile.am
+3
-3
3 additions, 3 deletions
src/Makefile.am
src/Memleak_check.cpp
+21
-0
21 additions, 0 deletions
src/Memleak_check.cpp
src/Memleak_check.hpp
+180
-0
180 additions, 0 deletions
src/Memleak_check.hpp
src/memory/PtrMemory.hpp
+0
-13
0 additions, 13 deletions
src/memory/PtrMemory.hpp
with
204 additions
and
16 deletions
src/Makefile.am
+
3
−
3
View file @
18cad2e7
...
...
@@ -8,17 +8,17 @@ else
endif
noinst_PROGRAMS
=
mem
mem_SOURCES
=
main.cpp memory/HeapMemory.cpp
$(
CUDA_SOURCES
)
mem_SOURCES
=
main.cpp memory/HeapMemory.cpp
$(
CUDA_SOURCES
)
Memleak_check.cpp
mem_CXXFLAGS
=
$(
INCLUDES_PATH
)
$(
BOOST_CPPFLAGS
)
-I
/usr/local/include
mem_CFLAGS
=
mem_LDADD
=
$(
LINKLIBS
)
-L
/usr/lib64/nvidia-bumblebee/
lib_LIBRARIES
=
libofpmmemory.a
libofpmmemory_a_SOURCES
=
memory/HeapMemory.cpp
$(
CUDA_SOURCES
)
memory/PtrMemory.cpp
libofpmmemory_a_SOURCES
=
memory/HeapMemory.cpp
$(
CUDA_SOURCES
)
memory/PtrMemory.cpp
Memleak_check.cpp
libofpmmemory_a_CXXFLAGS
=
$(
INCLUDES_PATH
)
$(
BOOST_CPPFLAGS
)
-I
/usr/local/include
libofpmmemory_a_CFLAGS
=
nobase_include_HEADERS
=
memory/ExtPreAlloc.hpp memory/HeapMemory.hpp memory/memory.hpp memory/PreAllocHeapMemory.hpp memory/PtrMemory.hpp
nobase_include_HEADERS
=
memory/ExtPreAlloc.hpp memory/HeapMemory.hpp memory/memory.hpp memory/PreAllocHeapMemory.hpp memory/PtrMemory.hpp
Memleak_check.hpp
.cu.o
:
$(
NVCC
)
$(
NVCCFLAGS
)
-I
.
$(
INCLUDES_PATH
)
-o
$@
-c
$<
This diff is collapsed.
Click to expand it.
src/Memleak_check.cpp
0 → 100644
+
21
−
0
View file @
18cad2e7
#include
"config.h"
#include
"Memleak_check.hpp"
#ifdef SE_CLASS2
// counter for allocation of new memory
size_t
new_data
;
// counter to delete memory
size_t
delete_data
;
// structure that store all the active pointer
std
::
map
<
byte_ptr
,
size_t
>
active_ptr
;
// Running process id
long
int
process_v_cl
;
// Process to print
long
int
process_to_print
=
0
;
#endif
This diff is collapsed.
Click to expand it.
src/Memleak_check.hpp
0 → 100644
+
180
−
0
View file @
18cad2e7
#include
"config.h"
#include
<iostream>
#include
<map>
#ifndef MEMLEAK_CHECK_HPP
#define MEMLEAK_CHECK_HPP
typedef
unsigned
char
*
byte_ptr
;
#ifdef SE_CLASS2
#include
"util/se_util.hpp"
#define MEM_ERROR 1300lu
extern
size_t
new_data
;
extern
size_t
delete_data
;
extern
std
::
map
<
byte_ptr
,
size_t
>
active_ptr
;
extern
long
int
process_v_cl
;
extern
long
int
process_to_print
;
/*! \brief Check and remove the active pointer
*
* Check and remove the pointer from the active list
*
* \param pointer to check and remove
*
* \return true if the operation succeded, false if the pointer does not exist
*
*/
static
bool
remove_ptr
(
const
void
*
ptr
)
{
// Check if the pointer exist
std
::
map
<
byte_ptr
,
size_t
>::
iterator
it
=
active_ptr
.
find
((
byte_ptr
)
ptr
);
// if the element does not exist, print that something wrong happened and return
if
(
it
==
active_ptr
.
end
()
)
{
std
::
cout
<<
"Error pointer not found "
<<
ptr
<<
"
\n
"
;
ACTION_ON_ERROR
(
MEM_ERROR
);
return
false
;
}
// erase the pointer
active_ptr
.
erase
((
byte_ptr
)
ptr
);
return
true
;
}
/*! \brief Print all active pointer
*
* Print all active pointer
*
*/
static
void
print_unalloc
()
{
for
(
std
::
map
<
byte_ptr
,
size_t
>::
iterator
it
=
active_ptr
.
begin
();
it
!=
active_ptr
.
end
();
++
it
)
{
std
::
cout
<<
"Unallocated memory "
<<
it
->
first
<<
" size "
<<
it
->
second
<<
"
\n
"
;
}
}
/*! \brief Add the new allocated active pointer
*
* Add the new allocated active pointer
*
* \param new data active pointer
* \param sz size of the new allocated memory
*
*/
static
bool
check_new
(
const
void
*
data
,
size_t
sz
)
{
// Add a new pointer
new_data
++
;
active_ptr
[(
byte_ptr
)
data
]
=
sz
;
#ifdef SE_CLASS2_VERBOSE
if
(
process_to_print
<
0
||
process_to_print
==
process_v_cl
)
std
::
cout
<<
"New data: "
<<
new_data
<<
" "
<<
data
<<
"
\n
"
;
#endif
return
true
;
}
/*! \brief check and delete a pointer
*
* check and delete a pointer from the list of active pointers
*
* \param pointer data
* \return true if the operation to delete succeed
*
*/
static
bool
check_delete
(
const
void
*
data
)
{
if
(
data
==
NULL
)
return
true
;
// Delete the pointer
delete_data
++
;
bool
result
=
remove_ptr
(
data
);
#ifdef SE_CLASS2_VERBOSE
if
(
process_to_print
<
0
||
process_to_print
==
process_v_cl
)
std
::
cout
<<
"Delete data: "
<<
delete_data
<<
" "
<<
data
<<
"
\n
"
;
#endif
return
result
;
}
/*! \brief check if the access is valid
*
* check if the access is valid
*
* \param ptr pointer we are going to access
* \param size_access is the size in byte of the data we are fetching
*
* \return true if the pointer is valid
*
*/
static
bool
check_valid
(
const
void
*
ptr
,
size_t
size_access
)
{
// get the lower bound
std
::
map
<
byte_ptr
,
size_t
>::
iterator
l_b
=
active_ptr
.
upper_bound
((
byte_ptr
)
ptr
);
if
(
active_ptr
.
size
()
==
0
)
{
std
::
cout
<<
"Error invalid pointer: "
<<
__FILE__
<<
":"
<<
__LINE__
<<
" "
<<
ptr
<<
"
\n
"
;
ACTION_ON_ERROR
(
MEM_ERROR
);
return
false
;
}
//! subtract one
l_b
--
;
// if there is no memory that satisfy the request
if
(
l_b
==
active_ptr
.
end
())
{
if
(
process_to_print
<
0
||
process_to_print
==
process_v_cl
)
{
std
::
cout
<<
"Error invalid pointer: "
<<
__FILE__
<<
":"
<<
__LINE__
<<
" "
<<
ptr
<<
"
\n
"
;
ACTION_ON_ERROR
(
MEM_ERROR
);
}
return
false
;
}
// check if ptr is in the range
size_t
sz
=
l_b
->
second
;
if
(((
unsigned
char
*
)
l_b
->
first
)
+
sz
<
((
unsigned
char
*
)
ptr
)
+
size_access
)
{
if
(
process_to_print
<
0
||
process_to_print
==
process_v_cl
)
{
std
::
cout
<<
"Error invalid pointer: "
<<
__FILE__
<<
":"
<<
__LINE__
<<
" "
<<
ptr
<<
"
\n
"
;
ACTION_ON_ERROR
(
MEM_ERROR
);
return
false
;
}
}
return
true
;
}
/*! \brief In case of Parallel application it set the process that print the
*
* \param p_to_print is < 0 (Mean all)
*
*/
static
void
set_process_to_print
(
long
int
p_to_print
)
{
process_to_print
=
p_to_print
;
}
#else
#endif
#endif
This diff is collapsed.
Click to expand it.
src/memory/PtrMemory.hpp
+
0
−
13
View file @
18cad2e7
...
...
@@ -104,28 +104,15 @@ public:
// Default constructor
PtrMemory
()
:
spm
(
0
),
dm
(
NULL
),
sz
(
0
),
ref_cnt
(
0
)
{
#ifdef SE_CLASS2
if
(
process_to_print
==
process_v_cl
)
std
::
cout
<<
"Creating PtrMemory: "
<<
this
<<
"
\n
"
;
#endif
};
//! Constructor, we choose a default alignment of 32 for avx
PtrMemory
(
void
*
ptr
,
size_t
sz
)
:
spm
(
sz
),
dm
(
ptr
),
sz
(
0
),
ref_cnt
(
0
)
{
#ifdef SE_CLASS2
if
(
process_to_print
==
process_v_cl
)
std
::
cout
<<
"Creating PtrMemory: "
<<
this
<<
"
\n
"
;
#endif
};
~
PtrMemory
()
{
#ifdef SE_CLASS2
if
(
process_to_print
==
process_v_cl
)
std
::
cout
<<
"Delete PtrMemory: "
<<
this
<<
"
\n
"
;
#endif
if
(
ref_cnt
==
0
)
destroy
();
else
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment