-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2c0af9e
Showing
61 changed files
with
6,057 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/************************************************************************* | ||
> File Name: AddStreamTask.h | ||
> Author: | ||
> Mail: | ||
> Created Time: Mon 20 Apr 2015 04:59:12 AM EDT | ||
************************************************************************/ | ||
|
||
#ifndef GET_ADDSTREAMTASK_H | ||
#define GET_ADDSTREAMTASK_H | ||
#include"StreamTask.h" | ||
|
||
template <typename Dtype> | ||
class AddStreamTask: public StreamTask<Dtype> | ||
{ | ||
public: | ||
~AddStreamTask(); | ||
explicit AddStreamTask(BaseDevice* device): | ||
StreamTask<Dtype>(device) | ||
{ | ||
this->data_per_block_ =device->GlobalMemory() / 6; | ||
} | ||
|
||
void PreCompute(); | ||
void Compute(); | ||
void PostCompute(); | ||
void SetParams(int channels, int height, int width) | ||
{ | ||
channels_ = channels; | ||
height_ = height; | ||
width_ = width; | ||
} | ||
protected: | ||
cl_int height_, width_; | ||
int channels_; | ||
|
||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/************************************************************************* | ||
> File Name: AddTask.h | ||
> Author: crows | ||
> Mail: [email protected] | ||
> Created Time: Mon 23 Mar 2015 11:58:50 PM EDT | ||
************************************************************************/ | ||
#ifndef GET_ADD_TASK_HEADER | ||
#define GET_ADD_TASK_HEADER | ||
#include<iostream> | ||
#include<CL/cl.h> | ||
#include"BaseTask.h" | ||
#include"BaseDevice.h" | ||
#include"proto/GET.pb.h" | ||
|
||
using namespace std; | ||
|
||
|
||
//template <typename Dtype> | ||
//using BaseTask<Dtype>::datas_; | ||
//using BaseTask::device_; | ||
//using BaseTask::results_; | ||
//using BaseTask::device_buffers_; | ||
template <typename Dtype> | ||
class AddTask : public BaseTask<Dtype> | ||
{ | ||
public: | ||
~AddTask() {}; | ||
//explicit AddTask(BaseDevice* device) {device_ = device;} | ||
AddTask(BaseDevice* device): | ||
BaseTask<Dtype>(device) | ||
{ | ||
|
||
} | ||
void PreCompute(); | ||
void Compute(); | ||
void PostCompute(); | ||
void SetParams(GET::AddParam param) {}; | ||
void SetParams(int channels, int height, int width) | ||
{ | ||
channels_ = channels; | ||
height_ = (cl_int)height; | ||
width_ = (cl_int)width; | ||
} | ||
|
||
protected: | ||
cl_int height_, width_; | ||
int channels_; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/************************************************************************* | ||
> File Name: ADD_TaskDispatcher.h | ||
> Author: | ||
> Mail: | ||
> Created Time: Mon 13 Apr 2015 03:23:50 AM EDT | ||
************************************************************************/ | ||
|
||
#ifndef GET_ADD_TASKDISPATCHER_H | ||
#define GET_ADD_TASKDISPATCHER_H | ||
#include "TaskDispatcher.h" | ||
|
||
template <typename Dtype> | ||
class AddTaskDispatcher : public TaskDispatcher<Dtype> | ||
{ | ||
public: | ||
~AddTaskDispatcher() {}; | ||
explicit AddTaskDispatcher(GET::TaskParam task_param, DeviceManager* device_manager):TaskDispatcher<Dtype>(task_param, device_manager) | ||
{ | ||
add_param_ = task_param.add_param(); | ||
} | ||
|
||
void PreTaskDispatch(); | ||
void TaskDispatch(); | ||
|
||
protected: | ||
GET::AddParam add_param_; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/************************************************************************* | ||
> File Name: BaseDevice.h | ||
> Author: crows | ||
> Mail: [email protected] | ||
> Created Time: Tue 24 Mar 2015 02:51:11 AM EDT | ||
************************************************************************/ | ||
#ifndef GET_BASE_DEVICE_HEADER | ||
#define GET_BASE_DEVICE_HEADER | ||
#include<iostream> | ||
using namespace std; | ||
#include<vector> | ||
#include<CL/cl.h> | ||
|
||
class BaseDevice | ||
{ | ||
public: | ||
~BaseDevice() {}; | ||
BaseDevice() | ||
:device_id_(), device_type_(), device_ctx_(), device_cmdqueues_(), global_memory_(0), catch_line_size_(0), wavefront_size_(64), max_block_size_(0), max_grid_size_(0) {}; | ||
|
||
explicit BaseDevice(cl_device_id device_id, int device_index, cl_context device_ctx, cl_command_queue device_que1, cl_command_queue device_que2) | ||
{ | ||
device_id_ = device_id; | ||
device_index_ = device_index; | ||
device_ctx_ =device_ctx; | ||
device_cmdqueues_.push_back(device_que1); | ||
if (device_que2 != NULL) | ||
device_cmdqueues_.push_back(device_que2); | ||
} | ||
void Init(); | ||
inline unsigned long GlobalMemory() {return global_memory_;} | ||
inline int WavefrontSize() {return wavefront_size_;} | ||
inline int MaxBlockSize() {return max_block_size_;} | ||
inline size_t* MaxGridSize() {return max_grid_size_;} | ||
inline cl_context DeviceContext() {return device_ctx_;} | ||
inline cl_device_id DeviceID() {return device_id_;} | ||
inline int DeviceIndex() {return device_index_;} | ||
inline cl_command_queue DeviceCmdQueA() {return device_cmdqueues_[0];} | ||
inline cl_command_queue DeviceCmdQueB() {return device_cmdqueues_[1];} | ||
|
||
typedef enum {CPU, GPU} DeviceType; | ||
|
||
protected: | ||
cl_device_id device_id_; | ||
int device_index_; | ||
DeviceType device_type_; | ||
cl_context device_ctx_; | ||
vector<cl_command_queue> device_cmdqueues_; | ||
cl_ulong global_memory_; | ||
cl_uint catch_line_size_; | ||
int wavefront_size_; | ||
int max_block_size_; | ||
size_t* max_grid_size_; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/************************************************************************* | ||
> File Name: BaseTask.h | ||
> Author: crows | ||
> Mail: [email protected] | ||
> Created Time: Mon 23 Mar 2015 11:58:41 PM EDT | ||
************************************************************************/ | ||
#ifndef GET_BASE_TASK_HEADER | ||
#define GET_BASE_TASK_HEADER | ||
#include<iostream> | ||
using namespace std; | ||
#include"BaseDevice.h" | ||
#include"DataBlob.h" | ||
#include<CL/cl.h> | ||
|
||
|
||
template <typename Dtype> | ||
class BaseTask | ||
{ | ||
public: | ||
~BaseTask(); | ||
explicit BaseTask(BaseDevice* device) {device_ = device;} | ||
//function to start Task | ||
void AddtoDatas(DataBlob<Dtype> data); | ||
void AddtoResults(DataBlob<Dtype> data); | ||
|
||
|
||
virtual void PreCompute() {}; | ||
virtual void Compute() {}; | ||
virtual void PostCompute() {}; | ||
//virtual void SetParams(TaskParam param); | ||
|
||
inline void TaskOn() | ||
{ | ||
PreCompute(); | ||
Compute(); | ||
PostCompute(); | ||
} | ||
|
||
protected: | ||
vector<DataBlob<Dtype> > datas_; | ||
BaseDevice* device_; | ||
vector<DataBlob<Dtype> > results_; | ||
vector<cl_mem> device_buffers_; | ||
|
||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/************************************************************************* | ||
> File Name: CommonTask.h | ||
> Author: | ||
> Mail: | ||
> Created Time: Sun 19 Apr 2015 09:58:51 PM EDT | ||
************************************************************************/ | ||
|
||
#ifndef GET_COMMONTASK_H | ||
#define GET_COMMONTASK_H | ||
#include"AddTask.h" | ||
#include"SubTask.h" | ||
#include"AddStreamTask.h" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/************************************************************************* | ||
> File Name: ConvTask.h | ||
> Author: | ||
> Mail: | ||
> Created Time: Thu 23 Apr 2015 09:21:10 AM EDT | ||
************************************************************************/ | ||
|
||
#ifndef GET_CONVTASK_H | ||
#define GET_CONVTASK_H | ||
#include"BaseDevice.h" | ||
#include"DataBlob.h" | ||
#include<CL/cl.h> | ||
#include"proto/GET.pb.h" | ||
|
||
template <typename Dtype> | ||
class ConvTask : public BaseTask<Dtype> | ||
{ | ||
public: | ||
~ConvTask() {}; | ||
ConvTask(BaseDevice* device): | ||
BaseTask<Dtype>(device) | ||
{ | ||
|
||
} | ||
|
||
void PreCompute(); | ||
void Compute(); | ||
void PostCompute(); | ||
void SetParams(GET::ConvParam param); | ||
|
||
protected: | ||
cl_int data_h_, data_w_; | ||
cl_int filter_h_. filter_w_; | ||
cl_int stride_h_, stride_w_; | ||
cl_int pad_h_, pad_w_; | ||
cl_int output_h_, output_w_; | ||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/************************************************************************* | ||
> File Name: DataBlob.h | ||
> Author: crows | ||
> Mail: [email protected] | ||
> Created Time: Tue 24 Mar 2015 03:03:57 AM EDT | ||
************************************************************************/ | ||
#ifndef GET_DATABLOB_HEADER_ | ||
#define GET_DATABLOB_HEADER_ | ||
#include<iostream> | ||
using namespace std; | ||
#include<stdlib.h> | ||
|
||
template <typename Dtype> | ||
|
||
class DataBlob | ||
{ | ||
public: | ||
~DataBlob() {}; | ||
DataBlob() | ||
: num_(0), channels_(0), height_(0), width_(0), capacity_(0), host_data_ptr_(NULL) {} | ||
|
||
// explicit DataBlob(const int n,const int c, const int h, int w, BaseDevice* device); | ||
explicit DataBlob(const int n, const int c, const int h, int w); | ||
explicit DataBlob(void * hd,int n,int c,int h,int w); | ||
void Reshape_HOST(const int n, const int c, const int h, const int w); | ||
void ReshapeLike(const int n, const int c, const int h, const int w); | ||
void CopyFromMemory(void* data); | ||
//void Reshape_DEVICE(const int n, const int c, const int h, const int w); | ||
//void CopyFromCPUtoGPU(); | ||
//void CopyFromGPUtoCPU(); | ||
//void CopyFromDataBlob(); | ||
inline int num() {return num_ ;} | ||
inline int channels() {return channels_ ;} | ||
inline int height() {return height_ ;} | ||
inline int width() {return width_ ;} | ||
inline int count() {return count_;} | ||
inline int offset(const int n, const int c, const int h, const int w) | ||
{ | ||
return ((n*channels() + c)*height() + h)*width()+w; | ||
} | ||
/* | ||
inline Dtype data_at(const int n, const int c, const int h, const int w) const | ||
{ | ||
return ((const Dtype*)host_data())[offset(n, c, h, w)]; | ||
} | ||
*/ | ||
inline void* host_data() {return host_data_ptr_;} | ||
inline void set_host_data(void * host_data){host_data_ptr_ = host_data;} | ||
//inline void* device_data() {return device_data_ptr_;} | ||
enum wh_data {HOST, DEVICE, SYNCED} data_state_; | ||
protected: | ||
int num_; | ||
int channels_; | ||
int height_; | ||
int width_; | ||
int count_; | ||
long capacity_; | ||
void* host_data_ptr_; | ||
//void* device_data_ptr_; | ||
//BaseDevice* device_; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/************************************************************************* | ||
> File Name: DeviceManager.h | ||
> Author: crows | ||
> Mail: [email protected] | ||
> Created Time: Mon 23 Mar 2015 11:59:00 PM EDT | ||
************************************************************************/ | ||
#ifndef GET_DEVICE_MANAGER_HEAD | ||
#define GET_DEVICE_MANAGER_HEAD | ||
#include<iostream> | ||
using namespace std; | ||
#include<map> | ||
#include<string> | ||
#include<CL/cl.h> | ||
#include"BaseDevice.h" | ||
#include<vector> | ||
#include<map> | ||
|
||
class DeviceManager | ||
{ | ||
public: | ||
~DeviceManager() {}; | ||
DeviceManager() | ||
:devices_index_(), devices_status_(), device_info_(),platforms_index_(),platforms_names_() {}; | ||
|
||
void Init(); | ||
BaseDevice* GetAvailableDevice(); | ||
void FreeDevice(int device_index); | ||
string GetDeviceInfo(int device_id); | ||
typedef enum {DEV_IDLE, DEV_BUSY} DeviceStatus; | ||
|
||
map<int, BaseDevice> devices_index_; | ||
map<int, DeviceStatus> devices_status_; | ||
|
||
string device_info_; | ||
vector<cl_platform_id> platforms_index_; | ||
map<int, string> platforms_names_; | ||
|
||
protected : | ||
void InitPlatforms(); | ||
void InitDevices(cl_platform_id platform); | ||
|
||
}; | ||
#endif |
Oops, something went wrong.