Skip to content

Commit

Permalink
Issue #75 (frontend function to bypass cpu-id and to set arch_id): re…
Browse files Browse the repository at this point in the history
…worked API which allows to get/set the target architecture: renamed libxsmm_get_target_archid <-> libxsmm_get_target_arch. Fixed function signatures (forbid arguments). Removed internal state which was tracking the name of the target architecture (now solely relying on target id). Introduced internal_get_target_arch function, which converts target id into target name. The latter simplifies a number of internal tasks, and fosters a single point of responsibility (code reuse). Fixed libxsmm_cpuid_x86 such that the code path cannot fall below LIBXSMM_STATIC_TARGET_ARCH.
  • Loading branch information
hfp committed May 17, 2016
1 parent faed393 commit d975a23
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 134 deletions.
2 changes: 1 addition & 1 deletion include/libxsmm_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

/**
* Enumerates the available target architectures and instruction
* set extensions as returned by libxsmm_get_target_arch().
* set extensions as returned by libxsmm_get_target_archid().
*/
#define LIBXSMM_TARGET_ARCH_UNKNOWN 0
#define LIBXSMM_TARGET_ARCH_GENERIC 1
Expand Down
216 changes: 113 additions & 103 deletions src/libxsmm.c

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/libxsmm.template.f
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ MODULE LIBXSMM
& LIBXSMM_PREFETCH_BL2_VIA_C, LIBXSMM_PREFETCH_AL2_AHEAD)

