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
62f314ea
Commit
62f314ea
authored
9 years ago
by
Pietro Incardona
Browse files
Options
Downloads
Patches
Plain Diff
Added PtrMemory.cpp
parent
f2ca1d3b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/memory/PtrMemory.cpp
+155
-0
155 additions, 0 deletions
src/memory/PtrMemory.cpp
with
155 additions
and
0 deletions
src/memory/PtrMemory.cpp
0 → 100644
+
155
−
0
View file @
62f314ea
/*
* PtrMemory.cpp
*
* Created on: Apr 15, 2015
* Author: i-bird
*/
#ifndef PTRMEMORY_CPP_
#define PTRMEMORY_CPP_
#include
"PtrMemory.hpp"
#include
<cstddef>
#include
<cstring>
#include
<iostream>
#include
<cstdint>
// If debugging mode include memory leak check
#ifdef MEMLEAK_CHECK
#include
"Memleak_check.hpp"
#endif
/*! \brief Allocate a chunk of memory
*
* \param sz size of the chunk of memory to allocate in byte
*
*/
bool
PtrMemory
::
allocate
(
size_t
sz
)
{
if
(
sz
<=
spm
)
return
true
;
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
" "
<<
__LINE__
<<
" allocation failed"
;
return
false
;
}
/*! \brief destroy a chunk of memory
*
*/
void
PtrMemory
::
destroy
()
{
}
/*! \brief copy the data from a pointer
*
* \param ptr
*/
bool
PtrMemory
::
copyFromPointer
(
void
*
ptr
,
size_t
sz
)
{
// memory copy
memcpy
(
dm
,
ptr
,
sz
);
return
true
;
}
/*! \brief copy from device to device
*
* copy a piece of memory from device to device
*
* \param PtrMemory from where to copy
*
*/
bool
PtrMemory
::
copyDeviceToDevice
(
PtrMemory
&
m
)
{
//! The source buffer is too big to copy it
if
(
m
.
spm
>
spm
)
{
std
::
cerr
<<
"Error "
<<
__LINE__
<<
" "
<<
__FILE__
<<
": source buffer is too big to copy"
;
return
false
;
}
// Copy the memory from m
memcpy
(
dm
,
m
.
dm
,
m
.
spm
);
return
true
;
}
/*! \brief copy the memory
*
* \param m a memory interface
*
*/
bool
PtrMemory
::
copy
(
memory
&
m
)
{
//! Here we try to cast memory into PtrMemory
PtrMemory
*
ofpm
=
dynamic_cast
<
PtrMemory
*>
(
&
m
);
//! if we fail we get the pointer and simply copy from the pointer
if
(
ofpm
==
NULL
)
{
// copy the memory from device to host and from host to device
return
copyFromPointer
(
m
.
getPointer
(),
m
.
size
());
}
else
{
// they are the same memory type, use cuda/thrust buffer copy
return
copyDeviceToDevice
(
*
ofpm
);
}
return
false
;
}
/*! \brief Get the size of the allocated memory
*
* Get the size of the allocated memory
*
* \return the size of the allocated memory
*
*/
size_t
PtrMemory
::
size
()
{
return
sz
;
}
/*! \brief Resize the allocated memory
*
* Resize the allocated memory, if request is smaller than the allocated memory
* is not resized
*
* \param sz size
* \return true if the resize operation complete correctly
*
*/
bool
PtrMemory
::
resize
(
size_t
sz
)
{
// if the allocated memory is enough, do not resize
if
(
sz
<=
spm
)
{
this
->
sz
=
sz
;
return
true
;
}
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
" "
<<
__LINE__
<<
" allocation failed"
;
return
false
;
}
/*! \brief Return a pointer to the allocated memory
*
*
*/
void
*
PtrMemory
::
getPointer
()
{
return
dm
;
}
#endif
/* PTRMEMORY_CPP_ */
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