18 USE iso_c_binding,
ONLY: c_char, &
23 USE iso_fortran_env,
ONLY: input_unit, &
25 USE omp_lib,
ONLY: omp_get_wtime
31#include "libxsmm_version.h"
32#if !defined(__LIBXSMM2) && (1 < __LIBXSMM || (1170000 < \
33 (libxsmm_config_version_major*1000000\
34 +libxsmm_config_version_minor*10000\
35 +libxsmm_config_version_update*100\
36 +libxsmm_config_version_patch)))
39#if defined(__LIBXSMM2)
40 USE libxsmm,
ONLY: libxsmm_timer_tick, libxsmm_timer_duration, libxsmm_get_target_archid, &
41 libxsmm_target_arch_generic, libxsmm_x86_sse4, libxsmm_x86_avx, libxsmm_x86_avx2, &
42 libxsmm_x86_avx512_skx, libxsmm_aarch64_v81, libxsmm_aarch64_sve128
44 USE libxsmm,
ONLY: libxsmm_timer_tick, libxsmm_timer_duration, libxsmm_get_target_archid, &
45 libxsmm_target_arch_generic, libxsmm_x86_sse4, libxsmm_x86_avx, libxsmm_x86_avx2, &
46 libxsmm_x86_avx512_skx => libxsmm_x86_avx512_core
62#include "machine_cpuid.h"
69 INTEGER,
PUBLIC,
PARAMETER :: &
136 INTEGER,
INTENT(IN) :: lunit
155#if defined(__LIBXSMM)
156 wt = libxsmm_timer_duration(0_int_8, libxsmm_timer_tick())
167 CHARACTER(LEN=default_string_length),
INTENT(OUT) :: model_name
169 INTEGER,
PARAMETER :: bufferlen = 2048
171 CHARACTER(LEN=bufferlen) :: buffer
172 INTEGER :: i, icol, iline, stat
174 model_name =
"UNKNOWN"
176 OPEN (121245, file=
"/proc/cpuinfo", action=
"READ", status=
"OLD", access=
"STREAM", iostat=stat)
179 READ (121245,
END=999) buffer(I:I)
182 i = index(buffer,
"model name")
184 icol = i - 1 + index(buffer(i:),
":")
185 iline = icol - 1 + index(buffer(icol:), new_line(
'A'))
186 IF (iline == icol - 1) iline = bufferlen + 1
187 model_name = buffer(icol + 1:iline - 1)
201#if !defined(__LIBXSMM)
207 archid = libxsmm_get_target_archid()
208 IF (libxsmm_x86_sse4 <= archid .AND. archid < libxsmm_x86_avx)
THEN
210 ELSE IF (libxsmm_x86_avx <= archid .AND. archid < libxsmm_x86_avx2)
THEN
212 ELSE IF (libxsmm_x86_avx2 <= archid .AND. archid < libxsmm_x86_avx512_skx)
THEN
214 ELSE IF (libxsmm_x86_avx512_skx <= archid .AND. archid <= 1999)
THEN
218#if defined(__LIBXSMM2)
220 IF (libxsmm_aarch64_v81 <= archid .AND. archid < libxsmm_aarch64_sve128)
THEN
222 ELSE IF (libxsmm_aarch64_sve128 <= archid .AND. archid < 2401)
THEN
224 ELSE IF (2401 <= archid .AND. archid <= 2999)
THEN
245 INTEGER,
INTENT(IN),
OPTIONAL :: cpuid
250 IF (
PRESENT(cpuid))
THEN
289 INTEGER,
INTENT(IN),
OPTIONAL :: cpuid, typesize
292 INTEGER :: isa, nbytes
294 IF (
PRESENT(typesize))
THEN
300 IF (0 < nbytes .AND. nbytes <= 16)
THEN
301 IF (
PRESENT(cpuid))
THEN
343#if defined(__CRAY_PM_ENERGY)
344 wt = read_energy(
"/sys/cray/pm_counters/energy")
345#elif defined(__CRAY_PM_ACCEL_ENERGY)
346 wt = read_energy(
"/sys/cray/pm_counters/accel_energy")
353#if defined(__CRAY_PM_ACCEL_ENERGY) || defined(__CRAY_PM_ENERGY)
361 FUNCTION read_energy(filename)
RESULT(wt)
362 CHARACTER(LEN=*) :: filename
365 CHARACTER(LEN=80) :: data
367 INTEGER(KIND=int_8) :: raw
369 OPEN (121245, file=filename, action=
"READ", status=
"OLD", access=
"STREAM")
371 READ (121245,
END=999) DATA(I:I)
375 READ (
DATA, *, iostat=iostat) raw
376 IF (iostat /= 0)
THEN
382 END FUNCTION read_energy
393 CHARACTER(len=timestamp_length),
INTENT(OUT) :: timestamp
395 CHARACTER(len=10) :: time
396 CHARACTER(len=8) :: date
398 CALL date_and_time(date=date, time=time)
399 timestamp = date(1:4)//
"-"//date(5:6)//
"-"//date(7:8)//
" "// &
400 time(1:2)//
":"//time(3:4)//
":"//time(5:10)
409 SUBROUTINE abort()
BIND(C, name="abort")
423 INTEGER,
INTENT(IN) :: pid
431 FUNCTION kill(pid, sig)
BIND(C, name="kill") RESULT(errno)
433 INTEGER(KIND=C_INT),
VALUE :: pid, sig
434 INTEGER(KIND=C_INT) :: errno
442 istat = kill(pid=pid, sig=0)
457 INTEGER(KIND=int_8),
OPTIONAL,
INTENT(OUT) :: mem
458 INTEGER(KIND=int_8) :: mem_local
463#if defined(__NO_STATM_ACCESS)
466 INTEGER(KIND=int_8) :: m1, m2, m3
467 CHARACTER(LEN=80) :: data
472 FUNCTION getpagesize()
BIND(C, name="getpagesize") RESULT(RES)
474 INTEGER(C_INT) :: res
475 END FUNCTION getpagesize
482 OPEN (121245, file=
"/proc/self/statm", action=
"READ", status=
"OLD", access=
"STREAM")
484 READ (121245,
END=999) DATA(I:I)
491 READ (
DATA, *, iostat=iostat) m1, m2, m3
492 IF (iostat /= 0)
THEN
496#if defined(__STATM_TOTAL)
499#if defined(__STATM_RESIDENT)
502 mem_local = mem_local*getpagesize()
507 IF (
PRESENT(mem)) mem = mem_local
525 SUBROUTINE m_memory_details(MemTotal, MemFree, Buffers, Cached, Slab, SReclaimable, MemLikelyFree)
527 INTEGER(kind=int_8),
OPTIONAL :: memtotal, memfree, buffers, cached, slab, sreclaimable, memlikelyfree
529 INTEGER,
PARAMETER :: nbuffer = 10000
530 CHARACTER(LEN=Nbuffer) :: meminfo
543 OPEN (unit=8123, file=
"/proc/meminfo", access=
"STREAM", err=901)
547 IF (i > nbuffer)
EXIT
548 READ (8123,
END=900, ERR=900) meminfo(i:i)
551 meminfo(i:nbuffer) =
""
553 CLOSE (8123, err=902)
555 memtotal = get_field_value_in_bytes(
'MemTotal:')
556 memfree = get_field_value_in_bytes(
'MemFree:')
557 buffers = get_field_value_in_bytes(
'Buffers:')
558 cached = get_field_value_in_bytes(
'Cached:')
559 slab = get_field_value_in_bytes(
'Slab:')
560 sreclaimable = get_field_value_in_bytes(
'SReclaimable:')
562 memlikelyfree = memfree + buffers + cached + sreclaimable
571 INTEGER(int_8) FUNCTION get_field_value_in_bytes(field)
572 CHARACTER(LEN=*) :: field
575 INTEGER(KIND=int_8) :: value
577 get_field_value_in_bytes = 0
578 start = index(meminfo, field)
580 start = start + len_trim(field)
581 IF (start < nbuffer)
THEN
582 READ (meminfo(start:), *, err=999,
END=999) value
584 get_field_value_in_bytes =
value*1024
588 END FUNCTION get_field_value_in_bytes
596 CHARACTER(len=*),
INTENT(OUT) :: hname
603 CHARACTER(len=default_path_length) :: buf
606 FUNCTION gethostname(buf, buflen)
BIND(C, name="gethostname") RESULT(errno)
608 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: buf
609 INTEGER(KIND=C_INT),
VALUE :: buflen
610 INTEGER(KIND=C_INT) :: errno
611 END FUNCTION gethostname
614 istat = gethostname(buf, len(buf))
616 WRITE (*, *)
"m_hostnm failed"
619 i = index(buf, c_null_char) - 1
629 CHARACTER(len=*),
INTENT(OUT) :: curdir
632 CHARACTER(len=default_path_length),
TARGET :: tmp
635 FUNCTION getcwd(buf, buflen)
BIND(C, name="getcwd") RESULT(stat)
637 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: buf
638 INTEGER(KIND=C_INT),
VALUE :: buflen
643 stat = getcwd(tmp, len(tmp))
644 IF (.NOT. c_associated(stat))
THEN
645 WRITE (*, *)
"m_getcwd failed"
648 i = index(tmp, c_null_char) - 1
658 CHARACTER(len=*),
INTENT(IN) :: dir
659 INTEGER,
INTENT(OUT) :: ierror
662 FUNCTION chdir(path)
BIND(C, name="chdir") RESULT(errno)
664 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: path
665 INTEGER(KIND=C_INT) :: errno
669 ierror = chdir(trim(dir)//c_null_char)
677 INTEGER,
INTENT(OUT) :: pid
680 FUNCTION getpid()
BIND(C, name="getpid") RESULT(pid)
682 INTEGER(KIND=C_INT) :: pid
694 FUNCTION m_unlink(path)
RESULT(istat)
696 CHARACTER(LEN=*),
INTENT(IN) :: path
701 FUNCTION unlink(path)
BIND(C, name="unlink") RESULT(errno)
703 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: path
704 INTEGER(KIND=C_INT) :: errno
708 istat = unlink(trim(path)//c_null_char)
709 END FUNCTION m_unlink
718 CHARACTER(LEN=*),
INTENT(IN) :: source, target
723 FUNCTION rename(src, dest)
BIND(C, name="rename") RESULT(errno)
725 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: src, dest
726 INTEGER(KIND=C_INT) :: errno
730 IF (
TARGET == source)
THEN
731 WRITE (*, *)
"Warning: m_mov ", trim(
TARGET),
" equals ", trim(source)
736 istat = m_unlink(
TARGET)
740 istat = rename(trim(source)//c_null_char, trim(
TARGET)//c_null_char)
742 WRITE (*, *)
"Trying to move "//trim(source)//
" to "//trim(
TARGET)//
"."
743 WRITE (*, *)
"rename returned status: ", istat
744 WRITE (*, *)
"Problem moving file"
755 CHARACTER(LEN=*),
INTENT(OUT) :: user
760 CALL get_environment_variable(
"LOGNAME",
value=user, status=istat)
763 CALL get_environment_variable(
"USER",
value=user, status=istat)
766 CALL get_environment_variable(
"USERNAME",
value=user, status=istat)
778 CHARACTER(LEN=*),
INTENT(OUT) :: omp_stacksize
783 CALL get_environment_variable(
"OMP_STACKSIZE",
value=omp_stacksize, status=istat)
785 IF (istat /= 0) omp_stacksize =
"default"
Target architecture or instruction set extension according to compiler target flags.
Trace OpenMP constructs if ennvironment variable CP2K_OMP_TRACE=1.
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Machine interface based on Fortran 2003 and POSIX.
integer, parameter, public machine_x86_avx
logical, save, public flush_should_flush
subroutine, public m_getpid(pid)
...
integer, parameter, public machine_arm_sve512
integer, parameter, public default_output_unit
integer, parameter, public machine_x86_sse4
subroutine, public m_memory(mem)
Returns the total amount of memory [bytes] in use, if known, zero otherwise.
integer, parameter, public machine_cpu_generic
integer, parameter, public default_input_unit
integer, parameter, public timestamp_length
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
integer, parameter, public machine_arm_sve256
integer, parameter, public machine_x86_avx2
subroutine, public m_abort()
Can be used to get a nice core.
subroutine, public m_timestamp(timestamp)
Returns a human readable timestamp.
integer function, public m_procrun(pid)
Returns if a process is running on the local machine 1 if yes and 0 if not.
subroutine, public m_memory_details(memtotal, memfree, buffers, cached, slab, sreclaimable, memlikelyfree)
get more detailed memory info, all units are bytes. the only 'useful' option is MemLikelyFree which i...
pure integer function, public m_cpuid()
Target architecture or instruction set extension according to CPU-check at runtime.
subroutine, public m_getcwd(curdir)
...
integer, parameter, public machine_x86
subroutine, public m_chdir(dir, ierror)
...
pure integer function, public m_cpuid_vlen(cpuid, typesize)
Determine vector-length for a given CPUID.
real(kind=dp) function, public m_energy()
returns the energy used since some time in the past. The precise meaning depends on the infrastructur...
integer, parameter, public machine_arm
subroutine, public m_cpuinfo(model_name)
reads /proc/cpuinfo if it exists (i.e. Linux) to return relevant info
subroutine, public m_mov(source, target)
...
pure character(len=default_string_length) function, public m_cpuid_name(cpuid)
Determine name of target architecture for a given CPUID.
integer, parameter, public machine_x86_avx512
integer, parameter, public machine_arm_arch64
subroutine, public m_omp_get_stacksize(omp_stacksize)
Retrieve environment variable OMP_STACKSIZE.
integer, parameter, public machine_cpu_unknown
integer(kind=int_8), save, public m_memory_max
integer, parameter, public machine_arm_sve128
subroutine, public m_getlog(user)
...
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
subroutine, public m_hostnm(hname)
...