Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
memory-faucet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
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
数学の武士
memory-faucet
Commits
304cd577
Commit
304cd577
authored
8 months ago
by
数学の武士
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
5d240064
No related branches found
No related tags found
No related merge requests found
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
CMakeLists.txt
+13
-1
13 additions, 1 deletion
CMakeLists.txt
Lib/CMakeLists.txt
+7
-1
7 additions, 1 deletion
Lib/CMakeLists.txt
Lib/memory-faucet.cpp
+82
-39
82 additions, 39 deletions
Lib/memory-faucet.cpp
Lib/memory-faucet.h
+13
-10
13 additions, 10 deletions
Lib/memory-faucet.h
main.cpp
+39
-9
39 additions, 9 deletions
main.cpp
with
154 additions
and
60 deletions
CMakeLists.txt
+
13
−
1
View file @
304cd577
cmake_minimum_required
(
VERSION 3.19
)
cmake_minimum_required
(
VERSION 3.19
)
option
(
INCLUDE_CUDA
"GPU build in mode"
OFF
)
option
(
INCLUDE_CUDA
"GPU build in mode"
OFF
)
option
(
ADRESS_SANITIZER
"Enable address sanitizer"
OFF
)
option
(
CXX23_STACKTRACE
"Enable C++23 stacktrace"
OFF
)
if
(
ADRESS_SANITIZER
)
set
(
CMAKE_CXX_FLAGS
"
${
CMAKE_CXX_FLAGS
}
-fsanitize=address -O1 -fno-omit-frame-pointer -g"
)
endif
(
ADRESS_SANITIZER
)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++2b")
project
(
memory-faucet-test
)
project
(
memory-faucet-test
)
enable_language
(
CXX
)
enable_language
(
CXX
)
if
(
CXX23_STACKTRACE
)
set
(
CMAKE_CXX_STANDARD 23
)
else
(
CXX23_STACKTRACE
)
set
(
CMAKE_CXX_STANDARD 11
)
set
(
CMAKE_CXX_STANDARD 11
)
endif
(
CXX23_STACKTRACE
)
if
(
INCLUDE_CUDA
)
if
(
INCLUDE_CUDA
)
if
(
NOT DEFINED CMAKE_CUDA_ARCHITECTURES
)
if
(
NOT DEFINED CMAKE_CUDA_ARCHITECTURES
)
...
...
This diff is collapsed.
Click to expand it.
Lib/CMakeLists.txt
+
7
−
1
View file @
304cd577
cmake_minimum_required
(
VERSION 3.19
)
cmake_minimum_required
(
VERSION 3.19
)
option
(
INCLUDE_CUDA
"GPU build in mode"
OFF
)
option
(
INCLUDE_CUDA
"GPU build in mode"
OFF
)
option
(
CXX23_STACKTRACE
"Enable C++23 stacktrace"
OFF
)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++2b")
project
(
memory-holder
)
project
(
memory-holder
)
enable_language
(
CXX
)
enable_language
(
CXX
)
if
(
CXX23_STACKTRACE
)
set
(
CMAKE_CXX_STANDARD 23
)
else
(
CXX23_STACKTRACE
)
set
(
CMAKE_CXX_STANDARD 11
)
set
(
CMAKE_CXX_STANDARD 11
)
endif
(
CXX23_STACKTRACE
)
include
(
FetchContent
)
include
(
FetchContent
)
FetchContent_Declare
(
FetchContent_Declare
(
...
...
This diff is collapsed.
Click to expand it.
Lib/memory-faucet.cpp
+
82
−
39
View file @
304cd577
...
@@ -35,6 +35,7 @@ void buffer<mem>::reallocate(const size_t required_size)
...
@@ -35,6 +35,7 @@ void buffer<mem>::reallocate(const size_t required_size)
template
<
MemType
mem
>
template
<
MemType
mem
>
buffer
<
mem
>::
buffer
(
const
size_t
required_size
)
buffer
<
mem
>::
buffer
(
const
size_t
required_size
)
{
{
ptr
=
nullptr
;
allocated_size
=
0
;
allocated_size
=
0
;
reallocate
(
required_size
);
reallocate
(
required_size
);
scalar_size
=
0
;
scalar_size
=
0
;
...
@@ -96,6 +97,12 @@ void buffer<mem>::set_allocated_size(const size_t required_size)
...
@@ -96,6 +97,12 @@ void buffer<mem>::set_allocated_size(const size_t required_size)
allocated_size
=
required_size
;
allocated_size
=
required_size
;
}
}
template
<
MemType
mem
>
void
buffer
<
mem
>::
set_null_pointer
()
{
ptr
=
nullptr
;
}
template
<
MemType
mem
>
template
<
MemType
mem
>
buffer
<
mem
>::
buffer
(
const
buffer
<
mem
>&
other
)
buffer
<
mem
>::
buffer
(
const
buffer
<
mem
>&
other
)
{
{
...
@@ -106,17 +113,19 @@ buffer<mem>::buffer(const buffer<mem>& other)
...
@@ -106,17 +113,19 @@ buffer<mem>::buffer(const buffer<mem>& other)
}
}
template
<
MemType
mem
>
template
<
MemType
mem
>
buffer
<
mem
>
&
buffer
<
mem
>::
operator
=
(
buffer
<
mem
>&
other
)
buffer
<
mem
>
::
buffer
(
buffer
<
mem
>&
&
other
)
{
{
if
(
this
==
&
other
)
ptr
=
other
.
ptr
;
return
*
this
;
allocated_size
=
other
.
allocated_size
;
scalar_size
=
other
.
scalar_size
;
is_free
=
other
.
is_free
;
id
=
other
.
id
;
std
::
swap
(
ptr
,
other
.
ptr
);
other
.
ptr
=
nullptr
;
allocated_size
=
other
.
get_size
();
other
.
allocated_size
=
0
;
other
.
set_allocated_size
(
size_t
(
0
));
other
.
scalar_size
=
0
;
is_free
=
other
.
get_status
();
other
.
is_free
=
false
;
id
=
other
.
get_id
();
other
.
id
=
-
1
;
return
*
this
;
}
}
template
<
MemType
mem
>
template
<
MemType
mem
>
...
@@ -132,6 +141,28 @@ buffer<mem>& buffer<mem>::operator=(const buffer<mem>& other)
...
@@ -132,6 +141,28 @@ buffer<mem>& buffer<mem>::operator=(const buffer<mem>& other)
return
*
this
;
return
*
this
;
}
}
template
<
MemType
mem
>
buffer
<
mem
>&
buffer
<
mem
>::
operator
=
(
buffer
<
mem
>&&
other
)
{
if
(
this
!=
&
other
)
{
memproc
::
dealloc
<
mem
>
((
void
*&
)
ptr
,
allocated_size
);
ptr
=
other
.
ptr
;
allocated_size
=
other
.
allocated_size
;
scalar_size
=
other
.
scalar_size
;
is_free
=
other
.
is_free
;
id
=
other
.
id
;
other
.
ptr
=
nullptr
;
other
.
allocated_size
=
0
;
other
.
scalar_size
=
0
;
other
.
is_free
=
false
;
other
.
id
=
-
1
;
}
return
*
this
;
}
template
<
MemType
mem
>
template
<
MemType
mem
>
void
buffer
<
mem
>::
set_status
(
const
bool
status
)
void
buffer
<
mem
>::
set_status
(
const
bool
status
)
{
{
...
@@ -165,8 +196,8 @@ memory_pipe_base::~memory_pipe_base()
...
@@ -165,8 +196,8 @@ memory_pipe_base::~memory_pipe_base()
cpu_buff
.
clear
();
cpu_buff
.
clear
();
}
}
template
<
MemType
mem
>
template
<
>
std
::
vector
<
buffer
<
mem
>
>&
memory_pipe_base
::
get_memtyped_vector
()
std
::
vector
<
buffer
<
MemType
::
CPU
>
>&
memory_pipe_base
::
get_memtyped_vector
()
{
{
return
cpu_buff
;
return
cpu_buff
;
}
}
...
@@ -202,7 +233,7 @@ typename std::vector<buffer<mem>>::iterator get_lower_bound(typename std::vector
...
@@ -202,7 +233,7 @@ typename std::vector<buffer<mem>>::iterator get_lower_bound(typename std::vector
{
{
it
=
first
;
it
=
first
;
step
=
count
/
2
;
step
=
count
/
2
;
std
::
next
(
it
,
step
);
it
=
std
::
next
(
it
,
step
);
if
(
comp
(
*
it
,
value
))
if
(
comp
(
*
it
,
value
))
{
{
...
@@ -235,7 +266,7 @@ typename std::vector<buffer<mem>>::iterator get_upper_bound(typename std::vector
...
@@ -235,7 +266,7 @@ typename std::vector<buffer<mem>>::iterator get_upper_bound(typename std::vector
{
{
it
=
first
;
it
=
first
;
step
=
count
/
2
;
step
=
count
/
2
;
std
::
next
(
it
,
step
);
it
=
std
::
next
(
it
,
step
);
if
(
!
comp
(
value
,
*
it
))
if
(
!
comp
(
value
,
*
it
))
{
{
...
@@ -258,7 +289,7 @@ template typename std::vector<buffer<MemType::GPU>>::iterator get_upper_bound<Me
...
@@ -258,7 +289,7 @@ template typename std::vector<buffer<MemType::GPU>>::iterator get_upper_bound<Me
template
<
buf_choose_policy
choose_type
>
template
<
buf_choose_policy
choose_type
>
template
<
MemType
mem
>
template
<
MemType
mem
>
int
memory_pipe
<
choose_type
>::
get_buffer
(
const
size_t
required_size
,
void
*
&
ptr
)
int
memory_pipe
<
choose_type
>::
get_buffer
(
const
size_t
required_size
,
void
*
*
ptr
)
{
{
std
::
vector
<
buffer
<
mem
>
>&
buff_vec
=
get_memtyped_vector
<
mem
>
();
std
::
vector
<
buffer
<
mem
>
>&
buff_vec
=
get_memtyped_vector
<
mem
>
();
const
int
allocated_buffer_n
=
buff_vec
.
size
();
const
int
allocated_buffer_n
=
buff_vec
.
size
();
...
@@ -269,24 +300,31 @@ int memory_pipe<choose_type>::get_buffer(const size_t required_size, void *& ptr
...
@@ -269,24 +300,31 @@ int memory_pipe<choose_type>::get_buffer(const size_t required_size, void *& ptr
if
(
is_free
==
true
&&
required_size
<=
avail_size
)
if
(
is_free
==
true
&&
required_size
<=
avail_size
)
{
{
ptr
=
buff_vec
[
i
].
get_ptr
();
(
*
ptr
)
=
buff_vec
[
i
].
get_ptr
();
buff_vec
[
i
].
set_status
(
false
);
return
i
;
return
i
;
}
}
}
}
buff_vec
.
push_back
(
buffer
<
mem
>
(
required_size
));
buff_vec
.
push_back
(
buffer
<
mem
>
(
required_size
));
ptr
=
buff_vec
.
back
().
get_ptr
();
(
*
ptr
)
=
buff_vec
.
back
().
get_ptr
();
int
id
=
buff_vec
.
size
()
-
1
;
int
id
=
buff_vec
.
size
()
-
1
;
buff_vec
.
back
().
set_status
(
false
);
buff_vec
.
back
().
set_id
(
id
);
return
id
;
return
id
;
}
}
template
int
memory_pipe
<
buf_choose_policy
::
naiv
>
::
get_buffer
<
MemType
::
CPU
>
(
const
size_t
required_size
,
void
*
&
ptr
);
template
int
memory_pipe
<
buf_choose_policy
::
naiv
e
>
::
get_buffer
<
MemType
::
CPU
>
(
const
size_t
required_size
,
void
*
*
ptr
);
#ifdef INCLUDE_CUDA
#ifdef INCLUDE_CUDA
template
int
memory_pipe
<
buf_choose_policy
::
naiv
>
::
get_buffer
<
MemType
::
GPU
>
(
const
size_t
required_size
,
void
*
&
ptr
);
template
int
memory_pipe
<
buf_choose_policy
::
naiv
e
>
::
get_buffer
<
MemType
::
GPU
>
(
const
size_t
required_size
,
void
*
*
ptr
);
#endif
#endif
// template< >
template
<
MemType
mem
>
template
<
MemType
mem
>
int
memory_pipe
<
buf_choose_policy
::
sorted_vec
>::
get_buffer
(
const
size_t
required_size
,
void
*
&
ptr
)
int
memory_pipe
<
buf_choose_policy
::
sorted_vec
>::
get_buffer
(
const
size_t
required_size
,
void
*
*
ptr
)
{
{
std
::
vector
<
buffer
<
mem
>
>&
buff_vec
=
get_memtyped_vector
<
mem
>
();
std
::
vector
<
buffer
<
mem
>
>&
buff_vec
=
get_memtyped_vector
<
mem
>
();
const
int
allocated_buffer_n
=
buff_vec
.
size
();
const
int
allocated_buffer_n
=
buff_vec
.
size
();
...
@@ -297,7 +335,8 @@ int memory_pipe<buf_choose_policy::sorted_vec>::get_buffer(const size_t required
...
@@ -297,7 +335,8 @@ int memory_pipe<buf_choose_policy::sorted_vec>::get_buffer(const size_t required
if
(
is_free
==
true
&&
required_size
<=
avail_size
)
if
(
is_free
==
true
&&
required_size
<=
avail_size
)
{
{
ptr
=
buff_vec
[
i
].
get_ptr
();
(
*
ptr
)
=
buff_vec
[
i
].
get_ptr
();
buff_vec
[
i
].
set_status
(
false
);
return
i
;
return
i
;
}
}
}
}
...
@@ -306,19 +345,20 @@ int memory_pipe<buf_choose_policy::sorted_vec>::get_buffer(const size_t required
...
@@ -306,19 +345,20 @@ int memory_pipe<buf_choose_policy::sorted_vec>::get_buffer(const size_t required
std
::
function
<
bool
(
const
size_t
,
const
buffer
<
mem
>&
)
>
comparator
=
size_comparator
<
mem
>
;
std
::
function
<
bool
(
const
size_t
,
const
buffer
<
mem
>&
)
>
comparator
=
size_comparator
<
mem
>
;
buf_it
=
get_upper_bound
<
mem
>
(
buff_vec
.
begin
(),
buff_vec
.
end
(),
required_size
,
comparator
);
buf_it
=
get_upper_bound
<
mem
>
(
buff_vec
.
begin
(),
buff_vec
.
end
(),
required_size
,
comparator
);
buf_it
=
buff_vec
.
insert
(
buf_it
,
buffer
<
mem
>
(
required_size
));
buf_it
=
buff_vec
.
insert
(
buf_it
,
buffer
<
mem
>
(
required_size
));
ptr
=
buf_it
->
get_ptr
();
(
*
ptr
)
=
buf_it
->
get_ptr
();
int
id
=
std
::
distance
(
buff_vec
.
begin
(),
buf_it
);
int
id
=
std
::
distance
(
buff_vec
.
begin
(),
buf_it
);
buff_vec
.
back
().
set_id
(
id
);
return
id
;
return
id
;
}
}
template
int
memory_pipe
<
buf_choose_policy
::
sorted_vec
>
::
get_buffer
<
MemType
::
CPU
>
(
const
size_t
required_size
,
void
*
&
ptr
);
template
int
memory_pipe
<
buf_choose_policy
::
sorted_vec
>
::
get_buffer
<
MemType
::
CPU
>
(
const
size_t
required_size
,
void
*
*
ptr
);
#ifdef INCLUDE_CUDA
#ifdef INCLUDE_CUDA
template
int
memory_pipe
<
buf_choose_policy
::
sorted_vec
>
::
get_buffer
<
MemType
::
GPU
>
(
const
size_t
required_size
,
void
*
&
ptr
);
template
int
memory_pipe
<
buf_choose_policy
::
sorted_vec
>
::
get_buffer
<
MemType
::
GPU
>
(
const
size_t
required_size
,
void
*
*
ptr
);
#endif
#endif
// template< >
template
<
MemType
mem
>
template
<
MemType
mem
>
int
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>::
get_buffer
(
const
size_t
required_size
,
void
*
&
ptr
)
int
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>::
get_buffer
(
const
size_t
required_size
,
void
*
*
ptr
)
{
{
std
::
vector
<
buffer
<
mem
>
>&
buff_vec
=
get_memtyped_vector
<
mem
>
();
std
::
vector
<
buffer
<
mem
>
>&
buff_vec
=
get_memtyped_vector
<
mem
>
();
typename
std
::
vector
<
buffer
<
mem
>>::
iterator
available_buf_it
;
typename
std
::
vector
<
buffer
<
mem
>>::
iterator
available_buf_it
;
...
@@ -326,42 +366,44 @@ int memory_pipe<buf_choose_policy::find_best_unsorted>::get_buffer(const size_t
...
@@ -326,42 +366,44 @@ int memory_pipe<buf_choose_policy::find_best_unsorted>::get_buffer(const size_t
available_buf_it
=
get_lower_bound
<
mem
>
(
buff_vec
.
begin
(),
buff_vec
.
end
(),
required_size
,
comparator
);
available_buf_it
=
get_lower_bound
<
mem
>
(
buff_vec
.
begin
(),
buff_vec
.
end
(),
required_size
,
comparator
);
if
(
available_buf_it
!=
buff_vec
.
end
())
if
(
available_buf_it
!=
buff_vec
.
end
())
{
{
ptr
=
available_buf_it
->
get_ptr
();
(
*
ptr
)
=
available_buf_it
->
get_ptr
();
int
id
=
std
::
distance
(
buff_vec
.
begin
(),
available_buf_it
);
int
id
=
std
::
distance
(
buff_vec
.
begin
(),
available_buf_it
);
buff_vec
[
id
].
set_status
(
false
);
return
id
;
return
id
;
}
}
else
else
{
{
buff_vec
.
push_back
(
buffer
<
mem
>
(
required_size
));
buff_vec
.
push_back
(
buffer
<
mem
>
(
required_size
));
ptr
=
buff_vec
.
back
().
get_ptr
();
(
*
ptr
)
=
buff_vec
.
back
().
get_ptr
();
int
id
=
buff_vec
.
size
()
-
1
;
int
id
=
buff_vec
.
size
()
-
1
;
buff_vec
.
back
().
set_id
(
id
);
return
id
;
return
id
;
}
}
}
}
template
int
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>
::
get_buffer
<
MemType
::
CPU
>
(
const
size_t
required_size
,
void
*
&
ptr
);
template
int
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>
::
get_buffer
<
MemType
::
CPU
>
(
const
size_t
required_size
,
void
*
*
ptr
);
#ifdef INCLUDE_CUDA
#ifdef INCLUDE_CUDA
template
int
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>
::
get_buffer
<
MemType
::
GPU
>
(
const
size_t
required_size
,
void
*
&
ptr
);
template
int
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>
::
get_buffer
<
MemType
::
GPU
>
(
const
size_t
required_size
,
void
*
*
ptr
);
#endif
#endif
template
<
>
template
<
>
memory_pipe
<
buf_choose_policy
::
naiv
>&
memory_faucet
::
get_faucet
()
memory_pipe
<
buf_choose_policy
::
naiv
e
>&
memory_faucet
::
get_faucet
()
{
{
static
memory_pipe
<
buf_choose_policy
::
naiv
>
mem_pipe_naiv
;
static
memory_pipe
<
buf_choose_policy
::
naiv
e
>
mem_pipe_naiv
e
=
memory_pipe
<
buf_choose_policy
::
naive
>
()
;
return
mem_pipe_naiv
;
return
mem_pipe_naiv
e
;
}
}
template
<
>
template
<
>
memory_pipe
<
buf_choose_policy
::
sorted_vec
>&
memory_faucet
::
get_faucet
()
memory_pipe
<
buf_choose_policy
::
sorted_vec
>&
memory_faucet
::
get_faucet
()
{
{
static
memory_pipe
<
buf_choose_policy
::
sorted_vec
>
mem_pipe_sorted
;
static
memory_pipe
<
buf_choose_policy
::
sorted_vec
>
mem_pipe_sorted
=
memory_pipe
<
buf_choose_policy
::
sorted_vec
>
()
;
return
mem_pipe_sorted
;
return
mem_pipe_sorted
;
}
}
template
<
>
template
<
>
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>&
memory_faucet
::
get_faucet
()
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>&
memory_faucet
::
get_faucet
()
{
{
static
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>
mem_pipe_unsorted
;
static
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>
mem_pipe_unsorted
=
memory_pipe
<
buf_choose_policy
::
find_best_unsorted
>
()
;
return
mem_pipe_unsorted
;
return
mem_pipe_unsorted
;
}
}
...
@@ -370,7 +412,7 @@ template< MemType mem, buf_choose_policy choose_type >
...
@@ -370,7 +412,7 @@ template< MemType mem, buf_choose_policy choose_type >
memBuf
<
mem
,
choose_type
>::
memBuf
(
const
size_t
required_size
)
memBuf
<
mem
,
choose_type
>::
memBuf
(
const
size_t
required_size
)
{
{
memory_pipe
<
choose_type
>&
mem_pipe
=
memory_faucet
::
get_faucet
<
choose_type
>
();
memory_pipe
<
choose_type
>&
mem_pipe
=
memory_faucet
::
get_faucet
<
choose_type
>
();
id
=
mem_pipe
.
template
get_buffer
<
mem
>(
required_size
,
buf
);
id
=
mem_pipe
.
template
get_buffer
<
mem
>(
required_size
,
&
buf
);
size
=
required_size
;
size
=
required_size
;
}
}
...
@@ -379,6 +421,7 @@ memBuf<mem, choose_type>::~memBuf()
...
@@ -379,6 +421,7 @@ memBuf<mem, choose_type>::~memBuf()
{
{
memory_pipe
<
choose_type
>&
mem_pipe
=
memory_faucet
::
get_faucet
<
choose_type
>
();
memory_pipe
<
choose_type
>&
mem_pipe
=
memory_faucet
::
get_faucet
<
choose_type
>
();
mem_pipe
.
template
set_available
<
mem
>(
id
);
mem_pipe
.
template
set_available
<
mem
>(
id
);
buf
=
nullptr
;
}
}
template
<
MemType
mem
,
buf_choose_policy
choose_type
>
template
<
MemType
mem
,
buf_choose_policy
choose_type
>
...
@@ -393,12 +436,12 @@ int memBuf<mem, choose_type>::get_size()
...
@@ -393,12 +436,12 @@ int memBuf<mem, choose_type>::get_size()
return
size
;
return
size
;
}
}
template
class
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
naiv
>;
template
class
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
naiv
e
>;
template
class
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
sorted_vec
>;
template
class
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
sorted_vec
>;
template
class
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
find_best_unsorted
>;
template
class
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
find_best_unsorted
>;
#ifdef INCLUDE_CUDA
#ifdef INCLUDE_CUDA
template
class
memBuf
<
MemType
::
GPU
,
buf_choose_policy
::
naiv
>;
template
class
memBuf
<
MemType
::
GPU
,
buf_choose_policy
::
naiv
e
>;
template
class
memBuf
<
MemType
::
GPU
,
buf_choose_policy
::
sorted_vec
>;
template
class
memBuf
<
MemType
::
GPU
,
buf_choose_policy
::
sorted_vec
>;
template
class
memBuf
<
MemType
::
GPU
,
buf_choose_policy
::
find_best_unsorted
>;
template
class
memBuf
<
MemType
::
GPU
,
buf_choose_policy
::
find_best_unsorted
>;
#endif
#endif
This diff is collapsed.
Click to expand it.
Lib/memory-faucet.h
+
13
−
10
View file @
304cd577
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
enum
class
buf_choose_policy
enum
class
buf_choose_policy
{
{
naiv
,
naiv
e
,
sorted_vec
,
sorted_vec
,
find_best_unsorted
find_best_unsorted
};
};
...
@@ -15,15 +15,15 @@ enum class buf_choose_policy
...
@@ -15,15 +15,15 @@ enum class buf_choose_policy
template
<
MemType
mem
>
template
<
MemType
mem
>
class
buffer
class
buffer
{
{
p
rivate
:
p
ublic
:
void
*
ptr
;
void
*
ptr
;
size_t
allocated_size
;
size_t
allocated_size
;
size_t
scalar_size
;
size_t
scalar_size
;
bool
is_free
;
bool
is_free
;
int
id
;
int
id
;
public:
buffer
(
const
buffer
<
mem
>&
other
);
buffer
(
const
buffer
<
mem
>&
other
);
buffer
(
buffer
<
mem
>&&
other
);
buffer
();
buffer
();
~
buffer
();
~
buffer
();
buffer
(
const
size_t
required_size
);
buffer
(
const
size_t
required_size
);
...
@@ -33,12 +33,15 @@ public:
...
@@ -33,12 +33,15 @@ public:
bool
get_status
()
const
;
bool
get_status
()
const
;
size_t
get_size
()
const
;
size_t
get_size
()
const
;
int
get_id
()
const
;
int
get_id
()
const
;
buffer
<
mem
>&
operator
=
(
buffer
<
mem
>&
other
);
buffer
<
mem
>&
operator
=
(
const
buffer
<
mem
>&
other
);
buffer
<
mem
>&
operator
=
(
const
buffer
<
mem
>&
other
);
buffer
<
mem
>&
operator
=
(
buffer
<
mem
>&&
other
);
void
reallocate
(
const
size_t
required_size
);
void
reallocate
(
const
size_t
required_size
);
void
set_allocated_size
(
const
size_t
required_size
);
void
set_allocated_size
(
const
size_t
required_size
);
void
set_status
(
const
bool
status
);
void
set_status
(
const
bool
status
);
void
set_id
(
const
int
id
);
void
set_id
(
const
int
id
);
void
set_null_pointer
();
};
};
class
memory_pipe_base
class
memory_pipe_base
...
@@ -59,7 +62,7 @@ public:
...
@@ -59,7 +62,7 @@ public:
std
::
vector
<
buffer
<
mem
>
>&
get_memtyped_vector
();
std
::
vector
<
buffer
<
mem
>
>&
get_memtyped_vector
();
};
};
template
<
buf_choose_policy
choose_type
=
buf_choose_policy
::
naiv
>
template
<
buf_choose_policy
choose_type
=
buf_choose_policy
::
naiv
e
>
class
memory_pipe
:
public
memory_pipe_base
class
memory_pipe
:
public
memory_pipe_base
{
{
public:
public:
...
@@ -67,7 +70,7 @@ public:
...
@@ -67,7 +70,7 @@ public:
~
memory_pipe
()
=
default
;
~
memory_pipe
()
=
default
;
template
<
MemType
mem
>
template
<
MemType
mem
>
int
get_buffer
(
const
size_t
required_size
,
void
*
&
ptr
);
int
get_buffer
(
const
size_t
required_size
,
void
*
*
ptr
);
};
};
template
<
>
template
<
>
...
@@ -78,7 +81,7 @@ public:
...
@@ -78,7 +81,7 @@ public:
~
memory_pipe
()
=
default
;
~
memory_pipe
()
=
default
;
template
<
MemType
mem
>
template
<
MemType
mem
>
int
get_buffer
(
const
size_t
required_size
,
void
*
&
ptr
);
int
get_buffer
(
const
size_t
required_size
,
void
*
*
ptr
);
};
};
template
<
>
template
<
>
...
@@ -89,7 +92,7 @@ public:
...
@@ -89,7 +92,7 @@ public:
~
memory_pipe
()
=
default
;
~
memory_pipe
()
=
default
;
template
<
MemType
mem
>
template
<
MemType
mem
>
int
get_buffer
(
const
size_t
required_size
,
void
*
&
ptr
);
int
get_buffer
(
const
size_t
required_size
,
void
*
*
ptr
);
};
};
class
memory_faucet
class
memory_faucet
...
@@ -101,11 +104,11 @@ private:
...
@@ -101,11 +104,11 @@ private:
public:
public:
template
<
buf_choose_policy
choose_type
=
buf_choose_policy
::
naiv
>
template
<
buf_choose_policy
choose_type
=
buf_choose_policy
::
naiv
e
>
static
memory_pipe
<
choose_type
>&
get_faucet
();
static
memory_pipe
<
choose_type
>&
get_faucet
();
};
};
template
<
MemType
mem
,
buf_choose_policy
choose_type
=
buf_choose_policy
::
naiv
>
template
<
MemType
mem
,
buf_choose_policy
choose_type
=
buf_choose_policy
::
naiv
e
>
class
memBuf
class
memBuf
{
{
private:
private:
...
...
This diff is collapsed.
Click to expand it.
main.cpp
+
39
−
9
View file @
304cd577
#include
"memory-faucet.h"
#include
"memory-faucet.h"
#include
<cstdio>
#include
<cstdio>
int
main
(
void
)
int
main
(
void
)
{
{
const
size_t
required_size
=
sizeof
(
float
)
*
100
;
const
size_t
required_size1
=
sizeof
(
float
)
*
100
;
const
size_t
required_size2
=
sizeof
(
float
)
*
1
;
const
size_t
required_size3
=
sizeof
(
float
)
*
10000
;
const
size_t
required_size5
=
sizeof
(
float
)
*
100000
;
const
size_t
required_size6
=
sizeof
(
float
)
*
100000000
;
// printf("required_size %ld\n", required_size);
// printf("required_size %ld\n", required_size);
memBuf
<
MemType
::
CPU
>
Buf1
(
required_size
);
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
sorted_vec
>
Buf2
(
required_size
);
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
find_best_unsorted
>
Buf3
(
required_size
);
// memBuf<MemType::GPU> Buf_gpu(required_size);
float
*
ptr
=
static_cast
<
float
*>
(
Buf1
.
ptr
());
printf
(
"Start Buf1
\n
"
);
// float* ptr_gpu = static_cast<float*>(Buf_gpu.ptr());
memBuf
<
MemType
::
CPU
>
Buf1
(
required_size3
);
// memBuf<MemType::CPU> Buf2(required_size3);
printf
(
"Start Buf2
\n
"
);
memBuf
<
MemType
::
CPU
>
Buf2
(
required_size3
);
// memBuf<MemType::CPU, buf_choose_policy::find_best_unsorted> Buf3(required_size3);
printf
(
"Start Buf4
\n
"
);
memBuf
<
MemType
::
CPU
>
Buf4
(
required_size1
);
printf
(
"Start Buf5
\n
"
);
memBuf
<
MemType
::
CPU
>
Buf5
(
required_size5
);
printf
(
"Start Buf6
\n
"
);
memBuf
<
MemType
::
CPU
>
Buf6
(
required_size6
);
printf
(
"Start Buf7
\n
"
);
memBuf
<
MemType
::
GPU
>
Buf7
(
required_size6
);
for
(
int
i
=
0
;
i
<
100
;
i
++
)
float
*
ptr1
=
static_cast
<
float
*>
(
Buf1
.
ptr
());
float
*
ptr2
=
static_cast
<
float
*>
(
Buf2
.
ptr
());
float
*
ptr4
=
static_cast
<
float
*>
(
Buf4
.
ptr
());
float
*
ptr6
=
static_cast
<
float
*>
(
Buf6
.
ptr
());
printf
(
"Address of Buf1 is %p
\n
"
,
Buf1
.
ptr
());
printf
(
"Address of Buf2 is %p
\n
"
,
Buf2
.
ptr
());
printf
(
"Address of Buf4 is %p
\n
"
,
Buf4
.
ptr
());
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
{
ptr
[
i
]
=
float
(
i
);
ptr1
[
i
]
=
float
(
i
);
ptr2
[
i
]
=
float
(
i
);
ptr4
[
i
]
=
float
(
i
);
ptr6
[
i
]
=
float
(
i
);
}
}
return
0
;
}
}
\ No newline at end of file
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