Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions CMakeModules/build_cl2hpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
INCLUDE(ExternalProject)

SET(prefix ${CMAKE_BINARY_DIR}/third_party/cl2hpp)

ExternalProject_Add(
cl2hpp-ext
GIT_REPOSITORY https://github.com/KhronosGroup/OpenCL-CLHPP.git
GIT_TAG 75bb7d0d8b2ffc6aac0a3dcaa22f6622cab81f7c
PREFIX "${prefix}"
INSTALL_DIR "${prefix}/package"
UPDATE_COMMAND ""
CONFIGURE_COMMAND ${CMAKE_COMMAND} -Wno-dev "-G${CMAKE_GENERATOR}" <SOURCE_DIR>
-DCMAKE_SOURCE_DIR:PATH=<SOURCE_DIR>
-DCMAKE_CXX_COMPILER:FILEPATH=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER:FILEPATH=${CMAKE_C_COMPILER}
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
-DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
-DBUILD_DOCS:BOOL=OFF
-DBUILD_EXAMPLES:BOOL=OFF
-DBUILD_TESTS:BOOL=OFF
)

ExternalProject_Get_Property(cl2hpp-ext install_dir)

ADD_CUSTOM_TARGET(cl2hpp DEPENDS "${prefix}/package/CL/cl2.hpp")

ADD_DEPENDENCIES(cl2hpp cl2hpp-ext)

SET(CL2HPP_INCLUDE_DIRECTORY ${install_dir})
77 changes: 42 additions & 35 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")

OPTION(BUILD_EXAMPLES_CUDA "Turn off/on building cuda examples" ON)
OPTION(BUILD_EXAMPLES_OPENCL "Turn off/on building opencl examples" ON)
OPTION(USE_SYSTEM_CL2HPP "Use cl2.hpp header installed on the system" OFF)

INCLUDE(build_cl2hpp)

MACRO(BUILD_EXAMPLE EX_NAME EX_SRC COMPUTE_NAME FG_LIBS COMPUTE_LIBS)
IF(${COMPUTE_NAME} STREQUAL "cuda")
Expand All @@ -18,6 +21,9 @@ MACRO(BUILD_EXAMPLE EX_NAME EX_SRC COMPUTE_NAME FG_LIBS COMPUTE_LIBS)
OUTPUT_NAME ${EX_NAME}_${COMPUTE_NAME}
RUNTIME_OUTPUT_DIRECTORY ${DIR_NAME}
FOLDER "Examples/${COMPUTE_NAME}")
IF(${COMPUTE_NAME} STREQUAL "opencl")
ADD_DEPENDENCIES(example_${EX_NAME}_${COMPUTE_NAME} cl2hpp)
ENDIF()
ENDMACRO()

IF(TARGET forge)
Expand All @@ -41,35 +47,27 @@ ELSE(TARGET forge)
${FREEIMAGE_INCLUDE_PATH}
)
ADD_DEFINITIONS(-DGLEW_MX)
IF(UNIX)
ADD_DEFINITIONS(-Wall -std=c++11 -fvisibility=hidden)
# GCC 5.3 and above give errors for mempcy from <string.h>
# This is a (temporary) fix for that
IF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.3.0")
ADD_DEFINITIONS(-D_FORCE_INLINES)
ENDIF()
ENDIF()

# OS Definitions
IF(UNIX)
IF(APPLE)
ADD_DEFINITIONS(-DOS_MAC)
SET(CMAKE_MACOSX_RPATH ON)
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
# OS Definitions
IF(UNIX)
ADD_DEFINITIONS(-Wall -std=c++11 -fvisibility=hidden)
IF(APPLE)
ADD_DEFINITIONS(-DOS_MAC)
SET(CMAKE_MACOSX_RPATH ON)
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}")
ENDIF("${isSystemDir}" STREQUAL "-1")
ELSE(APPLE)
ADD_DEFINITIONS(-DOS_LNX)
ENDIF(APPLE)
ELSE(UNIX)
ADD_DEFINITIONS(-DOS_WIN -DNOMINMAX)
ENDIF(UNIX)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}")
ENDIF("${isSystemDir}" STREQUAL "-1")
ELSE(APPLE)
ADD_DEFINITIONS(-DOS_LNX)
ENDIF(APPLE)
ELSE(UNIX)
ADD_DEFINITIONS(-DOS_WIN -DNOMINMAX)
ENDIF(UNIX)
ENDIF(TARGET forge)

