diff --git a/GPU_version/vio/include/vio/cl_class.h b/GPU_version/vio/include/vio/cl_class.h index f41b352..bbed7a9 100644 --- a/GPU_version/vio/include/vio/cl_class.h +++ b/GPU_version/vio/include/vio/cl_class.h @@ -56,11 +56,8 @@ public: int32_t reload(size_t id,T* buf,cl::CommandQueue* queue){ for(auto&& i:_buffers)if(i.second==id){ T* Map_buf=(T*)queue->enqueueMapBuffer(i.first.first,CL_TRUE,CL_MAP_WRITE,0,sizeof(T) * i.first.second); - std::cout<<"\n reload class L:59,\t"; memcpy(Map_buf,buf,sizeof(T) * i.first.second); - std::cout<<"L:61\t"; if(queue->enqueueUnmapMemObject(i.first.first,Map_buf)!=CL_SUCCESS)std::cerr<<"Reload buffer on GPU failed"<<'\n'; - std::cout<<"L:63\n"; } return CL_SUCCESS; }; @@ -188,13 +185,9 @@ public: } template void read(size_t id1/*kernal ID*/,size_t id2/*buffer ID*/,size_t size/*size*/, T* out){ - std::cout<<"read GPU line 191\t"; T* Map_buf=(T*)queue->enqueueMapBuffer(_kernels.at(id1).read(id2).first,CL_TRUE,CL_MAP_READ,0,sizeof(T) * size); - std::cout<<"read GPU line 193\t"; memcpy(out,Map_buf,sizeof(T) * size); - std::cout<<"read GPU line 195\t"; if(queue->enqueueUnmapMemObject(_kernels.at(id1).read(id2).first,Map_buf)!=CL_SUCCESS)std::cerr<<"Read buffer on GPU failed"<<'\n'; - std::cout<<"read GPU line 197\t"; } void clear_buf(); private: diff --git a/GPU_version/vio/src/cl_class.cpp b/GPU_version/vio/src/cl_class.cpp index c3af6a1..0a0b5a3 100644 --- a/GPU_version/vio/src/cl_class.cpp +++ b/GPU_version/vio/src/cl_class.cpp @@ -13,7 +13,7 @@ opencl::opencl(vk::AbstractCamera* cam):cam(cam) { std::vector all_devices; for(auto i:all_platforms){ std::cout << "Find platform number:"<< i.getInfo() << "\n"; - i.getDevices(CL_DEVICE_TYPE_GPU, &all_devices); + i.getDevices(CL_DEVICE_TYPE_CPU, &all_devices); } if (all_devices.size() == 0){ diff --git a/GPU_version/vio/src/frame_handler_mono.cpp b/GPU_version/vio/src/frame_handler_mono.cpp index 430f051..b9d9b62 100644 --- a/GPU_version/vio/src/frame_handler_mono.cpp +++ b/GPU_version/vio/src/frame_handler_mono.cpp @@ -167,8 +167,8 @@ FrameHandlerBase::UpdateResult FrameHandlerMono::processFrame() new_frame_->T_f_w_=init_f.second; new_frame_->Cov_ = init_f.first; // sparse image align - //SparseImgAlign img_align(Config::kltMaxLevel(), Config::kltMinLevel(),30, SparseImgAlign::LevenbergMarquardt, false, false); - SparseImgAlignGpu img_align(Config::kltMaxLevel(), Config::kltMinLevel(),30, SparseImgAlignGpu::GaussNewton, false,gpu_fast_); + SparseImgAlign img_align(Config::kltMaxLevel(), Config::kltMinLevel(),30, SparseImgAlign::LevenbergMarquardt, false, false); + //SparseImgAlignGpu img_align(Config::kltMaxLevel(), Config::kltMinLevel(),30, SparseImgAlignGpu::GaussNewton, false,gpu_fast_); if(img_align.run(last_frame_, new_frame_)==0)return RESULT_FAILURE; //assert (false); reprojector_.reprojectMap(new_frame_, overlap_kfs_); diff --git a/GPU_version/vio/src/sparse_img_align_gpu.cpp b/GPU_version/vio/src/sparse_img_align_gpu.cpp index fc5369e..2e5efde 100644 --- a/GPU_version/vio/src/sparse_img_align_gpu.cpp +++ b/GPU_version/vio/src/sparse_img_align_gpu.cpp @@ -30,7 +30,6 @@ SparseImgAlignGpu::SparseImgAlignGpu( method_ = method; verbose_ = verbose; eps_ = 1e-10; -// data = fopen((std::string(getenv("HOME"))+"/Project/data.txt").c_str(), "w+"); } size_t SparseImgAlignGpu::run(FramePtr ref_frame, FramePtr cur_frame) @@ -46,9 +45,6 @@ size_t SparseImgAlignGpu::run(FramePtr ref_frame, FramePtr cur_frame) residual_->reload_buf(1,3,ref_pos); cl_float3 features[ref_frame->fts_.size()]; cl_float2 featue_px[ref_frame->fts_.size()]; - // fprintf(data, "ref_frame:\n %f,%f,%f\n",ref_pos[0],ref_pos[1],ref_pos[2]); - // fprintf(data, "cur_frame:\n %f,%f,%f\n",cur_pos[0],cur_pos[1],cur_pos[2]); - // fprintf(data, "camera:\n %f,%f,%f,%f,%f\n features:\n",camera[0],camera[1],camera[2],camera[3],camera[4]); feature_counter_ = 0; // is used to compute the index of the cached jacobian for(auto it=ref_frame->fts_.begin(); it!=ref_frame->fts_.end();++it){ if(*it == nullptr)continue; @@ -59,7 +55,6 @@ size_t SparseImgAlignGpu::run(FramePtr ref_frame, FramePtr cur_frame) features[feature_counter_].z=xyz_ref(2); featue_px[feature_counter_].x=(*it)->px(0); featue_px[feature_counter_].y=(*it)->px(1); - // fprintf(data, "%f,%f,%f,%f,%f\n",xyz_ref(0),xyz_ref(1),xyz_ref(2),(*it)->px(0),(*it)->px(1)); ++feature_counter_; } residual_->reload_buf(1,4,features); @@ -91,31 +86,21 @@ double SparseImgAlignGpu::computeResiduals( cl_float3 J[300]={0.0}; float chi2_[300]={0.0}; float scale=(float)scale_; - std::cerr<<"computeResiduals line: 94,\t"; residual_->write_buf(1,11,scale); - std::cerr<<"96,\t"; residual_->reload_buf(1,10,chi2_); - std::cerr<<"computeResiduals line: 98,\t"; residual_->reload_buf(1,8,H); - std::cerr<<"computeResiduals line: 100,\t"; residual_->reload_buf(1,9,J); - std::cerr<<"computeResiduals line: 102,\t"; /// TODO GPU compute based on the feature residual_->run(1,feature_counter_); - std::cerr<<"105,\t"; float error[300]={0.0}; float chi[300]={0.0}; residual_->read(1,10,feature_counter_,chi); - std::cerr<<"109,\t"; residual_->read(1,7,feature_counter_,error); - std::cerr<<"111,\t"; for(int i = 1; i < feature_counter_; ++i){ error[0] += error[i]; chi[0] += chi[i]; } - std::cerr<<"116,\t"; scale_ = error[0]*(1.48f / feature_counter_); - std::cerr<<"118\n"; return chi[0]/(feature_counter_*8); }