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
453d86e4
Commit
453d86e4
authored
9 years ago
by
Pietro Incardona
Browse files
Options
Downloads
Patches
Plain Diff
Adding memory.hpp to devices
parent
f6b24b7b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/memory/ExtPreAlloc.hpp
+17
-3
17 additions, 3 deletions
src/memory/ExtPreAlloc.hpp
src/memory/memory.hpp
+110
-0
110 additions, 0 deletions
src/memory/memory.hpp
with
127 additions
and
3 deletions
src/memory/ExtPreAlloc.hpp
+
17
−
3
View file @
453d86e4
...
...
@@ -12,6 +12,8 @@
* External pre-allocated memory, is a class that preallocate memory and than it answer
* to a particular allocation pattern
*
* \warning zero sized allocation are removed from the request pattern
*
* \tparam Base memory allocation class [Example] HeapMemory or CudaMemory
*
*
...
...
@@ -49,8 +51,6 @@ public:
ExtPreAlloc
()
:
a_seq
(
0
),
ref_cnt
(
0
)
{
int
debug
=
0
;
debug
++
;
}
/*! \brief Preallocated memory sequence
...
...
@@ -64,6 +64,15 @@ public:
{
size_t
total_size
=
0
;
// remove zero size request
for
(
std
::
vector
<
size_t
>::
iterator
it
=
seq
.
begin
();
it
!=
seq
.
end
();
)
{
if
(
*
it
==
0
)
it
=
seq
.
erase
(
it
);
else
++
it
;
}
// Resize the sequence
sequence
.
resize
(
seq
.
size
());
sequence_c
.
resize
(
seq
.
size
());
...
...
@@ -72,6 +81,7 @@ public:
sequence
[
i
]
=
seq
[
i
];
sequence_c
[
i
]
=
total_size
;
total_size
+=
seq
[
i
];
}
// Allocate the total size of memory
...
...
@@ -101,11 +111,15 @@ public:
*/
virtual
bool
allocate
(
size_t
sz
)
{
// Zero sized allocation are ignored
if
(
sz
==
0
)
return
true
;
// Check that the size match
if
(
sequence
[
a_seq
]
!=
sz
)
{
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
"
"
<<
__LINE__
<<
"expecting: "
<<
sequence
[
a_seq
]
<<
" got: "
<<
sz
<<
" allocation failed
\n
"
;
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
"
:
"
<<
__LINE__
<<
"
expecting: "
<<
sequence
[
a_seq
]
<<
" got: "
<<
sz
<<
" allocation failed
\n
"
;
std
::
cerr
<<
"NOTE: if you are using this structure with vector remember to use openfpm::vector<...>::calculateMem(...) to get the required allocation sequence
\n
"
;
return
false
;
...
...
This diff is collapsed.
Click to expand it.
src/memory/memory.hpp
0 → 100644
+
110
−
0
View file @
453d86e4
/*
* memory.hpp
*
* Created on: Aug 8, 2014
* Author: Pietro Incardona
*/
/*! \brief This class is an interface
*
* This class is an interface to allocate memory
*
*/
#ifndef MEMORY_HPP_
#define MEMORY_HPP_
typedef
long
int
mem_id
;
#include
"config.h"
#include
<stddef.h>
class
memory
{
public:
/*! \brief allocate on device a buffer of
*
* Allocate on the device a buffer of memory
*
* \param sz the size of the buffer
*
*/
virtual
bool
allocate
(
size_t
sz
)
=
0
;
/*! \brief resize on device a buffer
*
* On the device resize
*
* \param sz the size the resized buffer
*
*/
virtual
bool
resize
(
size_t
sz
)
=
0
;
/*! \brief Destroy the buffer on the device
*
* destroy the buffer on the device
*
*/
virtual
void
destroy
()
=
0
;
/*! \brief Copy the memory from one device to another device
*
* \param m from where to copy
*
*/
virtual
bool
copy
(
memory
&
m
)
=
0
;
/*! \brief get the size of the buffer
*
*/
virtual
size_t
size
()
=
0
;
/*! \brief return a data pointer
*
* return readable pointer with the data stored
*
*/
virtual
void
*
getPointer
()
=
0
;
/*! \brief destructor
*
* destructor
*
*/
virtual
~
memory
()
{};
/*! \brief Increment the internal reference counter
*
*
*/
virtual
void
incRef
()
=
0
;
/*! \brief Decrement the internal reference counter
*
*
*/
virtual
void
decRef
()
=
0
;
/*! \brief Return the actual reference counter
*
* \return the reference counter
*
*/
virtual
long
int
ref
()
=
0
;
/*! \brief Return if the actual memory that is going to be allocated is already initialized
*
* \return true if already initialized
*
*/
virtual
bool
isInitialized
()
=
0
;
};
#endif
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