FILE(GLOB CPU_EXAMPLE_SRC_FILES "cpu/*.cpp")
Expand All @@ -90,14 +88,22 @@ ENDFOREACH()
IF (BUILD_EXAMPLES_CUDA)
FIND_PACKAGE(CUDA QUIET)
IF(CUDA_FOUND)
INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIRS})

# GCC 6.0 and above default to g++14, enabling c++11 features by default
# Enabling c++11 with nvcc 7.5 + gcc 6.x doesn't seem to work
# Only solution for now is to force use c++03 for gcc 6.x
IF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "6.0.0")
SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -std=c++98")
ENDIF()
IF(UNIX)
# GCC 5.3 and above give errors for mempcy from <string.h>
# This is a (temporary) fix for that
IF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.3.0")
ADD_DEFINITIONS(-D_FORCE_INLINES)
ENDIF()
# GCC 6.0 and above default to g++14, enabling c++11 features by default
# Enabling c++11 with nvcc 7.5 + gcc 6.x doesn't seem to work
# Only solution for now is to force use c++03 for gcc 6.x
IF("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "6.0.0")
SET(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -std=c++98")
ENDIF()
ENDIF(UNIX)

INCLUDE_DIRECTORIES(${CUDA_INCLUDE_DIRS})

FILE(GLOB CUDA_EXAMPLE_SRC_FILES "cuda/*.cu")
FOREACH(FILE ${CUDA_EXAMPLE_SRC_FILES})
Expand Down Expand Up @@ -128,6 +134,7 @@ IF (BUILD_EXAMPLES_OPENCL)
INCLUDE_DIRECTORIES(
"${CMAKE_CURRENT_SOURCE_DIR}/opencl"
${OpenCL_INCLUDE_DIRS}
${CL2HPP_INCLUDE_DIRECTORY}
)
FOREACH(FILE ${OpenCL_EXAMPLE_SRC_FILES})
GET_FILENAME_COMPONENT(EXAMPLE ${FILE} NAME_WE)
Expand Down
32 changes: 25 additions & 7 deletions examples/cpu/bubblechart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
********************************************************/

#include <forge.h>
#include <CPUCopy.hpp>
#define USE_FORGE_CPU_COPY_HELPERS
#include <ComputeCopy.h>
#include <complex>
#include <cmath>
#include <vector>
Expand Down Expand Up @@ -74,7 +75,7 @@ int main(void)
wnd.makeCurrent();

fg::Chart chart(FG_CHART_2D);
chart.setAxesLimits(FRANGE_START, FRANGE_END, -1.1f, 1.1f);
chart.setAxesLimits(FRANGE_START, FRANGE_END, -1.0f, 1.0f);

/* Create several plot objects which creates the necessary
* vertex buffer objects to hold the different plot types
Expand All @@ -98,19 +99,36 @@ int main(void)
* memory to display memory, Forge provides copy headers
* along with the library to help with this task
*/
fg::copy(plt1.vertices(), plt1.verticesSize(), (const void*)cosData.data());
fg::copy(plt2.vertices(), plt2.verticesSize(), (const void*)tanData.data());

GfxHandle* handles[5];

// create GL-CPU interop buffers
createGLBuffer(&handles[0], plt1.vertices(), FORGE_VBO);
createGLBuffer(&handles[1], plt2.vertices(), FORGE_VBO);
createGLBuffer(&handles[2], plt2.colors(), FORGE_VBO);
createGLBuffer(&handles[3], plt2.alphas(), FORGE_VBO);
createGLBuffer(&handles[4], plt2.markers(), FORGE_VBO);

// copy the data from compute buffer to graphics buffer
copyToGLBuffer(handles[0], (ComputeResourceHandle)cosData.data(), plt1.verticesSize());
copyToGLBuffer(handles[1], (ComputeResourceHandle)tanData.data(), plt2.verticesSize());

/* update color value for tan graph */
fg::copy(plt2.colors(), plt2.colorsSize(), (const void*)colors.data());
copyToGLBuffer(handles[2], (ComputeResourceHandle)colors.data(), plt2.colorsSize());
/* update alpha values for tan graph */
fg::copy(plt2.alphas(), plt2.alphasSize(), (const void*)alphas.data());
copyToGLBuffer(handles[3], (ComputeResourceHandle)alphas.data(), plt2.alphasSize());
/* update marker sizes for tan graph markers */
fg::copy(plt2.markers(), plt2.markersSize(), (const void*)radii.data());
copyToGLBuffer(handles[4], (ComputeResourceHandle)radii.data(), plt2.markersSize());

do {
wnd.draw(chart);
} while(!wnd.close());

// destroy GL-CPU Interop buffer
releaseGLBuffer(handles[0]);
releaseGLBuffer(handles[1]);
releaseGLBuffer(handles[2]);
releaseGLBuffer(handles[3]);
releaseGLBuffer(handles[4]);
return 0;
}
91 changes: 91 additions & 0 deletions examples/cpu/field.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*******************************************************
* Copyright (c) 2015-2019, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/

#include <forge.h>
#define USE_FORGE_CPU_COPY_HELPERS
#include <ComputeCopy.h>
#include <complex>
#include <cmath>
#include <vector>
#include <iostream>

const unsigned DIMX = 640;
const unsigned DIMY = 480;
const float PI = 3.14159265359;
const float MINIMUM = 1.0f;
const float MAXIMUM = 20.f;
const float STEP = 2.0f;
const float NELEMS = (MAXIMUM-MINIMUM+1)/STEP;
const unsigned DPOINTS[] = {5, 5, 5, 15, 15, 5, 15, 15};

using namespace std;

void generatePoints(std::vector<float> &points, std::vector<float> &dirs)
{
points.clear();

for (int j=0; j<NELEMS; ++j) {
float y = MINIMUM + j*STEP;
for (int i=0; i<NELEMS; ++i) {
float x = MINIMUM + i*STEP;
points.push_back(x);
points.push_back(y);
dirs.push_back(sin(2*PI*x/10.f));
dirs.push_back(sin(2*PI*y/10.f));
}
}
}

int main(void)
{
/*
* First Forge call should be a window creation call
* so that necessary OpenGL context is created for any
* other fg::* object to be created successfully
*/
fg::Window wnd(DIMX, DIMY, "Vector Field Demo");
wnd.makeCurrent();

fg::Chart chart(FG_CHART_2D);
chart.setAxesLimits(MINIMUM-1.0f, MAXIMUM, MINIMUM-1.0f, MAXIMUM);
chart.setAxesTitles("x-axis", "y-axis");

fg::Plot divPoints = chart.plot(4, fg::u32, FG_PLOT_SCATTER, FG_MARKER_CIRCLE);
divPoints.setColor(0.9f, 0.9f, 0.0f, 1.f);
divPoints.setLegend("Convergence Points");
divPoints.setMarkerSize(24);

fg::VectorField field = chart.vectorField(NELEMS*NELEMS, fg::f32);
field.setColor(0.f, 0.6f, 0.3f, 1.f);

std::vector<float> points;
std::vector<float> dirs;
generatePoints(points, dirs);

GfxHandle* handles[3];

createGLBuffer(&handles[0], divPoints.vertices(), FORGE_VBO);
createGLBuffer(&handles[1], field.vertices(), FORGE_VBO);
createGLBuffer(&handles[2], field.directions(), FORGE_VBO);

copyToGLBuffer(handles[0], (ComputeResourceHandle)DPOINTS, divPoints.verticesSize());
copyToGLBuffer(handles[1], (ComputeResourceHandle)points.data(), field.verticesSize());
copyToGLBuffer(handles[2], (ComputeResourceHandle)dirs.data(), field.directionsSize());

do {
wnd.draw(chart);
} while(!wnd.close());

// destroy GL-cpu interop buffers
releaseGLBuffer(handles[0]);
releaseGLBuffer(handles[1]);
releaseGLBuffer(handles[2]);

return 0;
}
14 changes: 12 additions & 2 deletions examples/cpu/fractal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
********************************************************/

#include <forge.h>
#include <CPUCopy.hpp>
#define USE_FORGE_CPU_COPY_HELPERS
#include <ComputeCopy.h>
#include <complex>
#include <cmath>

Expand Down Expand Up @@ -63,12 +64,21 @@ int main(void)
* along with the library to help with this task
*/
kernel(bmp);
fg::copy(img, (const void*)bmp.ptr);

GfxHandle* handle = 0;

// create GL-CPU interop buffer
createGLBuffer(&handle, img.pbo(), FORGE_PBO);

// copy the data from compute buffer to graphics buffer
copyToGLBuffer(handle, (ComputeResourceHandle)bmp.ptr, img.size());

do {
wnd.draw(img);
} while(!wnd.close());

// destroy GL-CPU Interop buffer
releaseGLBuffer(handle);
destroyBitmap(bmp);
return 0;
}
Expand Down
22 changes: 18 additions & 4 deletions examples/cpu/histogram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
********************************************************/

