diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..39c4ce500 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +.vscode +build* +sample_test +build.sh +temp/ +Gtest +cmake-3.16.0-rc2-Linux-x86_64/ +stb-test/ +hip_build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 2e339ecfe..fe43d8d9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,34 @@ -cmake_minimum_required(VERSION 3.15) +# Copyright (c) 2015 Advanced Micro Devices, Inc. All rights reserved. +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. + +cmake_minimum_required(VERSION 3.5) project(amd_rpp VERSION 0.2) - +message("${PROJECT_NAME} - ${PROJECT_VERSION}") +message("cmake minimum version required: ${CMAKE_MINIMUM_REQUIRED_VERSION}") +message("cmake version found: ${CMAKE_VERSION}") include(CheckCXXCompilerFlag) +# set default backend to OPENCL +if (NOT DEFINED BACKEND) + SET(BACKEND "OCL") +endif() if(WIN32 AND CMAKE_CROSSCOMPILING) set(WINE_CMD "wine") @@ -137,7 +163,6 @@ enable_cppcheck( ) -add_library(${PROJECT_NAME} SHARED include/rpp.h) # Find required packages find_package(OpenCL REQUIRED) # OpenCL_INCLUDE_DIRS, OpenCL_LIBRARIES @@ -247,6 +272,7 @@ if (NOT DEFINED SIMD_ENABLE) SET(SIMD_ENABLE "1") endif() +add_library(${PROJECT_NAME} SHARED include/rpp.h $) if( "${SIMD_ENABLE}" STREQUAL "1") target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_SIMD_INTRINSICS=1) message("-- ${Green}${PROJECT_NAME} built with ENABLE_SIMD_INTRINSICS") @@ -255,7 +281,6 @@ else() message("-- ${Green}${PROJECT_NAME} not built with ENABLE_SIMD_INTRINSICS") endif() - # target setting option(Boost_USE_STATIC_LIBS "Use boost static libraries" ON) set(BOOST_COMPONENTS filesystem system) @@ -265,10 +290,8 @@ find_package(Boost REQUIRED COMPONENTS ${BOOST_COMPONENTS}) set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE CXX) find_package(OpenMP) -if(OpenMP_CXX_FOUND) - target_link_libraries(${PROJECT_NAME} ${MODULES_LIST} ${SUB_MODULES_LIST} ${SUB_MODULES_LIST_HIP} ${LINK_LIST} ${LINK_LIST_HIP} OpenMP::OpenMP_CXX) -endif() -target_link_libraries(${PROJECT_NAME} ${MODULES_LIST} ${LINK_LIST} ${LINK_LIST_HIP}) + + target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include diff --git a/Readme.md b/Readme.md index 22dd99e5d..ee22cb45a 100644 --- a/Readme.md +++ b/Readme.md @@ -13,7 +13,9 @@ RPP is developed for __Linux__ operating system. 3. [ROCm](https://github.com/RadeonOpenCompute/ROCm#installing-from-amd-rocm-repositories) ## Functions Included + ### Image Augmentation Category + #### Enhancements * Brightness modification * Contrast modification @@ -23,18 +25,21 @@ RPP is developed for __Linux__ operating system. * Vignette effect * Gamma Correction * Histogram Balance + #### Self Driving Car Specs * Exposure modifications * Foggy * Rainy * Snowy * RandomShadow + #### Geometric Distortion Nodes * Rotate * Warp-affine * Flip (horizontally or vertically) * Fish Eye Effect * Lens correction + #### Other Augmentations * Resize * RandomResizeCrop @@ -45,6 +50,7 @@ RPP is developed for __Linux__ operating system. * Blurring * Adding Jitter * RandomCropLetterBox + ### Vision Functions * Absolute Difference * Accumulate @@ -136,58 +142,57 @@ Extended RPP support as a functionality through OpenVX [MIVisionX](https://githu #### RPP stand-alone code snippet using OCL ```` - err = clGetPlatformIDs(1, &platform_id, NULL); - err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL); - theContext = clCreateContext(0, 1, &device_id, NULL, NULL, &err); - theQueue = clCreateCommandQueue(theContext, device_id, 0, &err); - - d_a = clCreateBuffer(theContext, CL_MEM_READ_ONLY, bytes, NULL, NULL); - d_c = clCreateBuffer(theContext, CL_MEM_WRITE_ONLY, bytes, NULL, NULL); - err = clEnqueueWriteBuffer(theQueue, d_a, CL_TRUE, 0, bytes, h_a, 0, NULL, NULL); - cl_mem d_f; - d_f = clCreateBuffer(theContext, CL_MEM_READ_ONLY, f_bytes, NULL, NULL); - err = clEnqueueWriteBuffer(theQueue, d_f, CL_TRUE, 0, f_bytes, h_f, 0, NULL, NULL) +err = clGetPlatformIDs(1, &platform_id, NULL); +err = clGetDeviceIDs(platform_id, CL_DEVICE_TYPE_GPU, 1, &device_id, NULL); +theContext = clCreateContext(0, 1, &device_id, NULL, NULL, &err); +theQueue = clCreateCommandQueue(theContext, device_id, 0, &err); + +d_a = clCreateBuffer(theContext, CL_MEM_READ_ONLY, bytes, NULL, NULL); +d_c = clCreateBuffer(theContext, CL_MEM_WRITE_ONLY, bytes, NULL, NULL); +err = clEnqueueWriteBuffer(theQueue, d_a, CL_TRUE, 0, bytes, h_a, 0, NULL, NULL); +cl_mem d_f; +d_f = clCreateBuffer(theContext, CL_MEM_READ_ONLY, f_bytes, NULL, NULL); +err = clEnqueueWriteBuffer(theQueue, d_f, CL_TRUE, 0, f_bytes, h_f, 0, NULL, NULL) - Rpp32f alpha=2; - Rpp32s beta=1; +Rpp32f alpha=2; +Rpp32s beta=1; - RppiSize srcSize; - srcSize.height=height; - srcSize.width=width; - rppi_brighten_8u_pln1_gpu( d_a, srcSize, d_c, alpha, beta, theQueue);//device side API call +RppiSize srcSize; +srcSize.height=height; +srcSize.width=width; +rppi_brighten_8u_pln1_gpu( d_a, srcSize, d_c, alpha, beta, theQueue);//device side API call ```` #### RPP stand-alone code snippet using HOST ``` - rppHandle_t handle; - rppCreateWithBatchSize(&handle, noOfImages); - rppi_resize_u8_pkd3_batchDD_host(input, srcSize, output, dstSize, noOfImages, handle); - Rpp32f alpha=2; - Rpp32s beta=1; +rppHandle_t handle; +rppCreateWithBatchSize(&handle, noOfImages); +rppi_resize_u8_pkd3_batchDD_host(input, srcSize, output, dstSize, noOfImages, handle); +Rpp32f alpha=2; +Rpp32s beta=1; - RppiSize srcSize; - srcSize.height=height; - srcSize.width=width; - rppi_brighten_8u_pln1_gpu( d_a, srcSize, d_c, alpha, beta, theQueue);//device side API call - +RppiSize srcSize; +srcSize.height=height; +srcSize.width=width; +rppi_brighten_8u_pln1_gpu( d_a, srcSize, d_c, alpha, beta, theQueue);//device side API call ``` #### RPP stand-alone code snippet using HIP ``` - hipMalloc(&d_input, ioBufferSize * sizeof(Rpp8u)); - hipMalloc(&d_output, ioBufferSize * sizeof(Rpp8u)); - check_hip_error(); - hipMemcpy(d_input, input, ioBufferSize * sizeof(Rpp8u), hipMemcpyHostToDevice); - check_hip_error(); - Rpp32f alpha=2; - Rpp32s beta=1; - - RppiSize srcSize; - srcSize.height=height; - srcSize.width=width; - rppi_brightness_u8_pkd3_gpu(d_input, srcSize[0], d_output, alpha, beta, handle); //device side API call +hipMalloc(&d_input, ioBufferSize * sizeof(Rpp8u)); +hipMalloc(&d_output, ioBufferSize * sizeof(Rpp8u)); +check_hip_error(); +hipMemcpy(d_input, input, ioBufferSize * sizeof(Rpp8u), hipMemcpyHostToDevice); +check_hip_error(); +Rpp32f alpha=2; +Rpp32s beta=1; + +RppiSize srcSize; +srcSize.height=height; +srcSize.width=width; +rppi_brightness_u8_pkd3_gpu(d_input, srcSize[0], d_output, alpha, beta, handle); //device side API call ``` #### RPP with [GDF](https://github.com/GPUOpen-ProfessionalCompute-Libraries/MIVisionX/blob/master/utilities/runvx/README.md#amd-runvx)(uses OpenVX) code snippet @@ -198,7 +203,7 @@ read input ../images/face.jpg view input inputWindow view output brightnessWindow -#import RPP library +# import RPP library import vx_rpp # create input and output images data input = image:480,360,RGB2 @@ -210,8 +215,8 @@ data luma = image-virtual:0,0,U008 node org.khronos.openvx.color_convert input yuv node org.khronos.openvx.channel_extract yuv !CHANNEL_Y luma -#compute brightness and contrast in luma image using Brightness function +# compute brightness and contrast in luma image using Brightness function data alpha = scalar:FLOAT32,1.0 #contrast control data beta = scalar:INT32,30 #brightness control node org.rpp.Brightness luma output alpha beta -``` +``` \ No newline at end of file diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index e406218e1..ecb9a100f 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -1,15 +1,11 @@ -cmake_minimum_required(VERSION 3.5) project(modules) - if (${BACKEND} MATCHES OCL) file(GLOB RPP_KERNELS cl/kernel/*.cl) endif() - if (${BACKEND} MATCHES HIP) file(GLOB RPP_KERNELS hip/kernel/*.cpp) endif() - if( ${BACKEND} MATCHES "OCL" OR ${BACKEND} STREQUAL "HIPOC" OR ${BACKEND} STREQUAL "HIP") list(APPEND Rpp_Source ${PROJECT_BINARY_DIR}/rpp_kernels.h) MESSAGE("Add Custome Command") @@ -33,7 +29,6 @@ if( ${BACKEND} MATCHES "OCL" OR ${BACKEND} STREQUAL "HIPOC" OR ${BACKEND} STREQU add_custom_target(rpp_tidy_inlining DEPENDS ${PROJECT_BINARY_DIR}/rpp_kernels.h ${PROJECT_BINARY_DIR}/rpp_kernel_includes.h ) - add_dependencies(tidy rpp_tidy_inlining) endif() @@ -78,7 +73,6 @@ file( GLOB CPPFILES "*.cpp" ) list(APPEND Rpp_Source ${CPPFILES}) list(APPEND Rpp_Source ${PROJECT_BINARY_DIR}/kernel.cpp) list(APPEND Rpp_Source ${PROJECT_BINARY_DIR}/kernel_includes.cpp) - # Backend Specific Settings if( "${TIME_INFO}" STREQUAL "1") add_definitions(-DTIME_INFO) @@ -92,11 +86,10 @@ if( "${BACKEND}" STREQUAL "HIP") add_definitions(-DSTATIC) endif() set(BACKEND_HIPOC 1) - add_subdirectory( hip ) + #add_subdirectory( hip ) # add_subdirectory( hipoc ) set(CMAKE_CXX_COMPILER ${COMPILER_FOR_HIP}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HIP_HIPCC_FLAGS} -fopenmp -Ofast -msse4.2 -msse4.1 -mssse3 -mavx2 -g3 -std=c++14") - # set(LINK_LIST_HIPOC ${PROJECT_NAME}-hipoc ${LINK_LIST}) set(LINK_LIST_HIP ${PROJECT_NAME}-hip ${LINK_LIST}) # set(SUB_MODULES_LIST_HIPOC ${PROJECT_NAME}-hipoc ${SUB_MODULES_LIST} PARENT_SCOPE) @@ -106,13 +99,17 @@ if( "${BACKEND}" STREQUAL "HIP") set(HIP_INC "/opt/rocm/hip/include") set(INCLUDE_LIST ${HIP_INC} ${INCLUDE_LIST}) elseif( "${BACKEND}" STREQUAL "OCL") - add_subdirectory( cl ) - set(SUB_MODULES_LIST ${PROJECT_NAME}-opencl ${SUB_MODULES_LIST} PARENT_SCOPE) + file( GLOB MOD_CL_CPP "cl/*.cpp" ) + list(APPEND Rpp_Source ${CPPFILES} ${MOD_CL_CPP}) set(CMAKE_CXX_COMPILER ${COMPILER_FOR_OPENCL}) # GCC and G++ donst work for creating .so file set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Ofast -msse4.2 -msse4.1 -mssse3 -mavx2 -g3 -std=c++14 -Wno-deprecated-declarations") - set(LINK_LIST ${PROJECT_NAME}-opencl ${OpenCL_LIBRARIES} ${LINK_LIST}) add_definitions(-DRPP_CACHE_DIR="${CACHE_DIR}") set(ROCM_INC "/opt/rocm/include") + list(APPEND OpenCL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/src/include/cl/) + MESSAGE("OPenCL incude directories are ${OpenCL_INCLUDE_DIRS}") + add_definitions(-DMOD_CL_PATH="${CMAKE_CURRENT_LIST_DIR}/cl/kernel/") + add_definitions(-DRPP_CACHE_DIR="${CACHE_DIR}") + add_definitions(-DOCL_COMPILE) set(INCLUDE_LIST ${OpenCL_INCLUDE_DIRS} ${INCLUDE_LIST} ${ROCM_INC}) add_definitions(-DOCL_COMPILE) add_definitions(-DRPP_BACKEND_OPENCL) @@ -120,16 +117,9 @@ endif() add_kernels("${RPP_KERNELS}") add_kernel_includes("${RPP_KERNEL_INCLUDES}") - - -add_library( ${PROJECT_NAME} OBJECT ${Rpp_Source}) - -clang_tidy_check(${PROJECT_NAME}) - +add_library(${PROJECT_NAME} OBJECT ${Rpp_Source} ) # target setting - set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) -target_link_libraries (${PROJECT_NAME} ${LINK_LIST}) target_include_directories( ${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/include diff --git a/src/modules/cl/CMakeLists.txt b/src/modules/cl/CMakeLists.txt deleted file mode 100644 index 76139f8a7..000000000 --- a/src/modules/cl/CMakeLists.txt +++ /dev/null @@ -1,43 +0,0 @@ -cmake_minimum_required(VERSION 3.15) -project(modules-opencl) - -if( BACKEND_HIPOC) - file( GLOB MOD_CL_KERNEL "kernel/*.cl" ) - foreach (KERNEL_FILE ${MOD_CL_KERNEL}) - get_filename_component(KERN_FILE_NAME ${KERNEL_FILE} NAME) - add_library( ${KERN_FILE_NAME} ${KERNEL_FILE}) - set_target_properties(${KERN_FILE_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) - set_target_properties(${KERN_FILE_NAME} PROPERTIES LINKER_LANGUAGE CXX) - endforeach(KERNEL_FILE) - set(CMAKE_CXX_COMPILER ${COMPILER_FOR_HIPOC}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Ofast -g3 -std=c++14 ") - add_definitions(-DHIP_COMPILE) - # add_definitions(-DMOD_CL_PATH="\\"${CMAKE_CURRENT_LIST_DIR}/kernel/"\\") - add_definitions(-DMOD_CL_PATH="${CMAKE_CURRENT_LIST_DIR}/kernel/") - add_definitions(-DRPP_CACHE_DIR="/home/neel/shobi/") - add_definitions(-DRPP_BACKEND_HIP) - link_libraries(-amdgpu-target=gfx803 -amdgpu-target=gfx900 -Wno-unused-command-line-argument) -else() - file( GLOB MOD_CPP "*.cpp" ) - add_library( ${PROJECT_NAME} OBJECT ${MOD_CPP}) - set(CMAKE_CXX_COMPILER ${COMPILER_FOR_OPENCL}) # GCC and G++ donst work for creating .so file - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Ofast -g3 -std=c++14 -Wno-deprecated-declarations") - add_definitions(-DRPP_BACKEND_OPENCL) - - # add_definitions(-DMOD_CL_PATH="\\"${CMAKE_CURRENT_LIST_DIR}/kernel/"\\") - add_definitions(-DMOD_CL_PATH="${CMAKE_CURRENT_LIST_DIR}/kernel/") - add_definitions(-DRPP_CACHE_DIR="${CACHE_DIR}") - add_definitions(-DOCL_COMPILE) - - set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) - target_link_libraries (${PROJECT_NAME} ${OpenCL_LIBRARIES} ) - target_include_directories( ${PROJECT_NAME} - PUBLIC - ${CMAKE_SOURCE_DIR}/include - ${OpenCL_INCLUDE_DIRS} - /opt/rocm/include - PRIVATE - ${CMAKE_SOURCE_DIR}/src/include - ${CMAKE_SOURCE_DIR}/src/include/cl - ) -endif()