Skip to content

Commit

Permalink
AcquireAlignedMemory() aligns on the page boundary to improver OpenCL…
Browse files Browse the repository at this point in the history
… performanc

e
  • Loading branch information
Cristy committed Apr 1, 2017
1 parent 05a2367 commit f9c18b6
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 47 deletions.
8 changes: 4 additions & 4 deletions MagickCore/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static MagickBooleanType
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% AcquireAlignedMemory() returns a pointer to a block of memory at least size
% bytes whose address is a multiple of 16*sizeof(void *).
% bytes whose address is aligned on a page boundary.
%
% The format of the AcquireAlignedMemory method is:
%
Expand Down Expand Up @@ -249,10 +249,10 @@ MagickExport void *AcquireAlignedMemory(const size_t count,const size_t quantum)
if (HeapOverflowSanityCheck(count,quantum) != MagickFalse)
return((void *) NULL);
memory=NULL;
alignment=CACHE_LINE_SIZE;
alignment=GetMagickPageSize();
size=count*quantum;
extent=AlignedExtent(size,alignment);
if ((size == 0) || (alignment < sizeof(void *)) || (extent < size))
extent=AlignedExtent(size,CACHE_LINE_SIZE);
if ((size == 0) || (extent < size))
return((void *) NULL);
#if defined(MAGICKCORE_HAVE_POSIX_MEMALIGN)
if (posix_memalign(&memory,alignment,extent) != 0)
Expand Down
7 changes: 4 additions & 3 deletions MagickCore/semaphore.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "MagickCore/string_.h"
#include "MagickCore/thread_.h"
#include "MagickCore/thread-private.h"
#include "MagickCore/utility-private.h"