#include <forge.h>
#include <CPUCopy.hpp>
#define USE_FORGE_CPU_COPY_HELPERS
#include <ComputeCopy.h>
#include <complex>
#include <cmath>
#include <cstdlib>
Expand Down Expand Up @@ -85,13 +86,22 @@ int main(void)
*/
hist.setColor(FG_YELLOW);

GfxHandle* handles[3];

createGLBuffer(&handles[0], img.pbo(), FORGE_PBO);
createGLBuffer(&handles[1], hist.vertices(), FORGE_VBO);
createGLBuffer(&handles[2], hist.colors(), FORGE_VBO);

do {
/*
* generate image, and prepare data to pass into
* Histogram's underlying vertex buffer object
*/
kernel(bmp);
fg::copy(img, (const void*)bmp.ptr);

copyToGLBuffer(handles[0], (ComputeResourceHandle)bmp.ptr, img.size());

//fg::copy(img, (const void*)bmp.ptr);

/* copy your data into the vertex buffer object exposed by
* fg::Histogram class and then proceed to rendering.
Expand All @@ -103,15 +113,19 @@ int main(void)
std::vector<float> colArray(3*NBINS, 0.0f);
populateBins(bmp, histArray.data(), NBINS, colArray.data());

fg::copy(hist.vertices(), hist.verticesSize(), (const void*)histArray.data());
fg::copy(hist.colors(), hist.colorsSize(), (const void*)colArray.data());
copyToGLBuffer(handles[1], (ComputeResourceHandle)histArray.data(), hist.verticesSize());
copyToGLBuffer(handles[2], (ComputeResourceHandle)colArray.data(), hist.colorsSize());

wnd.draw(0, 0, img, "Dynamic Perlin Noise" );
wnd.draw(1, 0, chart, "Histogram of Noisy Image");

wnd.swapBuffers();
} while(!wnd.close());

releaseGLBuffer(handles[0]);
releaseGLBuffer(handles[1]);
releaseGLBuffer(handles[2]);

return 0;
}

Expand Down
Loading