Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
O
openfpm_devices
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
openfpm
openfpm_devices
Commits
5df3d68a
Commit
5df3d68a
authored
Aug 21, 2018
by
incardon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GitLab CI test
parent
c751d466
Pipeline
#303
failed
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
154 additions
and
274 deletions
+154
-274
.gitlab-ci.yml
.gitlab-ci.yml
+45
-0
src/main.cpp
src/main.cpp
+1
-1
src/memory/BHeapMemory.hpp
src/memory/BHeapMemory.hpp
+18
-17
src/memory/CudaMemory.cu
src/memory/CudaMemory.cu
+31
-0
src/memory/CudaMemory.cuh
src/memory/CudaMemory.cuh
+15
-3
src/memory/ExtPreAlloc.hpp
src/memory/ExtPreAlloc.hpp
+17
-2
src/memory/HeapMemory.hpp
src/memory/HeapMemory.hpp
+13
-3
src/memory/HeapMemory_unit_tests.hpp
src/memory/HeapMemory_unit_tests.hpp
+0
-245
src/memory/PtrMemory.hpp
src/memory/PtrMemory.hpp
+13
-3
src/memory/memory.hpp
src/memory/memory.hpp
+1
-0
No files found.
.gitlab-ci.yml
0 → 100644
View file @
5df3d68a
centos_build
:
stage
:
build
tags
:
-
centos
script
:
-
sh "./build.sh $CI_PROJECT_DIR $CI_SERVER_NAME"
centos_run
:
stage
:
run
tags
:
-
centos
script
:
-
sh "./src/mem"
-
sh "./success.sh 2 centos openfpm_devices"
mac_build
:
stage
:
build
tags
:
-
mac
script
:
-
sh "./build.sh $CI_PROJECT_DIR $CI_SERVER_NAME"
mac_run
:
stage
:
run
tags
:
-
mac
script
:
-
sh "./src/mem"
-
sh "./success.sh 2 mac openfpm_devices"
ubuntu_build
:
stage
:
build
tags
:
-
ubuntu
script
:
-
sh "./build.sh $CI_PROJECT_DIR $CI_SERVER_NAME"
ubuntu_run
:
stage
:
run
tags
:
-
ubuntu
script
:
-
sh "./src/mem"
-
sh "./success.sh 2 ubuntu openfpm_devices"
src/main.cpp
View file @
5df3d68a
...
@@ -3,5 +3,5 @@
...
@@ -3,5 +3,5 @@
#include <boost/test/included/unit_test.hpp>
#include <boost/test/included/unit_test.hpp>
#include "config.h"
#include "config.h"
#include "memory/
Heap
Memory_unit_tests.hpp"
#include "memory/Memory_unit_tests.hpp"
src/memory/BHeapMemory.hpp
View file @
5df3d68a
...
@@ -44,7 +44,8 @@ typedef unsigned char byte;
...
@@ -44,7 +44,8 @@ typedef unsigned char byte;
* \snippet HeapMemory_unit_tests.hpp BShrink memory
* \snippet HeapMemory_unit_tests.hpp BShrink memory
*
*
*/
*/
class
BHeapMemory
:
public
HeapMemory
template
<
typename
Memory
>
class
BMemory
:
public
Memory
{
{
//! size of the memory
//! size of the memory
size_t
buf_sz
;
size_t
buf_sz
;
...
@@ -56,7 +57,7 @@ public:
...
@@ -56,7 +57,7 @@ public:
* \param mem memory to copy
* \param mem memory to copy
*
*
*/
*/
B
HeapMemory
(
const
BHeapMemory
&
mem
)
B
Memory
(
const
BMemory
<
Memory
>
&
mem
)
:
HeapMemory
(
mem
),
buf_sz
(
mem
.
size
())
:
HeapMemory
(
mem
),
buf_sz
(
mem
.
size
())
{
{
}
}
...
@@ -66,18 +67,18 @@ public:
...
@@ -66,18 +67,18 @@ public:
* \param mem memory to copy
* \param mem memory to copy
*
*
*/
*/
B
HeapMemory
(
BHeapMemory
&&
mem
)
noexcept
B
Memory
(
BMemory
<
Memory
>
&&
mem
)
noexcept
:
HeapMemory
((
Heap
Memory
&&
)
mem
),
buf_sz
(
mem
.
size
())
:
Memory
((
Memory
&&
)
mem
),
buf_sz
(
mem
.
size
())
{
{
}
}
//! Constructor, we choose a default alignment of 32 for avx
//! Constructor, we choose a default alignment of 32 for avx
B
Heap
Memory
()
BMemory
()
:
Heap
Memory
(),
buf_sz
(
0
)
:
Memory
(),
buf_sz
(
0
)
{};
{};
//! Destructor
//! Destructor
virtual
~
B
Heap
Memory
()
noexcept
virtual
~
BMemory
()
noexcept
{
{
};
};
...
@@ -92,7 +93,7 @@ public:
...
@@ -92,7 +93,7 @@ public:
*/
*/
virtual
bool
allocate
(
size_t
sz
)
virtual
bool
allocate
(
size_t
sz
)
{
{
bool
ret
=
Heap
Memory
::
allocate
(
sz
);
bool
ret
=
Memory
::
allocate
(
sz
);
if
(
ret
==
true
)
if
(
ret
==
true
)
buf_sz
=
sz
;
buf_sz
=
sz
;
...
@@ -111,7 +112,7 @@ public:
...
@@ -111,7 +112,7 @@ public:
*/
*/
virtual
bool
resize
(
size_t
sz
)
virtual
bool
resize
(
size_t
sz
)
{
{
bool
ret
=
Heap
Memory
::
resize
(
sz
);
bool
ret
=
Memory
::
resize
(
sz
);
// if the allocated memory is enough, do not resize
// if the allocated memory is enough, do not resize
if
(
ret
==
true
)
if
(
ret
==
true
)
...
@@ -138,7 +139,7 @@ public:
...
@@ -138,7 +139,7 @@ public:
*/
*/
size_t
msize
()
size_t
msize
()
{
{
return
Heap
Memory
::
size
();
return
Memory
::
size
();
}
}
/*! \brief Copy the memory
/*! \brief Copy the memory
...
@@ -148,10 +149,10 @@ public:
...
@@ -148,10 +149,10 @@ public:
* \return itself
* \return itself
*
*
*/
*/
B
HeapMemory
&
operator
=
(
const
BHeapMemory
&
mem
)
B
Memory
&
operator
=
(
const
BMemory
<
Memory
>
&
mem
)
{
{
buf_sz
=
mem
.
buf_sz
;
buf_sz
=
mem
.
buf_sz
;
static_cast
<
Heap
Memory
*>
(
this
)
->
operator
=
(
mem
);
static_cast
<
Memory
*>
(
this
)
->
operator
=
(
mem
);
return
*
this
;
return
*
this
;
}
}
...
@@ -163,10 +164,10 @@ public:
...
@@ -163,10 +164,10 @@ public:
* \return itself
* \return itself
*
*
*/
*/
B
HeapMemory
&
operator
=
(
BHeapMemory
&&
mem
)
B
Memory
&
operator
=
(
BMemory
<
Memory
>
&&
mem
)
{
{
buf_sz
=
mem
.
buf_sz
;
buf_sz
=
mem
.
buf_sz
;
static_cast
<
Heap
Memory
*>
(
this
)
->
operator
=
(
mem
);
static_cast
<
Memory
*>
(
this
)
->
operator
=
(
mem
);
return
*
this
;
return
*
this
;
}
}
...
@@ -177,7 +178,7 @@ public:
...
@@ -177,7 +178,7 @@ public:
*/
*/
void
destroy
()
void
destroy
()
{
{
Heap
Memory
::
destroy
();
Memory
::
destroy
();
buf_sz
=
0
;
buf_sz
=
0
;
}
}
...
@@ -186,9 +187,9 @@ public:
...
@@ -186,9 +187,9 @@ public:
* \param mem Memory to swap with
* \param mem Memory to swap with
*
*
*/
*/
void
swap
(
B
HeapMemory
&
mem
)
void
swap
(
B
Memory
<
Memory
>
&
mem
)
{
{
Heap
Memory
::
swap
(
mem
);
Memory
::
swap
(
mem
);
size_t
buf_sz_t
=
mem
.
buf_sz
;
size_t
buf_sz_t
=
mem
.
buf_sz
;
mem
.
buf_sz
=
buf_sz
;
mem
.
buf_sz
=
buf_sz
;
...
...
src/memory/CudaMemory.cu
View file @
5df3d68a
...
@@ -353,3 +353,34 @@ void * CudaMemory::getDevicePointerNoCopy()
...
@@ -353,3 +353,34 @@ void * CudaMemory::getDevicePointerNoCopy()
return
dm
;
return
dm
;
}
}
/*! \brief Swap the memory
*
* \param mem memory to swap
*
*/
void
CudaMemory
::
swap
(
CudaMemory
&
mem
)
{
size_t
sz_tmp
;
void
*
dm_tmp
;
long
int
ref_cnt_tmp
;
bool
is_hm_sync_tmp
;
void
*
hm_tmp
;
hm_tmp
=
hm
;
is_hm_sync_tmp
=
is_hm_sync
;
sz_tmp
=
sz
;
dm_tmp
=
dm
;
ref_cnt_tmp
=
ref_cnt
;
hm
=
mem
.
hm
;
is_hm_sync
=
mem
.
is_hm_sync
;
sz
=
mem
.
sz
;
dm
=
mem
.
dm
;
ref_cnt
=
mem
.
ref_cnt
;
mem
.
hm
=
hm_tmp
;
mem
.
is_hm_sync
=
is_hm_sync_tmp
;
mem
.
sz
=
sz_tmp
;
mem
.
dm
=
dm_tmp
;
mem
.
ref_cnt
=
ref_cnt_tmp
;
}
src/memory/CudaMemory.cuh
View file @
5df3d68a
...
@@ -60,14 +60,14 @@ class CudaMemory : public memory
...
@@ -60,14 +60,14 @@ class CudaMemory : public memory
//! Allocate an host buffer
//! Allocate an host buffer
void
allocate_host
(
size_t
sz
)
const
;
void
allocate_host
(
size_t
sz
)
const
;
//! copy from GPU to GPU buffer directly
bool
copyDeviceToDevice
(
const
CudaMemory
&
m
);
//! copy from Pointer to GPU
//! copy from Pointer to GPU
bool
copyFromPointer
(
const
void
*
ptr
);
bool
copyFromPointer
(
const
void
*
ptr
);
public:
public:
//! copy from GPU to GPU buffer directly
bool
copyDeviceToDevice
(
const
CudaMemory
&
m
);
//! flush the memory
//! flush the memory
virtual
bool
flush
();
virtual
bool
flush
();
//! allocate memory
//! allocate memory
...
@@ -180,6 +180,18 @@ public:
...
@@ -180,6 +180,18 @@ public:
else
else
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
" "
<<
__LINE__
<<
" destroying a live object"
<<
"
\n
"
;
std
::
cerr
<<
"Error: "
<<
__FILE__
<<
" "
<<
__LINE__
<<
" destroying a live object"
<<
"
\n
"
;
};
};
void
swap
(
CudaMemory
&
mem
);
/*! \brief Return true if the device and the host pointer are the same
*
* \return true if they are the same
*
*/
static
bool
isDeviceHostSame
()
{
return
false
;
}
};
};
#endif
#endif
...
...
src/memory/ExtPreAlloc.hpp
View file @
5df3d68a
...
@@ -65,6 +65,21 @@ public:
...
@@ -65,6 +65,21 @@ public:
mem
.
resize
(
size
);
mem
.
resize
(
size
);
}
}
/*! \brief Copy the memory from device to device
*
* \param m memory from where to copy
*
*/
bool
copyDeviceToDevice
(
const
ExtPreAlloc
<
Mem
>
&
m
)
{
return
mem
->
copyDeviceToDevice
(
*
m
.
mem
);
}
static
bool
isDeviceHostSame
()
{
return
Mem
::
isDeviceHostSame
();
}
//! Increment the reference counter
//! Increment the reference counter
virtual
void
incRef
()
virtual
void
incRef
()
{
ref_cnt
++
;}
{
ref_cnt
++
;}
...
@@ -164,7 +179,7 @@ public:
...
@@ -164,7 +179,7 @@ public:
*/
*/
virtual
void
*
getDevicePointer
()
virtual
void
*
getDevicePointer
()
{
{
return
getDevicePointer
();
return
mem
->
getDevicePointer
();
}
}
/*! \brief Return the pointer of the last allocation
/*! \brief Return the pointer of the last allocation
...
@@ -174,7 +189,7 @@ public:
...
@@ -174,7 +189,7 @@ public:
*/
*/
virtual
void
*
getDevicePointerNoCopy
()
virtual
void
*
getDevicePointerNoCopy
()
{
{
return
getDevicePointerNoCopy
();
return
mem
->
getDevicePointerNoCopy
();
}
}
//! Do nothing
//! Do nothing
...
...
src/memory/HeapMemory.hpp
View file @
5df3d68a
...
@@ -51,9 +51,6 @@ class HeapMemory : public memory
...
@@ -51,9 +51,6 @@ class HeapMemory : public memory
//! Reference counter
//! Reference counter
long
int
ref_cnt
;
long
int
ref_cnt
;
//! copy from same Heap to Heap
bool
copyDeviceToDevice
(
const
HeapMemory
&
m
);
//! copy from Pointer to Heap
//! copy from Pointer to Heap
bool
copyFromPointer
(
const
void
*
ptr
,
size_t
sz
);
bool
copyFromPointer
(
const
void
*
ptr
,
size_t
sz
);
...
@@ -62,6 +59,9 @@ class HeapMemory : public memory
...
@@ -62,6 +59,9 @@ class HeapMemory : public memory
public:
public:
//! copy from same Heap to Heap
bool
copyDeviceToDevice
(
const
HeapMemory
&
m
);
//! flush the memory
//! flush the memory
virtual
bool
flush
()
{
return
true
;};
virtual
bool
flush
()
{
return
true
;};
//! allocate memory
//! allocate memory
...
@@ -196,6 +196,16 @@ public:
...
@@ -196,6 +196,16 @@ public:
mem
.
dmOrig
=
dmOrig_tmp
;
mem
.
dmOrig
=
dmOrig_tmp
;
mem
.
ref_cnt
=
ref_cnt_tmp
;
mem
.
ref_cnt
=
ref_cnt_tmp
;
}
}
/*! \brief Return true if the device and the host pointer are the same
*
* \return true if they are the same
*
*/
static
bool
isDeviceHostSame
()
{
return
true
;
}
};
};
...
...
src/memory/HeapMemory_unit_tests.hpp
deleted
100644 → 0
View file @
c751d466
/*
* HeapMemory_unit_tests.hpp
*
* Created on: Jul 9, 2015
* Author: i-bird
*/
#ifndef HEAPMEMORY_UNIT_TESTS_HPP_
#define HEAPMEMORY_UNIT_TESTS_HPP_
#include "config.h"
#include "memory/HeapMemory.hpp"
#include "memory/BHeapMemory.hpp"
#ifdef NVCC
#include "memory/CudaMemory.cuh"
#endif
BOOST_AUTO_TEST_SUITE
(
HeapMemory_test
)
//! [Memory test constants]
#define FIRST_ALLOCATION 1024ul
#define SECOND_ALLOCATION 4096ul
//! [Memory test constants]
template
<
typename
T
>
void
test
()
{
//! [Allocate some memory and fill with data]
T
mem
;
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
0ul
);
mem
.
allocate
(
FIRST_ALLOCATION
);
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
FIRST_ALLOCATION
);
// get the pointer of the allocated memory and fill
unsigned
char
*
ptr
=
(
unsigned
char
*
)
mem
.
getPointer
();
for
(
size_t
i
=
0
;
i
<
mem
.
size
()
;
i
++
)
{
ptr
[
i
]
=
i
;}
mem
.
flush
();
//! [Allocate some memory and fill with data]
//! [Resize the memory]
mem
.
resize
(
SECOND_ALLOCATION
);
unsigned
char
*
ptr2
=
(
unsigned
char
*
)
mem
.
getPointer
();
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
SECOND_ALLOCATION
);
BOOST_REQUIRE_EQUAL
(
mem
.
isInitialized
(),
false
);
//! [Resize the memory]
// check that the data are retained
for
(
size_t
i
=
0
;
i
<
FIRST_ALLOCATION
;
i
++
)
{
unsigned
char
c
=
i
;
BOOST_REQUIRE_EQUAL
(
ptr2
[
i
],
c
);
}
//! [Shrink memory]
mem
.
resize
(
1
);
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
SECOND_ALLOCATION
);
//! [Shrink memory]
{
//! [Copy memory]
T
src
;
T
dst
;
src
.
allocate
(
FIRST_ALLOCATION
);
dst
.
allocate
(
SECOND_ALLOCATION
);
unsigned
char
*
ptr
=
(
unsigned
char
*
)
src
.
getPointer
();
for
(
size_t
i
=
0
;
i
<
src
.
size
()
;
i
++
)
ptr
[
i
]
=
i
;
dst
.
copy
(
src
);
for
(
size_t
i
=
0
;
i
<
FIRST_ALLOCATION
;
i
++
)
{
unsigned
char
c
=
i
;
BOOST_REQUIRE_EQUAL
(
ptr2
[
i
],
c
);
}
//! [Copy Memory]
}
{
T
src
;
src
.
allocate
(
FIRST_ALLOCATION
);
unsigned
char
*
ptr
=
(
unsigned
char
*
)
src
.
getPointer
();
for
(
size_t
i
=
0
;
i
<
src
.
size
()
;
i
++
)
ptr
[
i
]
=
i
;
src
.
flush
();
T
dst
=
src
;
unsigned
char
*
ptr2
=
(
unsigned
char
*
)
dst
.
getPointer
();
BOOST_REQUIRE
(
src
.
getPointer
()
!=
dst
.
getPointer
());
for
(
size_t
i
=
0
;
i
<
FIRST_ALLOCATION
;
i
++
)
{
unsigned
char
c
=
i
;
BOOST_REQUIRE_EQUAL
(
ptr2
[
i
],
c
);
}
mem
.
destroy
();
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
0ul
);
mem
.
allocate
(
FIRST_ALLOCATION
);
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
FIRST_ALLOCATION
);
}
}
template
<
typename
T
>
void
Btest
()
{
//! [BAllocate some memory and fill with data]
T
mem
;
mem
.
allocate
(
FIRST_ALLOCATION
);
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
FIRST_ALLOCATION
);
// get the pointer of the allocated memory and fill
unsigned
char
*
ptr
=
(
unsigned
char
*
)
mem
.
getPointer
();
for
(
size_t
i
=
0
;
i
<
mem
.
size
()
;
i
++
)
ptr
[
i
]
=
i
;
//! [BAllocate some memory and fill with data]
//! [BResize the memory]
mem
.
resize
(
SECOND_ALLOCATION
);
unsigned
char
*
ptr2
=
(
unsigned
char
*
)
mem
.
getPointer
();
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
SECOND_ALLOCATION
);
BOOST_REQUIRE_EQUAL
(
mem
.
isInitialized
(),
false
);
//! [BResize the memory]
// check that the data are retained
for
(
size_t
i
=
0
;
i
<
FIRST_ALLOCATION
;
i
++
)
{
unsigned
char
c
=
i
;
BOOST_REQUIRE_EQUAL
(
ptr2
[
i
],
c
);
}
//! [BShrink memory]
mem
.
resize
(
1
);
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
1ul
);
//! [BShrink memory]
mem
.
destroy
();
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
0ul
);
mem
.
allocate
(
FIRST_ALLOCATION
);
BOOST_REQUIRE_EQUAL
(
mem
.
size
(),
FIRST_ALLOCATION
);
}
template
<
typename
T
>
void
Stest
()
{
T
mem1
;
T
mem2
;
mem1
.
allocate
(
5
*
sizeof
(
size_t
));
mem2
.
allocate
(
6
*
sizeof
(
size_t
));
BOOST_REQUIRE_EQUAL
(
mem1
.
size
(),
5
*
sizeof
(
size_t
));
BOOST_REQUIRE_EQUAL
(
mem2
.
size
(),
6
*
sizeof
(
size_t
));
// get the pointer of the allocated memory and fill
size_t
*
ptr1
=
(
size_t
*
)
mem1
.
getPointer
();
size_t
*
ptr2
=
(
size_t
*
)
mem2
.
getPointer
();
for
(
size_t
i
=
0
;
i
<
5
;
i
++
)
ptr1
[
i
]
=
i
;
for
(
size_t
i
=
0
;
i
<
6
;
i
++
)
ptr2
[
i
]
=
i
+
100
;
mem1
.
swap
(
mem2
);
bool
ret
=
true
;
ptr1
=
(
size_t
*
)
mem2
.
getPointer
();
ptr2
=
(
size_t
*
)
mem1
.
getPointer
();
for
(
size_t
i
=
0
;
i
<
5
;
i
++
)
ret
&=
ptr1
[
i
]
==
i
;
for
(
size_t
i
=
0
;
i
<
6
;
i
++
)
ret
&=
ptr2
[
i
]
==
i
+
100
;
BOOST_REQUIRE_EQUAL
(
ret
,
true
);
BOOST_REQUIRE_EQUAL
(
mem1
.
size
(),
6
*
sizeof
(
size_t
));
BOOST_REQUIRE_EQUAL
(
mem2
.
size
(),
5
*
sizeof
(
size_t
));
}
BOOST_AUTO_TEST_CASE
(
use_heap_memory
)
{
test
<
HeapMemory
>
();
#ifdef CUDA_GPU
test
<
CudaMemory
>
();
#endif
}
BOOST_AUTO_TEST_CASE
(
use_memory
)
{
test
<
HeapMemory
>
();
#ifdef CUDA_GPU
test
<
CudaMemory
>
();
#endif
}
BOOST_AUTO_TEST_CASE
(
use_bheap_memory
)
{
Btest
<
BHeapMemory
>
();
}
BOOST_AUTO_TEST_CASE
(
swap_heap_memory
)
{
Stest
<
HeapMemory
>
();
}