提交 099ba7b6 编写于 作者: S storypku 提交者: Xiangquan Xiao

Build: unified usage of macros USE_GPU and CPU_ONLY as USE_GPU

上级 50e863d1
......@@ -116,7 +116,7 @@ TEST(BlobTest, source_test) {
blob_4d.Reshape({1, 3, 4, 5});
blob_4d.set_cpu_data(cpu_data);
#ifndef CPU_ONLY
#if USE_GPU == 1
blob_4d.Reshape({2, 3, 4, 5});
float* gpu_data = nullptr;
BASE_CUDA_CHECK(cudaMalloc(&gpu_data, blob_4d.count() * sizeof(float)));
......
......@@ -16,7 +16,9 @@
#pragma once
#ifndef CPU_ONLY
#include <cassert>
#if USE_GPU == 1
#include <cublas_v2.h>
#include <cuda_runtime.h>
......@@ -31,7 +33,7 @@ namespace base {
#define NO_GPU assert(false)
#endif
#ifndef CPU_ONLY
#if USE_GPU == 1
#define BASE_CUDA_CHECK(condition) \
{ apollo::perception::base::GPUAssert((condition), __FILE__, __LINE__); }
......
......@@ -22,7 +22,7 @@ namespace perception {
namespace base {
TEST(CommonTest, GPUAssertTest) {
#ifndef CPU_ONLY
#if USE_GPU == 1
GPUAssert(cudaSetDevice(-1), __FILE__, __LINE__, false);
#endif
}
......
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
// build perception with cpu or gpu
/* #undef CPU_ONLY */
// build perception with using cyber log lib or glog lib
/* #undef PERCEPTION_USE_CYBER */
......@@ -75,7 +75,7 @@ SyncedMemory::SyncedMemory(bool use_cuda)
cpu_malloc_use_cuda_(use_cuda),
own_gpu_data_(false),
device_(-1) {
#ifndef CPU_ONLY
#if USE_GPU == 1
#ifdef PERCEPTION_DEBUG
BASE_CUDA_CHECK(cudaGetDevice(&device_));
#endif
......@@ -91,7 +91,7 @@ SyncedMemory::SyncedMemory(size_t size, bool use_cuda)
cpu_malloc_use_cuda_(use_cuda),
own_gpu_data_(false),
device_(-1) {
#ifndef CPU_ONLY
#if USE_GPU == 1
#ifdef PERCEPTION_DEBUG
BASE_CUDA_CHECK(cudaGetDevice(&device_));
#endif
......@@ -104,11 +104,11 @@ SyncedMemory::~SyncedMemory() {
PerceptionFreeHost(cpu_ptr_, cpu_malloc_use_cuda_);
}
#ifndef CPU_ONLY
#if USE_GPU == 1
if (gpu_ptr_ && own_gpu_data_) {
BASE_CUDA_CHECK(cudaFree(gpu_ptr_));
}
#endif // CPU_ONLY
#endif // USE_GPU
}
inline void SyncedMemory::to_cpu() {
......@@ -125,7 +125,7 @@ inline void SyncedMemory::to_cpu() {
own_cpu_data_ = true;
break;
case HEAD_AT_GPU:
#ifndef CPU_ONLY
#if USE_GPU == 1
if (cpu_ptr_ == nullptr) {
PerceptionMallocHost(&cpu_ptr_, size_, cpu_malloc_use_cuda_);
own_cpu_data_ = true;
......@@ -144,7 +144,7 @@ inline void SyncedMemory::to_cpu() {
inline void SyncedMemory::to_gpu() {
check_device();
#ifndef CPU_ONLY
#if USE_GPU == 1
switch (head_) {
case UNINITIALIZED:
BASE_CUDA_CHECK(cudaMalloc(&gpu_ptr_, size_));
......@@ -188,7 +188,7 @@ void SyncedMemory::set_cpu_data(void* data) {
const void* SyncedMemory::gpu_data() {
check_device();
#ifndef CPU_ONLY
#if USE_GPU == 1
to_gpu();
return (const void*)gpu_ptr_;
#else
......@@ -199,7 +199,7 @@ const void* SyncedMemory::gpu_data() {
void SyncedMemory::set_gpu_data(void* data) {
check_device();
#ifndef CPU_ONLY
#if USE_GPU == 1
ACHECK(data);
if (own_gpu_data_) {
BASE_CUDA_CHECK(cudaFree(gpu_ptr_));
......@@ -221,7 +221,7 @@ void* SyncedMemory::mutable_cpu_data() {
void* SyncedMemory::mutable_gpu_data() {
check_device();
#ifndef CPU_ONLY
#if USE_GPU == 1
to_gpu();
head_ = HEAD_AT_GPU;
return gpu_ptr_;
......@@ -231,7 +231,7 @@ void* SyncedMemory::mutable_gpu_data() {
#endif
}
#ifndef CPU_ONLY
#if USE_GPU == 1
void SyncedMemory::async_gpu_push(const cudaStream_t& stream) {
check_device();
CHECK_EQ(head_, HEAD_AT_CPU);
......@@ -247,7 +247,7 @@ void SyncedMemory::async_gpu_push(const cudaStream_t& stream) {
#endif
void SyncedMemory::check_device() {
#ifndef CPU_ONLY
#if USE_GPU == 1
#ifdef PERCEPTION_DEBUG
int device;
cudaGetDevice(&device);
......
......@@ -70,7 +70,7 @@ namespace perception {
namespace base {
inline void PerceptionMallocHost(void** ptr, size_t size, bool use_cuda) {
#ifndef CPU_ONLY
#if USE_GPU == 1
if (use_cuda) {
BASE_CUDA_CHECK(cudaMallocHost(ptr, size));
return;
......@@ -81,7 +81,7 @@ inline void PerceptionMallocHost(void** ptr, size_t size, bool use_cuda) {
}
inline void PerceptionFreeHost(void* ptr, bool use_cuda) {
#ifndef CPU_ONLY
#if USE_GPU == 1
if (use_cuda) {
BASE_CUDA_CHECK(cudaFreeHost(ptr));
return;
......@@ -119,7 +119,7 @@ class SyncedMemory {
void set_head_cpu() { set_head(HEAD_AT_CPU); }
size_t size() { return size_; }
#ifndef CPU_ONLY
#if USE_GPU == 1
void async_gpu_push(const cudaStream_t& stream);
#endif
......
......@@ -100,7 +100,7 @@ TEST_F(SyncedMemoryTest, TestInitialization) {
delete p_mem;
}
#ifndef CPU_ONLY // GPU test
#if USE_GPU == 1 // GPU test
TEST_F(SyncedMemoryTest, TestAllocationCPUGPU) {
SyncedMemory mem(10, true);
......@@ -118,7 +118,7 @@ TEST_F(SyncedMemoryTest, TestAllocationCPU) {
EXPECT_TRUE(mem.mutable_cpu_data());
}
#ifndef CPU_ONLY // GPU test
#if USE_GPU == 1 // GPU test
TEST_F(SyncedMemoryTest, TestAllocationGPU) {
SyncedMemory mem(10, true);
......@@ -145,7 +145,7 @@ TEST_F(SyncedMemoryTest, TestCPUWrite) {
}
}
#ifndef CPU_ONLY // GPU test
#if USE_GPU == 1 // GPU test
TEST_F(SyncedMemoryTest, TestGPURead) {
SyncedMemory mem(10, true);
......
......@@ -46,7 +46,7 @@ struct CPUDevice {
template <typename Dtype>
class CPUDeviceTest : public MultiDeviceTest<CPUDevice<Dtype>> {};
#ifdef CPU_ONLY
#if USE_GPU == 0
typedef ::testing::Types<CPUDevice<float>, CPUDevice<double>>
TestDtypesAndDevices;
......
......@@ -15,7 +15,9 @@
*****************************************************************************/
#include "modules/perception/camera/common/data_provider.h"
#if USE_GPU == 1
#include <nppi.h>
#endif
#include "cyber/common/log.h"
......@@ -124,7 +126,7 @@ bool DataProvider::FillImageData(int rows, int cols, const uint8_t *data,
bool success = false;
#ifdef CPU_ONLY // copy to host memory
#if USE_GPU == 0 // copy to host memory
AINFO << "Fill in CPU mode ...";
if (handler_ != nullptr) {
AERROR << "Undistortion DO NOT support CPU mode!";
......
......@@ -17,7 +17,10 @@
#include <vector>
#include "cuda/include/npp.h"
#if USE_GPU == 1
#include <npp.h>
#endif
#include "Eigen/Dense"
#include "cyber/common/log.h"
......
......@@ -116,7 +116,7 @@ TEST(DetectionTest, all) {
gt_lights.push_back(light2);
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
EXPECT_TRUE(detector->Detect(detetor_options, &frame));
EXPECT_EQ(lights.size(), gt_lights.size());
......@@ -185,7 +185,7 @@ TEST(DetectionTest, no_light) {
lights.clear();
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
EXPECT_TRUE(detector->Detect(detetor_options, &frame));
#endif
}
......@@ -255,7 +255,7 @@ TEST(DetectionTest, out_of_img_light) {
gt_lights.push_back(light2);
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
EXPECT_TRUE(detector->Detect(detetor_options, &frame));
EXPECT_FALSE(lights[0]->region.is_detected);
......
......@@ -69,7 +69,7 @@ TEST(RecognizeTest, yellow) {
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
ASSERT_TRUE(recognition->Detect(recognition_options, &frame));
AINFO << "COLOR " << static_cast<int>(lights[0]->status.color);
ASSERT_TRUE(base::TLColor::TL_YELLOW == lights[0]->status.color);
......@@ -125,7 +125,7 @@ TEST(RecognizeTest, red) {
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
ASSERT_TRUE(recognition->Detect(recognition_options, &frame));
AINFO << "COLOR " << static_cast<int>(lights[0]->status.color);
ASSERT_TRUE(base::TLColor::TL_RED == lights[0]->status.color);
......@@ -233,7 +233,7 @@ TEST(RecognizeTest, black) {
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
ASSERT_TRUE(recognition->Detect(recognition_options, &frame));
AINFO << "COLOR " << static_cast<int>(lights[0]->status.color);
ASSERT_TRUE(base::TLColor::TL_BLACK == lights[0]->status.color);
......@@ -285,7 +285,7 @@ TEST(RecognizeTest, no_detection) {
lights[0]->region.is_detected = false;
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
ASSERT_TRUE(recognition->Detect(recognition_options, &frame));
AINFO << "COLOR " << static_cast<int>(lights[0]->status.color);
ASSERT_TRUE(base::TLColor::TL_UNKNOWN_COLOR == lights[0]->status.color);
......@@ -341,7 +341,7 @@ TEST(RecognizeTest, unknown_class) {
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
ASSERT_FALSE(recognition->Detect(recognition_options, &frame));
#endif
}
......@@ -395,7 +395,7 @@ TEST(RecognizeTest, quadrate) {
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
ASSERT_TRUE(recognition->Detect(recognition_options, &frame));
AINFO << "COLOR " << static_cast<int>(lights[0]->status.color);
ASSERT_TRUE(base::TLColor::TL_GREEN == lights[0]->status.color);
......@@ -457,7 +457,7 @@ TEST(RecognizeTest, horizontal) {
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
ASSERT_TRUE(recognition->Detect(recognition_options, &frame));
AINFO << "COLOR " << static_cast<int>(lights[0]->status.color);
ASSERT_TRUE(base::TLColor::TL_GREEN == lights[0]->status.color);
......@@ -507,7 +507,7 @@ TEST(RecognizeTest, no_light) {
lights.clear();
frame.traffic_lights = lights;
#ifndef CPU_ONLY
#if USE_GPU == 1
ASSERT_TRUE(recognition->Detect(recognition_options, &frame));
EXPECT_EQ(lights.size(), 0);
#endif
......
......@@ -46,7 +46,7 @@ bool FeatureGenerator::Init(const FeatureParam& feature_param,
// set output feature blob data
float* out_blob_data = nullptr;
#ifndef CPU_ONLY
#if USE_GPU == 1
log_blob_.reset(
new base::Blob<float>(1, 1, 1, static_cast<int>(log_table_.size())));
float* log_table = log_blob_->mutable_gpu_data();
......@@ -95,7 +95,7 @@ bool FeatureGenerator::Init(const FeatureParam& feature_param,
}
// memory copy direction and distance features
#ifndef CPU_ONLY
#if USE_GPU == 1
cudaMemcpy(direction_data_, direction_data.data(),
direction_data.size() * sizeof(float), cudaMemcpyHostToDevice);
cudaMemcpy(distance_data_, distance_data.data(),
......
......@@ -33,7 +33,7 @@ namespace lidar {
class FeatureGenerator {
public:
FeatureGenerator() {
#ifndef CPU_ONLY
#if USE_GPU == 1
pc_gpu_size_ = kMaxPointCloudGPUSize;
BASE_CUDA_CHECK(cudaMalloc(reinterpret_cast<void**>(&pc_gpu_),
pc_gpu_size_ * sizeof(base::PointF)));
......@@ -43,7 +43,7 @@ class FeatureGenerator {
}
virtual ~FeatureGenerator() {
#ifndef CPU_ONLY
#if USE_GPU == 1
ReleaseGPUMemory();
#endif
}
......@@ -52,7 +52,7 @@ class FeatureGenerator {
void Generate(const base::PointFCloudPtr& pc_ptr,
const std::vector<int>& point2grid) {
#ifndef CPU_ONLY
#if USE_GPU == 1
GenerateGPU(pc_ptr, point2grid);
#else
GenerateCPU(pc_ptr, point2grid);
......@@ -62,7 +62,7 @@ class FeatureGenerator {
inline std::string Name() const { return "FeatureGenerator"; }
private:
#ifndef CPU_ONLY
#if USE_GPU == 1
void GenerateGPU(const base::PointFCloudPtr& pc_ptr,
const std::vector<int>& point2grid);
void ReleaseGPUMemory();
......
......@@ -16,7 +16,6 @@
#pragma once
#include <cuda.h>
#include <cuda_runtime.h>
namespace apollo {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册