Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ArrayFire Internals to use Forge v1.0 #1800

Merged
merged 3 commits into from
Jun 10, 2017
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
4 changes: 3 additions & 1 deletion CMakeModules/build_forge.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ELSE()
ENDIF(WIN32)
ENDIF()

SET(FORGE_VERSION 0.9.2)
SET(FORGE_VERSION 1.0.1)

# FIXME Tag forge correctly during release
ExternalProject_Add(
Expand All @@ -69,6 +69,8 @@ ExternalProject_Add(
-DUSE_SYSTEM_GLBINDING:BOOL=TRUE
-Dglbinding_DIR:STRING=${glbinding_DIR}
-DGLFW_ROOT_DIR:STRING=${GLFW_ROOT_DIR}
-DBOOST_ROOT:PATH=${BOOST_ROOT}
-DBOOST_INCLUDEDIR:PATH=${BOOST_INCLUDEDIR}
-DFREEIMAGE_INCLUDE_PATH:PATH=${FREEIMAGE_INCLUDE_PATH}
-DFREEIMAGE_DYNAMIC_LIBRARY:PATH=${FREEIMAGE_DYNAMIC_LIBRARY}
-DFREEIMAGE_STATIC_LIBRARY:PATH=${FREEIMAGE_STATIC_LIBRARY}
Expand Down
21 changes: 19 additions & 2 deletions src/api/c/graphics_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <platform.hpp>
#include <util.hpp>
#include <mutex>
#include <utility>

using namespace std;
using namespace gl;
Expand Down Expand Up @@ -246,6 +247,7 @@ void ForgeManager::setWindowChartGrid(const forge::Window* window,
const int r, const int c)
{
ChartMapIter iter = mChartMap.find(window);
GridMapIter gIter = mWndGridMap.find(window);

if(iter != mChartMap.end()) {
// ChartVec found. Clear it.
Expand All @@ -258,25 +260,40 @@ void ForgeManager::setWindowChartGrid(const forge::Window* window,
}
}
(iter->second).clear();
gIter->second = std::make_pair<int, int>(1, 1);
}

if(r == 0 || c == 0) {
mChartMap.erase(window);
mWndGridMap.erase(window);
} else {
mChartMap[window] = std::vector<forge::Chart*>(r * c);
mWndGridMap[window] = std::make_pair(r, c);
}
}

WindGridDims_t ForgeManager::getWindowGrid(const forge::Window* window)
{
GridMapIter gIter = mWndGridMap.find(window);

if (gIter == mWndGridMap.end()) {
mWndGridMap[window] = std::make_pair(1, 1);
}

return mWndGridMap[window];
}

forge::Chart* ForgeManager::getChart(const forge::Window* window, const int r, const int c,
const forge::ChartType ctype)
{
forge::Chart* chart = NULL;
ChartMapIter iter = mChartMap.find(window);
GridMapIter gIter = mWndGridMap.find(window);

if (iter != mChartMap.end()) {

int gRows = window->gridRows();
int gCols = window->gridCols();
int gRows = std::get<0>(gIter->second);
int gCols = std::get<1>(gIter->second);

if(c >= gCols || r >= gRows)
AF_ERROR("Grid points are out of bounds", AF_ERR_TYPE);
Expand Down
5 changes: 5 additions & 0 deletions src/api/c/graphics_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ typedef VectorFieldMap_t::iterator VcfMapIter;

typedef std::vector<forge::Chart*> ChartVec_t;
typedef std::map<const forge::Window*, ChartVec_t> ChartMap_t;
typedef std::pair<int, int> WindGridDims_t;
typedef std::map<const forge::Window*, WindGridDims_t> WindGridMap_t;
typedef ChartVec_t::iterator ChartVecIter;
typedef ChartMap_t::iterator ChartMapIter;
typedef WindGridMap_t::iterator GridMapIter;

// Keeps track of which charts have manually assigned axes limits
typedef std::map<forge::Chart*, bool> ChartAxesOverride_t;
Expand Down Expand Up @@ -97,6 +100,7 @@ class ForgeManager
VectorFieldMap_t mVcfMap;

ChartMap_t mChartMap;
WindGridMap_t mWndGridMap;
ChartAxesOverride_t mChartAxesOverrideMap;

public:
Expand All @@ -109,6 +113,7 @@ class ForgeManager
void setWindowChartGrid(const forge::Window* window,
const int r, const int c);

WindGridDims_t getWindowGrid(const forge::Window* window);
forge::Chart* getChart(const forge::Window* window, const int r, const int c,
const forge::ChartType ctype);

Expand Down
4 changes: 3 additions & 1 deletion src/api/c/hist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,11 @@ af_err af_draw_hist(const af_window wind, const af_array X, const double minval,
default: TYPE_ERROR(1, Xtype);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
// Window's draw function requires either image or chart
if (props->col > -1 && props->row > -1)
window->draw(props->row, props->col, *chart, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*chart, props->title);
else
window->draw(*chart);
}
Expand Down
4 changes: 3 additions & 1 deletion src/api/c/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,11 @@ af_err af_draw_image(const af_window wind, const af_array in, const af_cell* con
default: TYPE_ERROR(1, type);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
window->setColorMap((forge::ColorMap)props->cmap);
if (props->col>-1 && props->row>-1)
window->draw(props->row, props->col, *image, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*image, props->title);
else
window->draw(*image);
}
Expand Down
12 changes: 9 additions & 3 deletions src/api/c/plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ af_err plotWrapper(const af_window wind, const af_array in, const int order_dim,
default: TYPE_ERROR(1, type);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
// Window's draw function requires either image or chart
if (props->col>-1 && props->row>-1)
window->draw(props->row, props->col, *chart, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*chart, props->title);
else
window->draw(*chart);
}
Expand Down Expand Up @@ -212,9 +214,11 @@ af_err plotWrapper(const af_window wind, const af_array X, const af_array Y, con
default: TYPE_ERROR(1, xType);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
// Window's draw function requires either image or chart
if (props->col>-1 && props->row>-1)
window->draw(props->row, props->col, *chart, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*chart, props->title);
else
window->draw(*chart);

Expand Down Expand Up @@ -266,9 +270,11 @@ af_err plotWrapper(const af_window wind, const af_array X, const af_array Y,
default: TYPE_ERROR(1, xType);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
// Window's draw function requires either image or chart
if (props->col>-1 && props->row>-1)
window->draw(props->row, props->col, *chart, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*chart, props->title);
else
window->draw(*chart);

Expand Down
4 changes: 3 additions & 1 deletion src/api/c/surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,10 @@ af_err af_draw_surface(const af_window wind, const af_array xVals, const af_arra
default: TYPE_ERROR(1, Xtype);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
if (props->col>-1 && props->row>-1)
window->draw(props->row, props->col, *chart, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*chart, props->title);
else
window->draw(*chart);
}
Expand Down
12 changes: 9 additions & 3 deletions src/api/c/vector_field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ af_err vectorFieldWrapper(const af_window wind, const af_array points, const af_
default: TYPE_ERROR(1, pType);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
// Window's draw function requires either image or chart
if (props->col > -1 && props->row > -1)
window->draw(props->row, props->col, *chart, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*chart, props->title);
else
window->draw(*chart);
}
Expand Down Expand Up @@ -247,9 +249,11 @@ af_err vectorFieldWrapper(const af_window wind,
default: TYPE_ERROR(1, xpType);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
// Window's draw function requires either image or chart
if (props->col > -1 && props->row > -1)
window->draw(props->row, props->col, *chart, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*chart, props->title);
else
window->draw(*chart);
}
Expand Down Expand Up @@ -323,9 +327,11 @@ af_err vectorFieldWrapper(const af_window wind,
default: TYPE_ERROR(1, xpType);
}

auto gridDims = ForgeManager::getInstance().getWindowGrid(window);
// Window's draw function requires either image or chart
if (props->col > -1 && props->row > -1)
window->draw(props->row, props->col, *chart, props->title);
window->draw(gridDims.first, gridDims.second, props->col * gridDims.first + props->row,
*chart, props->title);
else
window->draw(*chart);
}
Expand Down
1 change: 0 additions & 1 deletion src/api/c/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ af_err af_grid(const af_window wind, const int rows, const int cols)

try {
forge::Window* wnd = reinterpret_cast<forge::Window*>(wind);
wnd->grid(rows, cols);

// Recreate a chart map
ForgeManager& fgMngr = ForgeManager::getInstance();
Expand Down
8 changes: 7 additions & 1 deletion src/backend/cuda/GraphicsResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ ShrdResVector GraphicsResourceManager::registerResources(std::vector<uint32_t> r
ShrdResVector output;

auto deleter = [](CGR_t* handle) {
CUDA_CHECK(cudaGraphicsUnregisterResource(*handle));
//FIXME Having a CUDA_CHECK around unregister
//call is causing invalid GL context.
//Moving ForgeManager class singleton as data
//member of DeviceManager with proper ordering
//of member destruction doesn't help either.
//Calling makeContextCurrent also doesn't help.
cudaGraphicsUnregisterResource(*handle);
delete handle;
};

Expand Down