Skip to content

Fix compilation in MacOS for Xcode 10.2.1 by #3

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 23 additions & 2 deletions AVX_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,23 @@ class Quaternion8f
}
};

//from Eigen/src/Core/util/Memory.h, added alignment parameter
inline void* handmade_aligned_malloc(std::size_t size, std::size_t alignment)
{
void *original = std::malloc(size+alignment);
if (original == 0) return 0;
void *aligned = reinterpret_cast<void*>((reinterpret_cast<std::size_t>(original) & ~(std::size_t(alignment-1))) + alignment);
*(reinterpret_cast<void**>(aligned) - 1) = original;
return aligned;
}

//from Eigen/src/Core/util/Memory.h
inline void handmade_aligned_free(void *ptr)
{
if (ptr) std::free(*(reinterpret_cast<void**>(ptr) - 1));
}


// ----------------------------------------------------------------------------------------------
//alligned allocator so that vectorized types can be used in std containers
//from: https://stackoverflow.com/questions/8456236/how-is-a-vectors-data-aligned
Expand Down Expand Up @@ -503,9 +520,11 @@ class AlignmentAllocator {
inline pointer allocate(size_type n) {
#ifdef _WIN32
return (pointer)_aligned_malloc(n * sizeof(value_type), N);
#elif __linux__
#elif defined(__linux__)
// NB! Argument order is opposite from MSVC/Windows
return (pointer) aligned_alloc(N, n * sizeof(value_type));
#elif defined(__APPLE__)
return (pointer) handmade_aligned_malloc(n * sizeof(value_type), N);
#else
#error "Unknown platform"
#endif
Expand All @@ -514,8 +533,10 @@ class AlignmentAllocator {
inline void deallocate(pointer p, size_type) {
#ifdef _WIN32
_aligned_free(p);
#elif __linux__
#elif defined(__linux__)
free(p);
#elif defined(__APPLE__)
handmade_aligned_free(p);
#else
#error "Unknown platform"
#endif
Expand Down
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
add_compile_options(/arch:AVX)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options("-mavx")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
add_compile_options("-mavx")
endif()

set(EIGEN3_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/extern/eigen")
Expand Down Expand Up @@ -65,8 +67,9 @@ if (WIN32)
add_dependencies(FastCorotDemo freeglut)
else()
find_package(GLUT REQUIRED)
endif()

endif()

set_target_properties(FastCorotDemo PROPERTIES CXX_STANDARD 11)
target_link_libraries(FastCorotDemo ${OPENGL_LIBRARIES} ${GLUT_LIBRARIES})

add_definitions(-DDATA_PATH="${PROJECT_PATH}/meshes/")
add_definitions(-DDATA_PATH="${PROJECT_PATH}/meshes/")
18 changes: 9 additions & 9 deletions FastCorotFEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool FastCorotFEM::initialize(
vector<Triplet<Real>> triplets_M;
triplets_M.reserve(4 * nTets);
vector<Real> Kreal(nTets);
vector<Real[4][3]> Dt(nTets);
vector<Eigen::Matrix<Real,4,3> > Dt(nTets);
vector<Matrix3r> Dm_inv(nTets);
vector<Real> rest_volume(nTets);
vector<Real> invMass(nVerts);
Expand Down Expand Up @@ -98,16 +98,16 @@ bool FastCorotFEM::initialize(

//compute matrix D_t from Eq. (9) (actually Dt[t] is D_t^T)
for (int k = 0; k < 3; k++)
Dt[t][0][k] = -Dm_inv[t](0, k) - Dm_inv[t](1, k) - Dm_inv[t](2, k);
Dt[t](0,k) = -Dm_inv[t](0, k) - Dm_inv[t](1, k) - Dm_inv[t](2, k);

for (int j = 1; j < 4; j++)
for (int k = 0; k < 3; k++)
Dt[t][j][k] = Dm_inv[t](j - 1, k);
Dt[t](j,k) = Dm_inv[t](j - 1, k);

//initialize the matrix D
for (int i = 0; i<4; i++)
for (int j = 0; j < 3; j++)
triplets_D.push_back(Triplet<Real>(9 * t + 3 * j, it[i], Dt[t][i][j]));
triplets_D.push_back(Triplet<Real>(9 * t + 3 * j, it[i], Dt[t](i,j)));
}

//set matrices
Expand Down Expand Up @@ -577,8 +577,8 @@ void FastCorotFEM::convertToAVX(const vector<Real>& v, vector<Scalarf8, Alignmen
// ----------------------------------------------------------------------------------------------
//
void FastCorotFEM::convertToAVX(
const vector<Real[4][3]>& v,
vector<vector<vector<Scalarf8, AlignmentAllocator<Scalarf8, 32>>>>& vAVX)
const vector<Eigen::Matrix<Real,4,3> >& v,
vector<vector<vector<Scalarf8, AlignmentAllocator<Scalarf8, 32> > > >& vAVX)
{
int regularPart = (nTets / 8) * 8;
for (int i = 0; i < regularPart; i += 8)
Expand All @@ -588,7 +588,7 @@ void FastCorotFEM::convertToAVX(
{
vAVX[i / 8][j].resize(3);
for (int k = 0; k < 3; k++)
vAVX[i / 8][j][k] = Scalarf8(v[i + 0][j][k], v[i + 1][j][k], v[i + 2][j][k], v[i + 3][j][k], v[i + 4][j][k], v[i + 5][j][k], v[i + 6][j][k], v[i + 7][j][k]);
vAVX[i / 8][j][k] = Scalarf8(v[i + 0](j,k), v[i + 1](j,k), v[i + 2](j,k), v[i + 3](j,k), v[i + 4](j,k), v[i + 5](j,k), v[i + 6](j,k), v[i + 7](j,k));
}
}

Expand All @@ -601,8 +601,8 @@ void FastCorotFEM::convertToAVX(
{
Real vtmp[8];
for (int i = regularPart; i < regularPart + 8; i++)
if (i < nTets) vtmp[i - regularPart] = v[i][j][k];
else vtmp[i - regularPart] = v[nTets - 1][j][k];
if (i < nTets) vtmp[i - regularPart] = v[i](j,k);
else vtmp[i - regularPart] = v[nTets - 1](j,k);

vAVX[regularPart/ 8][j][k] = Scalarf8(vtmp[0], vtmp[1], vtmp[2], vtmp[3], vtmp[4], vtmp[5], vtmp[6], vtmp[7]);
}
Expand Down
2 changes: 1 addition & 1 deletion FastCorotFEM.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class FastCorotFEM
std::vector<Scalarf8, AlignmentAllocator<Scalarf8, 32>>& vAVX);

void convertToAVX(
const std::vector<Real[4][3]>& v,
const std::vector<Eigen::Matrix<Real,4,3>>& v,
std::vector<std::vector<std::vector<Scalarf8, AlignmentAllocator<Scalarf8, 32>>>>& vAVX);
};
#endif
5 changes: 5 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
#include "utilities/MiniGL.h"
#include "utilities/Timing.h"
#include "TetModel.h"

#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include "GL/glut.h"
#endif

INIT_TIMING

Expand Down
6 changes: 3 additions & 3 deletions utilities/MiniGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#ifdef __APPLE__
#include <OpenGL/GL.h>
#include <OpenGL/GLU.h>
#include <GLUT/glut.h>
#else
#include "GL/gl.h"
#include "GL/glu.h"
#endif

#include "GL/glut.h"
#include "GL/freeglut_ext.h"
#endif

#define _USE_MATH_DEFINES

Expand Down Expand Up @@ -944,7 +944,7 @@ void MiniGL::breakPointMainLoop()
m_breakPointLoop = true;
while (m_breakPointLoop)
{
glutMainLoopEvent();
glutMainLoop();
}
}
}