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
7b0f6961
Commit
7b0f6961
authored
4 months ago
by
数学の武士
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
866b28c6
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Lib/memory-holder.cpp
+11
-20
11 additions, 20 deletions
Lib/memory-holder.cpp
Lib/memory-holder.h
+18
-15
18 additions, 15 deletions
Lib/memory-holder.h
main.cpp
+4
-2
4 additions, 2 deletions
main.cpp
with
33 additions
and
37 deletions
Lib/memory-holder.cpp
+
11
−
20
View file @
7b0f6961
...
...
@@ -3,9 +3,8 @@
#ifdef INCLUDE_CUDA
#include
"MemoryProcessing.cuh"
#endif
#include
<cstdio>
#include
<algorithm>
#include
<stdio.h>
template
<
MemType
mem
>
buffer
<
mem
>::
buffer
()
...
...
@@ -39,18 +38,11 @@ template< MemType mem >
buffer
<
mem
>::
buffer
(
const
size_t
required_size
)
{
allocated_size
=
0
;
// printf("required_size in constructor %ld\n", required_size);
reallocate
(
required_size
);
// printf("allocated_size in constructor %ld\n", allocated_size);
scalar_size
=
0
;
is_free
=
false
;
}
// typedef bool (*Fun)(const buffer<MemType::CPU>&, const size_t);
// #ifdef INCLUDE_CUDA
// typedef bool (*Fun)(const buffer<MemType::GPU>&, const size_t);
// #endif
template
<
MemType
mem
>
bool
free_size_comparator
(
const
buffer
<
mem
>&
obj
,
const
size_t
required_size
)
{
...
...
@@ -110,8 +102,6 @@ template< MemType mem >
buffer
<
mem
>::
buffer
(
const
buffer
<
mem
>&
other
)
{
allocated_size
=
0
;
// printf("Here in copy construct\n");
// printf("allocated_size %ld\n", other.get_size());
reallocate
(
other
.
get_size
());
is_free
=
other
.
get_status
();
id
=
other
.
get_id
();
...
...
@@ -120,8 +110,6 @@ buffer<mem>::buffer(const buffer<mem>& other)
template
<
MemType
mem
>
buffer
<
mem
>&
buffer
<
mem
>::
operator
=
(
buffer
<
mem
>&
other
)
{
// printf("Here in swap\n");
if
(
this
==
&
other
)
return
*
this
;
...
...
@@ -136,7 +124,6 @@ buffer<mem>& buffer<mem>::operator=(buffer<mem>& other)
template
<
MemType
mem
>
buffer
<
mem
>&
buffer
<
mem
>::
operator
=
(
const
buffer
<
mem
>&
other
)
{
printf
(
"Here in not swap
\n
"
);
if
(
this
==
&
other
)
return
*
this
;
...
...
@@ -197,7 +184,8 @@ std::vector<buffer<MemType::GPU> >& memory_pipline_base::get_memtyped_vector()
template
<
MemType
mem
>
void
memory_pipline_base
::
set_available
(
const
int
id
)
{
get_memtyped_vector
<
mem
>
()[
id
].
set_status
(
true
);
// printf("Id %d, size = %d\n", id, get_memtyped_vector<mem>().size());
get_memtyped_vector
<
mem
>
()[
id
].
set_status
(
true
);
}
template
void
memory_pipline_base
::
set_available
<
MemType
::
CPU
>(
const
int
id
);
...
...
@@ -275,7 +263,7 @@ template<buf_choose_policy choose_type>
template
<
MemType
mem
>
int
memory_pipline
<
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
();
for
(
int
i
=
0
;
i
<
allocated_buffer_n
;
i
++
)
{
...
...
@@ -291,6 +279,7 @@ int memory_pipline<choose_type>::get_buffer(const size_t required_size, void *&
buff_vec
.
push_back
(
buffer
<
mem
>
(
required_size
));
ptr
=
buff_vec
.
back
().
get_ptr
();
// printf("buff_vec.size() %d\n", buff_vec.size());
int
id
=
buff_vec
.
size
()
-
1
;
return
id
;
}
...
...
@@ -303,7 +292,7 @@ template int memory_pipline<buf_choose_policy::naiv>::get_buffer<MemType::GPU>(c
template
<
MemType
mem
>
int
memory_pipline
<
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
();
for
(
int
i
=
0
;
i
<
allocated_buffer_n
;
i
++
)
{
...
...
@@ -335,7 +324,7 @@ template int memory_pipline<buf_choose_policy::sorted_vec>::get_buffer<MemType::
template
<
MemType
mem
>
int
memory_pipline
<
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
;
std
::
function
<
bool
(
const
buffer
<
mem
>&
,
const
size_t
)
>
comparator
=
free_size_comparator
<
mem
>
;
available_buf_it
=
get_lower_bound
<
mem
>
(
buff_vec
.
begin
(),
buff_vec
.
end
(),
required_size
,
comparator
);
...
...
@@ -402,14 +391,16 @@ memBuf<mem, choose_type>::memBuf(const size_t required_size)
{
memory_pipline
<
choose_type
>*
mem_pipe
=
memory_faucet
::
get_faucet
<
choose_type
>
();
id
=
mem_pipe
->
template
get_buffer
<
mem
>(
required_size
,
buf
);
// printf("mem %d, choose_type %d, kkddd %d\n", mem, choose_type, mem_pipe->template get_memtyped_vector<mem>().size());
size
=
required_size
;
}
template
<
MemType
mem
,
buf_choose_policy
choose_type
>
memBuf
<
mem
,
choose_type
>::~
memBuf
()
{
// memory_pipline<choose_type>* mem_pipe = memory_faucet::get_faucet<choose_type>();
// mem_pipe->template set_available<mem>(id);
memory_pipline
<
choose_type
>*
mem_pipe
=
memory_faucet
::
get_faucet
<
choose_type
>
();
// printf("mem %d, choose_type %d, kk %d\n", mem, choose_type, mem_pipe->template get_memtyped_vector<mem>().size());
mem_pipe
->
template
set_available
<
mem
>(
id
);
}
template
<
MemType
mem
,
buf_choose_policy
choose_type
>
...
...
This diff is collapsed.
Click to expand it.
Lib/memory-holder.h
+
18
−
15
View file @
7b0f6961
...
...
@@ -57,16 +57,19 @@ public:
template
<
MemType
mem
>
std
::
vector
<
buffer
<
mem
>
>&
get_memtyped_vector
();
// template< MemType mem >
// std::vector<buffer<mem> >& get_memtyped_vector();
};
template
<
buf_choose_policy
choose_type
=
buf_choose_policy
::
naiv
>
class
memory_pipline
:
public
memory_pipline_base
{
private:
#ifdef INCLUDE_CUDA
using
memory_pipline_base
::
gpu_buff
;
#endif
using
memory_pipline_base
::
cpu_buff
;
//
private:
//
#ifdef INCLUDE_CUDA
//
using memory_pipline_base::gpu_buff;
//
#endif
//
using memory_pipline_base::cpu_buff;
public:
memory_pipline
(
/* args */
)
:
memory_pipline_base
()
{}
~
memory_pipline
()
=
default
;
...
...
@@ -78,11 +81,11 @@ public:
template
<
>
class
memory_pipline
<
buf_choose_policy
::
sorted_vec
>:
public
memory_pipline_base
{
private:
#ifdef INCLUDE_CUDA
using
memory_pipline_base
::
gpu_buff
;
#endif
using
memory_pipline_base
::
cpu_buff
;
//
private:
//
#ifdef INCLUDE_CUDA
//
using memory_pipline_base::gpu_buff;
//
#endif
//
using memory_pipline_base::cpu_buff;
public:
memory_pipline
(
/* args */
)
:
memory_pipline_base
()
{}
~
memory_pipline
()
=
default
;
...
...
@@ -94,11 +97,11 @@ public:
template
<
>
class
memory_pipline
<
buf_choose_policy
::
find_best_unsorted
>:
public
memory_pipline_base
{
private:
#ifdef INCLUDE_CUDA
using
memory_pipline_base
::
gpu_buff
;
#endif
using
memory_pipline_base
::
cpu_buff
;
//
private:
//
#ifdef INCLUDE_CUDA
//
using memory_pipline_base::gpu_buff;
//
#endif
//
using memory_pipline_base::cpu_buff;
public:
memory_pipline
(
/* args */
)
:
memory_pipline_base
()
{}
~
memory_pipline
()
=
default
;
...
...
This diff is collapsed.
Click to expand it.
main.cpp
+
4
−
2
View file @
7b0f6961
...
...
@@ -4,10 +4,12 @@ int main(void)
{
const
size_t
required_size
=
sizeof
(
float
)
*
100
;
// printf("required_size %ld\n", required_size);
memBuf
<
MemType
::
CPU
,
buf_choose_policy
::
find_best_unsorted
>
Buf
(
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
*>
(
Buf
.
ptr
());
float
*
ptr
=
static_cast
<
float
*>
(
Buf
1
.
ptr
());
// float* ptr_gpu = static_cast<float*>(Buf_gpu.ptr());
for
(
int
i
=
0
;
i
<
100
;
i
++
)
...
...
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