! Enumerates the available target architectures and instruction
! set extensions as returned by libxsmm_get_target_arch().
! set extensions as returned by libxsmm_get_target_archid().
INTEGER(C_INT), PARAMETER :: &
& LIBXSMM_TARGET_ARCH_UNKNOWN = 0, &
& LIBXSMM_TARGET_ARCH_GENERIC = 1, &
Expand Down Expand Up @@ -242,9 +242,9 @@ PURE SUBROUTINE LIBXSMM_MMFUNCTION1(a, b, c, &
END INTERFACE

!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_init, libxsmm_finalize
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_get_target_arch
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_set_target_arch
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_get_target_archid
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_set_target_archid
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_set_target_arch
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_timer_duration
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_timer_tick
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_omp_sgemm
Expand All @@ -262,20 +262,20 @@ SUBROUTINE libxsmm_finalize() BIND(C)
! as determined by the CPUID flags. 0 != LIBXSMM_JIT and
! LIBXSMM_X86_AVX <= result, then this instruction set
! extension is targeted by the JIT code generator.
INTEGER(C_INT) PURE FUNCTION libxsmm_get_target_arch() BIND(C)
INTEGER(C_INT) PURE FUNCTION libxsmm_get_target_archid() BIND(C)
IMPORT :: C_INT
END FUNCTION

! Set target architecture (archid: see PARAMETER enumeration)
! for subsequent code generation (JIT).
SUBROUTINE libxsmm_set_target_arch(archid) BIND(C)
SUBROUTINE libxsmm_set_target_archid(archid) BIND(C)
IMPORT :: C_INT
INTEGER(C_INT), INTENT(IN), VALUE :: archid
END SUBROUTINE

! Set target architecture (id=0|wsm|snb|hsw|knl|skx, 0/NULL: CPUID)
! for subsequent code generation (JIT).
SUBROUTINE libxsmm_set_target_archid(name) BIND(C)
SUBROUTINE libxsmm_set_target_arch(name) BIND(C)
IMPORT :: C_CHAR
CHARACTER(C_CHAR), INTENT(IN) :: name(*)
END SUBROUTINE
Expand Down Expand Up @@ -320,19 +320,19 @@ SUBROUTINE libxsmm_omp_dgemm(transa, transb, m, n, k, &
CONTAINS
! Returns a name for the target architecture as identified
! by libxsmm_get_target_arch().
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_get_target_archid
FUNCTION libxsmm_get_target_archid() RESULT(name)
!DIR$ ATTRIBUTES OFFLOAD:MIC :: libxsmm_get_target_arch
FUNCTION libxsmm_get_target_arch() RESULT(name)
CHARACTER(LEN=:), ALLOCATABLE :: name
CHARACTER(LEN=16) :: tmp
!DIR$ ATTRIBUTES OFFLOAD:MIC :: get_target_archid
!DIR$ ATTRIBUTES OFFLOAD:MIC :: get_target_arch
INTERFACE
PURE SUBROUTINE get_target_archid(name, length) BIND(C)
PURE SUBROUTINE get_target_arch(name, length) BIND(C)
IMPORT :: C_CHAR, C_INT
CHARACTER(C_CHAR), INTENT(OUT) :: name(*)
INTEGER(C_INT), VALUE, INTENT(IN) :: length
END SUBROUTINE
END INTERFACE
CALL get_target_archid(tmp, LEN(tmp))
CALL get_target_arch(tmp, LEN(tmp))
name = TRIM(tmp)
END FUNCTION

Expand Down
10 changes: 5 additions & 5 deletions src/libxsmm.template.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE void libxsmm_finalize(void);
* If 0 != LIBXSMM_JIT and LIBXSMM_X86_AVX <= result, then this instruction set extension
* is targeted by the JIT code generator.
*/
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE int libxsmm_get_target_arch();
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE int libxsmm_get_target_archid(void);
/** Set target architecture (archid: see libxsmm_typedefs.h) for subsequent code generation (JIT). */
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE void libxsmm_set_target_arch(int archid);
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE void libxsmm_set_target_archid(int archid);

/** Returns a name for the target architecture as identified by libxsmm_get_target_arch(). */
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE const char* libxsmm_get_target_archid();
/** Returns a name for the target architecture as identified by libxsmm_get_target_archid(). */
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE const char* libxsmm_get_target_arch(void);
/** Set target architecture (name=0|wsm|snb|hsw|knl|skx, 0/NULL: CPUID) for subsequent code generation (JIT). */
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE void libxsmm_set_target_archid(const char* name);
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE void libxsmm_set_target_arch(const char* name);

/** Query or JIT-generate a function; return zero if it does not exist or if JIT is not supported (descriptor form). */
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE libxsmm_xmmfunction libxsmm_xmmdispatch(const libxsmm_gemm_descriptor* descriptor);
Expand Down
7 changes: 1 addition & 6 deletions src/libxsmm_cpuid_x86.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@
#endif


LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE int libxsmm_cpuid_x86(const char** archid)
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE int libxsmm_cpuid_x86(void)
{
int target_arch = LIBXSMM_STATIC_TARGET_ARCH;
unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
if (archid) *archid = "x86";

LIBXSMM_CPUID_X86(0, eax, ebx, ecx, edx);
if (1 <= eax) { /* CPUID */
Expand All @@ -68,23 +67,19 @@ LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE int libxsmm_cpuid_x86(const char** archid)
AVX512ER(0x08000000) */
if (0x1C010000 == (0x1C010000 & ebx)) {
target_arch = LIBXSMM_X86_AVX512_MIC;
if (archid) *archid = "knl";
}
/* AVX512F(0x00010000), AVX512CD(0x10000000), AVX512DQ(0x00020000),
AVX512BW(0x40000000), AVX512VL(0x80000000) */
else if (0xD0030000 == (0xD0030000 & ebx)) {
target_arch = LIBXSMM_X86_AVX512_CORE;
if (archid) *archid = "skx";
}
}
else if (0x10000000 == (0x10000000 & ecx)) { /* AVX(0x10000000) */
if (0x00001000 == (0x00001000 & ecx)) { /* FMA(0x00001000) */
target_arch = LIBXSMM_X86_AVX2;
if (archid) *archid = "hsw";
}
else {
target_arch = LIBXSMM_X86_AVX;
if (archid) *archid = "snb";
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/libxsmm_cpuid_x86.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@
#include <libxsmm.h>


/**
* Returns the target architecture and instruction set extension (code path),
* and thereby (via argument list) optionally returns an internal name of the
* target architecture.
*/
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE int libxsmm_cpuid_x86(const char** archid);
/** Returns the target architecture and instruction set extension (code path). */
LIBXSMM_EXTERN_C LIBXSMM_RETARGETABLE int libxsmm_cpuid_x86(void);


#if defined(LIBXSMM_BUILD) && !defined(LIBXSMM_CPUID_X86_NOINLINE)
Expand Down
2 changes: 1 addition & 1 deletion tests/dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int main()
if (size != nerrors) {
return size == i ? EXIT_SUCCESS : (i + 1)/*EXIT_FAILURE*/;
}
else if (LIBXSMM_X86_AVX > libxsmm_get_target_arch()) {
else if (LIBXSMM_X86_AVX > libxsmm_get_target_archid()) {
/* potentially unsupported platforms due to not supporting AVX, due to calling convention,
* or due to the environment variable LIBXSMM_JIT being set to zero.
*/
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
master-1.4.1-73
master-1.4.1-74

0 comments on commit d975a23

Please sign in to comment.