/*
Struct declaractions.
Expand Down Expand Up @@ -145,15 +146,15 @@ static void *AcquireSemaphoreMemory(const size_t count,const size_t quantum)
return((void *) NULL);
}
memory=NULL;
alignment=CACHE_LINE_SIZE;
extent=AlignedExtent(size,alignment);
alignment=GetMagickPageSize();
extent=AlignedExtent(size,CACHE_LINE_SIZE);
if ((size == 0) || (alignment < sizeof(void *)) || (extent < size))
return((void *) NULL);
#if defined(MAGICKCORE_HAVE_POSIX_MEMALIGN)
if (posix_memalign(&memory,alignment,extent) != 0)
memory=NULL;
#elif defined(MAGICKCORE_HAVE__ALIGNED_MALLOC)
memory=_aligned_malloc(extent,alignment);
memory=_aligned_malloc(extent,alignment);
#else
{
void
Expand Down
101 changes: 66 additions & 35 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ You have another version of autoconf. It may work, but is not guaranteed to.
If you have problems, you may need to regenerate the build system entirely.
To do so, use the procedure documented by the package, typically 'autoreconf'.])])

# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html
# ===========================================================================
# ============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_append_compile_flags.html
# ============================================================================
#
# SYNOPSIS
#
Expand Down Expand Up @@ -63,7 +63,7 @@ To do so, use the procedure documented by the package, typically 'autoreconf'.])
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
Expand All @@ -78,7 +78,7 @@ To do so, use the procedure documented by the package, typically 'autoreconf'.])
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.

#serial 5
#serial 6

AC_DEFUN([AX_APPEND_COMPILE_FLAGS],
[AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
Expand All @@ -89,7 +89,7 @@ done
])dnl AX_APPEND_COMPILE_FLAGS

# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_append_link_flags.html
# https://www.gnu.org/software/autoconf-archive/ax_append_link_flags.html
# ===========================================================================
#
# SYNOPSIS
Expand Down Expand Up @@ -129,7 +129,7 @@ done
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
Expand All @@ -144,7 +144,7 @@ done
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.

#serial 5
#serial 6

AC_DEFUN([AX_APPEND_LINK_FLAGS],
[AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])
Expand All @@ -155,7 +155,7 @@ done
])dnl AX_APPEND_LINK_FLAGS

# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html
# https://www.gnu.org/software/autoconf-archive/ax_check_link_flag.html
# ===========================================================================
#
# SYNOPSIS
Expand Down Expand Up @@ -196,7 +196,7 @@ done
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
# with this program. If not, see <https://www.gnu.org/licenses/>.
#
# As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure
Expand All @@ -211,7 +211,7 @@ done
# modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well.

#serial 4
#serial 5

AC_DEFUN([AX_CHECK_LINK_FLAG],
[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
Expand All @@ -230,7 +230,7 @@ AS_VAR_POPDEF([CACHEVAR])dnl
])dnl AX_CHECK_LINK_FLAGS

# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html
# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags.html
# ===========================================================================
#
# SYNOPSIS
Expand Down Expand Up @@ -332,7 +332,7 @@ AS_VAR_POPDEF([CACHEVAR])dnl
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 13
#serial 14

# _AX_COMPILER_FLAGS_LANG([LANGNAME])
m4_defun([_AX_COMPILER_FLAGS_LANG],
Expand Down Expand Up @@ -388,9 +388,9 @@ AC_DEFUN([AX_COMPILER_FLAGS],[
AX_COMPILER_FLAGS_GIR([WARN_SCANNERFLAGS],[$ax_compiler_flags_is_release])
])dnl AX_COMPILER_FLAGS

# ============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cflags.html
# ============================================================================
# =============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cflags.html
# =============================================================================
#
# SYNOPSIS
#
Expand All @@ -415,7 +415,7 @@ AC_DEFUN([AX_COMPILER_FLAGS],[
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 11
#serial 14

AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
AC_REQUIRE([AC_PROG_SED])
Expand All @@ -424,7 +424,7 @@ AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
# Variable names
m4_define(ax_warn_cflags_variable,
m4_define([ax_warn_cflags_variable],
[m4_normalize(ifelse([$1],,[WARN_CFLAGS],[$1]))])
AC_LANG_PUSH([C])
Expand All @@ -440,6 +440,13 @@ AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
ax_compiler_flags_test=""
])
# Check that -Wno-suggest-attribute=format is supported
AX_CHECK_COMPILE_FLAG([-Wno-suggest-attribute=format],[
ax_compiler_no_suggest_attribute_flags="-Wno-suggest-attribute=format"
],[
ax_compiler_no_suggest_attribute_flags=""
])
# Base flags
AX_APPEND_COMPILE_FLAGS([ dnl
-fno-strict-aliasing dnl
Expand Down Expand Up @@ -498,7 +505,7 @@ AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
AX_APPEND_FLAG([-Werror],ax_warn_cflags_variable)
AX_APPEND_COMPILE_FLAGS([ dnl
-Wno-suggest-attribute=format dnl
[$ax_compiler_no_suggest_attribute_flags] dnl
],ax_warn_cflags_variable,[$ax_compiler_flags_test])
])
Expand All @@ -522,9 +529,9 @@ AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
AC_SUBST(ax_warn_cflags_variable)
])dnl AX_COMPILER_FLAGS

# ==============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cxxflags.html
# ==============================================================================
# ===============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_cxxflags.html
# ===============================================================================
#
# SYNOPSIS
#
Expand All @@ -550,7 +557,7 @@ AC_DEFUN([AX_COMPILER_FLAGS_CFLAGS],[
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 7
#serial 10

AC_DEFUN([AX_COMPILER_FLAGS_CXXFLAGS],[
AC_REQUIRE([AC_PROG_SED])
Expand All @@ -559,7 +566,7 @@ AC_DEFUN([AX_COMPILER_FLAGS_CXXFLAGS],[
AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
# Variable names
m4_define(ax_warn_cxxflags_variable,
m4_define([ax_warn_cxxflags_variable],
[m4_normalize(ifelse([$1],,[WARN_CXXFLAGS],[$1]))])
AC_LANG_PUSH([C++])
Expand All @@ -575,6 +582,13 @@ AC_DEFUN([AX_COMPILER_FLAGS_CXXFLAGS],[
ax_compiler_flags_test=""
])
# Check that -Wno-suggest-attribute=format is supported
AX_CHECK_COMPILE_FLAG([-Wno-suggest-attribute=format],[
ax_compiler_no_suggest_attribute_flags="-Wno-suggest-attribute=format"
],[
ax_compiler_no_suggest_attribute_flags=""
])
# Base flags
AX_APPEND_COMPILE_FLAGS([ dnl
-fno-strict-aliasing dnl
Expand Down Expand Up @@ -628,7 +642,7 @@ AC_DEFUN([AX_COMPILER_FLAGS_CXXFLAGS],[
AX_APPEND_FLAG([-Werror],ax_warn_cxxflags_variable)
AX_APPEND_COMPILE_FLAGS([ dnl
-Wno-suggest-attribute=format dnl
[$ax_compiler_no_suggest_attribute_flags] dnl
],ax_warn_cxxflags_variable,[$ax_compiler_flags_test])
])
Expand All @@ -653,7 +667,7 @@ AC_DEFUN([AX_COMPILER_FLAGS_CXXFLAGS],[
])dnl AX_COMPILER_FLAGS_CXXFLAGS

# ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_gir.html
# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_gir.html
# ===========================================================================
#
# SYNOPSIS
Expand All @@ -680,13 +694,13 @@ AC_DEFUN([AX_COMPILER_FLAGS_CXXFLAGS],[
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 4
#serial 6

AC_DEFUN([AX_COMPILER_FLAGS_GIR],[
AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
# Variable names
m4_define(ax_warn_scannerflags_variable,
m4_define([ax_warn_scannerflags_variable],
[m4_normalize(ifelse([$1],,[WARN_SCANNERFLAGS],[$1]))])
# Base flags
Expand All @@ -713,9 +727,9 @@ AC_DEFUN([AX_COMPILER_FLAGS_GIR],[
AC_SUBST(ax_warn_scannerflags_variable)
])dnl AX_COMPILER_FLAGS

# =============================================================================
# http://www.gnu.org/software/autoconf-archive/ax_compiler_flags_ldflags.html
# =============================================================================
# ==============================================================================
# https://www.gnu.org/software/autoconf-archive/ax_compiler_flags_ldflags.html
# ==============================================================================
#
# SYNOPSIS
#
Expand All @@ -740,15 +754,16 @@ AC_DEFUN([AX_COMPILER_FLAGS_GIR],[
# and this notice are preserved. This file is offered as-is, without any
# warranty.

#serial 5
#serial 8

AC_DEFUN([AX_COMPILER_FLAGS_LDFLAGS],[
AX_REQUIRE_DEFINED([AX_APPEND_LINK_FLAGS])
AX_REQUIRE_DEFINED([AX_APPEND_FLAG])
AX_REQUIRE_DEFINED([AX_CHECK_COMPILE_FLAG])
AX_REQUIRE_DEFINED([AX_CHECK_LINK_FLAG])
# Variable names
m4_define(ax_warn_ldflags_variable,
m4_define([ax_warn_ldflags_variable],
[m4_normalize(ifelse([$1],,[WARN_LDFLAGS],[$1]))])
# Always pass -Werror=unknown-warning-option to get Clang to fail on bad
Expand All @@ -762,9 +777,25 @@ AC_DEFUN([AX_COMPILER_FLAGS_LDFLAGS],[
ax_compiler_flags_test=""
])
# macOS linker does not have --as-needed
AX_CHECK_LINK_FLAG([-Wl,--no-as-needed], [
ax_compiler_flags_as_needed_option="-Wl,--no-as-needed"
], [
ax_compiler_flags_as_needed_option=""
])
# macOS linker speaks with a different accent
ax_compiler_flags_fatal_warnings_option=""
AX_CHECK_LINK_FLAG([-Wl,--fatal-warnings], [
ax_compiler_flags_fatal_warnings_option="-Wl,--fatal-warnings"
])
AX_CHECK_LINK_FLAG([-Wl,-fatal_warnings], [
ax_compiler_flags_fatal_warnings_option="-Wl,-fatal_warnings"
])
# Base flags
AX_APPEND_LINK_FLAGS([ dnl
-Wl,--no-as-needed dnl
$ax_compiler_flags_as_needed_option dnl
$3 dnl
],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
Expand All @@ -781,7 +812,7 @@ AC_DEFUN([AX_COMPILER_FLAGS_LDFLAGS],[
# suggest-attribute=format is disabled because it gives too many false
# positives
AX_APPEND_LINK_FLAGS([ dnl
-Wl,--fatal-warnings dnl
$ax_compiler_flags_fatal_warnings_option dnl
],ax_warn_ldflags_variable,[$ax_compiler_flags_test])
])
Expand Down
Loading

0 comments on commit f9c18b6

Please sign in to comment.