Skip to content
Snippets Groups Projects
Commit 7b0f6961 authored by 数学の武士's avatar 数学の武士
Browse files

.

parent 866b28c6
No related branches found
No related tags found
No related merge requests found
...@@ -3,9 +3,8 @@ ...@@ -3,9 +3,8 @@
#ifdef INCLUDE_CUDA #ifdef INCLUDE_CUDA
#include "MemoryProcessing.cuh" #include "MemoryProcessing.cuh"
#endif #endif
#include <cstdio>
#include <algorithm> #include <algorithm>
#include<stdio.h>
template< MemType mem > template< MemType mem >
buffer<mem>::buffer() buffer<mem>::buffer()
...@@ -39,18 +38,11 @@ template< MemType mem > ...@@ -39,18 +38,11 @@ template< MemType mem >
buffer<mem>::buffer(const size_t required_size) buffer<mem>::buffer(const size_t required_size)
{ {
allocated_size = 0; allocated_size = 0;
// printf("required_size in constructor %ld\n", required_size);
reallocate(required_size); reallocate(required_size);
// printf("allocated_size in constructor %ld\n", allocated_size);
scalar_size = 0; scalar_size = 0;
is_free = false; 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 > template< MemType mem >
bool free_size_comparator(const buffer<mem>& obj, const size_t required_size) bool free_size_comparator(const buffer<mem>& obj, const size_t required_size)
{ {
...@@ -110,8 +102,6 @@ template< MemType mem > ...@@ -110,8 +102,6 @@ template< MemType mem >
buffer<mem>::buffer(const buffer<mem>& other) buffer<mem>::buffer(const buffer<mem>& other)
{ {
allocated_size = 0; allocated_size = 0;
// printf("Here in copy construct\n");
// printf("allocated_size %ld\n", other.get_size());
reallocate(other.get_size()); reallocate(other.get_size());
is_free = other.get_status(); is_free = other.get_status();
id = other.get_id(); id = other.get_id();
...@@ -120,8 +110,6 @@ buffer<mem>::buffer(const buffer<mem>& other) ...@@ -120,8 +110,6 @@ buffer<mem>::buffer(const buffer<mem>& other)
template< MemType mem > template< MemType mem >
buffer<mem>& buffer<mem>::operator=(buffer<mem>& other) buffer<mem>& buffer<mem>::operator=(buffer<mem>& other)
{ {
// printf("Here in swap\n");
if (this == &other) if (this == &other)
return *this; return *this;
...@@ -136,7 +124,6 @@ buffer<mem>& buffer<mem>::operator=(buffer<mem>& other) ...@@ -136,7 +124,6 @@ buffer<mem>& buffer<mem>::operator=(buffer<mem>& other)
template< MemType mem > template< MemType mem >
buffer<mem>& buffer<mem>::operator=(const buffer<mem>& other) buffer<mem>& buffer<mem>::operator=(const buffer<mem>& other)
{ {
printf("Here in not swap\n");
if (this == &other) if (this == &other)
return *this; return *this;
...@@ -197,7 +184,8 @@ std::vector<buffer<MemType::GPU> >& memory_pipline_base::get_memtyped_vector() ...@@ -197,7 +184,8 @@ std::vector<buffer<MemType::GPU> >& memory_pipline_base::get_memtyped_vector()
template< MemType mem > template< MemType mem >
void memory_pipline_base::set_available(const int id) 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); template void memory_pipline_base::set_available<MemType::CPU>(const int id);
...@@ -275,7 +263,7 @@ template<buf_choose_policy choose_type> ...@@ -275,7 +263,7 @@ template<buf_choose_policy choose_type>
template< MemType mem > template< MemType mem >
int memory_pipline<choose_type>::get_buffer(const size_t required_size, void *& ptr) 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(); const int allocated_buffer_n = buff_vec.size();
for (int i = 0; i < allocated_buffer_n; i++) 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 *& ...@@ -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)); buff_vec.push_back(buffer<mem>(required_size));
ptr = buff_vec.back().get_ptr(); ptr = buff_vec.back().get_ptr();
// printf("buff_vec.size() %d\n", buff_vec.size());
int id = buff_vec.size() - 1; int id = buff_vec.size() - 1;
return id; return id;
} }
...@@ -303,7 +292,7 @@ template int memory_pipline<buf_choose_policy::naiv>::get_buffer<MemType::GPU>(c ...@@ -303,7 +292,7 @@ template int memory_pipline<buf_choose_policy::naiv>::get_buffer<MemType::GPU>(c
template< MemType mem > template< MemType mem >
int memory_pipline<buf_choose_policy::sorted_vec>::get_buffer(const size_t required_size, void *& ptr) 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(); const int allocated_buffer_n = buff_vec.size();
for (int i = 0; i < allocated_buffer_n; i++) 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:: ...@@ -335,7 +324,7 @@ template int memory_pipline<buf_choose_policy::sorted_vec>::get_buffer<MemType::
template< MemType mem > template< MemType mem >
int memory_pipline<buf_choose_policy::find_best_unsorted>::get_buffer(const size_t required_size, void *& ptr) 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; typename std::vector<buffer<mem>>::iterator available_buf_it;
std::function<bool (const buffer<mem>&, const size_t) > comparator = free_size_comparator<mem>; 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); 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) ...@@ -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>(); memory_pipline<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);
// printf("mem %d, choose_type %d, kkddd %d\n", mem, choose_type, mem_pipe->template get_memtyped_vector<mem>().size());
size = required_size; size = required_size;
} }
template< MemType mem, buf_choose_policy choose_type > template< MemType mem, buf_choose_policy choose_type >
memBuf<mem, choose_type>::~memBuf() memBuf<mem, choose_type>::~memBuf()
{ {
// memory_pipline<choose_type>* mem_pipe = memory_faucet::get_faucet<choose_type>(); memory_pipline<choose_type>* mem_pipe = memory_faucet::get_faucet<choose_type>();
// mem_pipe->template set_available<mem>(id); // 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 > template< MemType mem, buf_choose_policy choose_type >
......
...@@ -57,16 +57,19 @@ public: ...@@ -57,16 +57,19 @@ public:
template< MemType mem > template< MemType mem >
std::vector<buffer<mem> >& get_memtyped_vector(); 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> template<buf_choose_policy choose_type = buf_choose_policy::naiv>
class memory_pipline: public memory_pipline_base class memory_pipline: public memory_pipline_base
{ {
private: // private:
#ifdef INCLUDE_CUDA // #ifdef INCLUDE_CUDA
using memory_pipline_base::gpu_buff; // using memory_pipline_base::gpu_buff;
#endif // #endif
using memory_pipline_base::cpu_buff; // using memory_pipline_base::cpu_buff;
public: public:
memory_pipline(/* args */) : memory_pipline_base() {} memory_pipline(/* args */) : memory_pipline_base() {}
~memory_pipline() = default; ~memory_pipline() = default;
...@@ -78,11 +81,11 @@ public: ...@@ -78,11 +81,11 @@ public:
template<> template<>
class memory_pipline<buf_choose_policy::sorted_vec>: public memory_pipline_base class memory_pipline<buf_choose_policy::sorted_vec>: public memory_pipline_base
{ {
private: // private:
#ifdef INCLUDE_CUDA // #ifdef INCLUDE_CUDA
using memory_pipline_base::gpu_buff; // using memory_pipline_base::gpu_buff;
#endif // #endif
using memory_pipline_base::cpu_buff; // using memory_pipline_base::cpu_buff;
public: public:
memory_pipline(/* args */) : memory_pipline_base() {} memory_pipline(/* args */) : memory_pipline_base() {}
~memory_pipline() = default; ~memory_pipline() = default;
...@@ -94,11 +97,11 @@ public: ...@@ -94,11 +97,11 @@ public:
template<> template<>
class memory_pipline<buf_choose_policy::find_best_unsorted>: public memory_pipline_base class memory_pipline<buf_choose_policy::find_best_unsorted>: public memory_pipline_base
{ {
private: // private:
#ifdef INCLUDE_CUDA // #ifdef INCLUDE_CUDA
using memory_pipline_base::gpu_buff; // using memory_pipline_base::gpu_buff;
#endif // #endif
using memory_pipline_base::cpu_buff; // using memory_pipline_base::cpu_buff;
public: public:
memory_pipline(/* args */) : memory_pipline_base() {} memory_pipline(/* args */) : memory_pipline_base() {}
~memory_pipline() = default; ~memory_pipline() = default;
......
...@@ -4,10 +4,12 @@ int main(void) ...@@ -4,10 +4,12 @@ int main(void)
{ {
const size_t required_size = sizeof(float) * 100; const size_t required_size = sizeof(float) * 100;
// printf("required_size %ld\n", required_size); // 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); // memBuf<MemType::GPU> Buf_gpu(required_size);
float* ptr = static_cast<float*>(Buf.ptr()); float* ptr = static_cast<float*>(Buf1.ptr());
// float* ptr_gpu = static_cast<float*>(Buf_gpu.ptr()); // float* ptr_gpu = static_cast<float*>(Buf_gpu.ptr());
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment