Commit ad047d6b authored by karius's avatar karius

first Target infrastructure

parent db14c06b
......@@ -23,6 +23,17 @@ FittingProtocol::FittingProtocol() {
_determine_gpu_resources();
}
void FittingProtocol::loadTarget(int gpu_index){
if(gpu_index < _num_devices){
if(_device_memory_infos[gpu_index].free > target.getGpuMem()){
target.loadToGpu(gpu_index);
}
}
else{
std::cout << "Gpu Index " << gpu_index << " does not match the number of devices ..." << std::endl;
}
}
void FittingProtocol::printGPUInfo(void){
printf("Found %i devices ...\n",_num_devices);
printf("-------------------------------------");
......@@ -40,9 +51,9 @@ FittingProtocol::~FittingProtocol() {
void FittingProtocol::setFileTarget(const char * file_name){
if (file_exists(file_name)){
// target = Target::fromMrc(file_name);
target = Target::fromMrc(file_name);
}
else {
// std::cout << "File " << file_name << " is not found ..." << std::endl;
std::cout << "File " << file_name << " is not found ..." << std::endl;
}
}
......@@ -8,7 +8,7 @@
#ifndef FITTINGPROTOCOL_H_
#define FITTINGPROTOCOL_H_
//#include <Target.h>
#include <Target.h>
//#include <Query.h>
//#include <Score.h>
#include <vector>
......@@ -16,6 +16,7 @@
#include <util.h>
#include <nvml.h>
#include <vector>
#include <iostream>
class FittingProtocol {
public:
......@@ -23,7 +24,8 @@ public:
void setFileTarget(const char * file_name);
virtual ~FittingProtocol();
void printGPUInfo(void);
// Target target;
Target target;
void loadTarget(int gpu_index);
// std::vector<Query> queries;
// std::vector<Score> scores;
private:
......
......@@ -33,13 +33,13 @@ protocol:
# nvcc --gpu-architecture=sm_61 --device-link Particles.o PdbReader.o FittingProtocol.o Density.o Target.o CMrcReader.o --output-file link.o -lnvidia-ml $(CUDA_LINKS)
# g++ FittingProtocol.o Particles.o PdbReader.o Target.o Density.o CMrcReader.o ccl_test.o link.o -o protocol -lnvidia-ml -L. $(CUDA_LINKS)
$(info Compiling for device architecture $(DEVICE_ARCH))
nvcc --gpu-architecture=$(DEVICE_ARCH) --include-path=./ --device-c FittingProtocol.cu ccl_test.cu -g -G
nvcc --gpu-architecture=$(DEVICE_ARCH) --device-link FittingProtocol.o ccl_test.o --output-file link.o
g++ FittingProtocol.o ccl_test.o link.o -o protocol -lnvidia-ml -L/usr/local/cuda-10.0/lib64/ -lcudart
nvcc --gpu-architecture=$(DEVICE_ARCH) --include-path=./ --device-c PdbReader.cu Particles.cu CMrcReader.cu Density.cu Target.cu FittingProtocol.cu ccl_test.cu -g -G
nvcc --gpu-architecture=$(DEVICE_ARCH) --device-link PdbReader.o Particles.o CMrcReader.o Density.o Target.o FittingProtocol.o ccl_test.o --output-file link.o
g++ PdbReader.o Particles.o CMrcReader.o Density.o Target.o FittingProtocol.o ccl_test.o link.o -o protocol -lnvidia-ml -L/usr/local/cuda-10.0/lib64/ -lcudart -lcudadevrt
ccl2: CMrcReader.o
nvcc --gpu-architecture=sm_61 --include-path=./ --device-c Density.cu Kernels.cu PdbReader.cu Particles.cu Labeler.cu ccl_test.cu -g -G
nvcc --gpu-architecture=sm_61 --include-path=./ --device-c Particles.cu Density.cu Kernels.cu PdbReader.cu Particles.cu Labeler.cu ccl_test.cu -g -G
nvcc --gpu-architecture=sm_61 --device-link Sampler.o PdbReader.o Particles.o Labeler.o Kernels.o Density.o ccl_test.o --output-file link.o
g++ Sampler.o PdbReader.o Particles.o Labeler.o Kernels.o Density.o CMrcReader.o ccl_test.o link.o -o ccl_test -L. $(CUDA_LINKS) $(BOOST_LINKS)
......
......@@ -16,7 +16,7 @@ struct MemoryResources{
size_t CPU;
};
enum SourceType {MRC,PDB};
enum SourceType {MRC,PDB,NONE};
typedef float TDensity;
#endif /* MEMORYRESOURCES_H_ */
......@@ -21,6 +21,18 @@ size_t Target::getCpuMem(){
return _data_byte_vol;
}
int Target::loadToGpu(int gpu_index){
int ret = 0;
if (!_cpu_initiated){
ret += initCpu();
}
if (!_gpu_initiated){
ret += initGpu(gpu_index);
}
toGpu(gpu_index);
return ret;
}
int Target::initCpu(){
int ret = 0;
if (_source_type == MRC){
......@@ -30,26 +42,33 @@ int Target::initCpu(){
return ret;
}
int Target::initGpu(){
int Target::initGpu(int gpu_index){
int ret = 0;
if (_source_type == MRC){
ret = int(cudaSuccess != cudaMalloc((void **)&_density.d_data,_data_byte_vol));
ret += int(cudaSuccess != cudaSetDevice(gpu_index));
ret += int(cudaSuccess != cudaMalloc((void **)&_density.d_data,_data_byte_vol));
_gpu_initiated = true;
return ret;
}
return 0;
}
int Target::toGpu(){
int Target::toGpu(int gpu_index){
int ret = 0;
if (_source_type == MRC && _cpu_initiated && _gpu_initiated){
return int(cudaSuccess != cudaMemcpy(_density.d_data,_density.d_data,_data_byte_vol,cudaMemcpyHostToDevice));
ret += int(cudaSuccess != cudaSetDevice(gpu_index));
ret += int(cudaSuccess != cudaMemcpy(_density.d_data,_density.d_data,_data_byte_vol,cudaMemcpyHostToDevice));
return ret;
}
return 0;
}
int Target::fromGpu(){
int Target::fromGpu(int gpu_index){
int ret = 0;
if (_source_type == MRC && _cpu_initiated && _gpu_initiated){
return int(cudaSuccess != cudaMemcpy(_density.d_data,_density.d_data,_data_byte_vol,cudaMemcpyDeviceToHost));
ret += int(cudaSuccess != cudaSetDevice(gpu_index));
ret += int(cudaSuccess != cudaMemcpy(_density.d_data,_density.d_data,_data_byte_vol,cudaMemcpyDeviceToHost));
return ret;
}
return 0;
}
......
......@@ -18,15 +18,16 @@ public:
static Target fromMrc(const char * fileName);
size_t getCpuMem();
size_t getGpuMem();
int loadToGpu(int gpu_index);
int initCpu();
int initGpu();
int toGpu();
int fromGpu();
int initGpu(int gpu_index);
int toGpu(int gpu_index);
int fromGpu(int gpu_index);
virtual ~Target();
private:
Density _density;
size_t _data_byte_vol = 0;
SourceType _source_type;
SourceType _source_type = NONE;
bool _cpu_initiated = false;
bool _gpu_initiated = false;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment