CPP项目中使用CUDA(opencv+cuda or pybind+cuda)

CPP项目中使用CUDA(opencv+cuda or pybind+cuda)_第1张图片

cmake_minimum_required(VERSION 2.8.12)
project(flow LANGUAGES CXX)


set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(include
        ${CUDA_INCLUDE_DIRS}
        ${OpenCV_INCLUDE_DIRS}
        )

link_directories(${OpenCV_LIBRARY_DIRS})

find_package(CUDA REQUIRED)
find_package(OpenCV REQUIRED)


FILE(GLOB SOURCES "*.cu" "*.cpp" "*.cuh" "*.h" )

set(CUDA_NVCC_FLAGS "-g -G")

CUDA_ADD_EXECUTABLE(flow hell0.cu example.cpp)  # add_executable(flow example.cpp)

target_link_libraries(flow ${OpenCV_LIBS})
#include "hell0.cuh"
int main(){
    cuda_main();
    return 0;
}
#include 

__global__ void cuda_hello(){
    printf("gpu\n");
}



extern "C" void cuda_main() {
    cuda_hello<<<1,10>>>();
    cudaDeviceSynchronize();//witout this no output
}

extern "C"
void cuda_main();

opencv+cuda

cmake_minimum_required(VERSION 3.5)

project(cuda_cv LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(include
        ${CUDA_INCLUDE_DIRS}
        ${OpenCV_INCLUDE_DIRS}
        )

link_directories(${OpenCV_LIBRARY_DIRS})

find_package(CUDA REQUIRED)
find_package(OpenCV REQUIRED)

#INCLUDE(/home/psdz/cmake-3.9.0/Modules/FindCUDA.cmake)

FILE(GLOB SOURCES "*.cu" "*.cpp" "*.c" "*.h")

set(CUDA_NVCC_FLAGS "-g -G")

CUDA_ADD_EXECUTABLE(cuda_cv main.cu)

target_link_libraries(cuda_cv ${OpenCV_LIBS})

pybind+cuda

cmake_minimum_required(VERSION 2.8.12)
project(example LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(PYBIND11_PYTHON_VERSION "3.7")

#include_directories("/usr/include/python3.10/")

include_directories(include
        ${CUDA_INCLUDE_DIRS}
        ${OpenCV_INCLUDE_DIRS}
        )
link_directories(${OpenCV_LIBRARY_DIRS})

find_package(CUDA REQUIRED)
find_package(OpenCV REQUIRED)
include_directories("/home/pdd/anaconda3/envs/yolocopy/bin/")


FILE(GLOB SOURCES "*.cu" "*.cpp" "*.cuh" "*.h" )

set(CUDA_NVCC_FLAGS "-g -G")

add_subdirectory(pybind11)
pybind11_add_module(example example.cpp)
#add_executable(untitled example.cpp)

#target_link_libraries(${PROJECT_NAME} INTERFACE
#        ${OpenCV_LIBRARIES}
##        pybind11::pybind11
#        )
target_link_libraries(${PROJECT_NAME} PRIVATE
       ${OpenCV_LIBRARIES}
        pybind11::pybind11
        )
#link_libraries(${OpenCV_LIBRARIES})

你可能感兴趣的:(语言学习笔记,opencv,计算机视觉,人工智能)