Skip to content

Commit

Permalink
Add Fortran90 interface for Rocmon (RRZE-HPC#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTheBear authored Nov 7, 2023
1 parent efdf173 commit 1240792
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ $(GENGROUPLOCK): $(foreach directory,$(shell ls $(GROUP_DIR)), $(wildcard $(GROU
$(Q)$(GEN_GROUPS) ./groups $(BUILD_DIR) ./perl/templates
$(Q)touch $(GENGROUPLOCK)

$(FORTRAN_IF): $(SRC_DIR)/likwid.f90
$(FORTRAN_IF): $(SRC_DIR)/likwid.F90
@echo "===> COMPILE FORTRAN INTERFACE $@"
$(Q)$(FC) -c $(FCFLAGS) $<
@rm -f likwid.o
Expand Down
2 changes: 1 addition & 1 deletion doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ WARN_LOGFILE =
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.

INPUT = ./src/includes/likwid.h ./src/includes/likwid-marker.h ./doc/likwid-doxygen.md ./src/includes/perfmon_types.h ./src/includes/topology_types.h ./src/includes/power_types.h ./src/includes/tree_types.h ./doc/archs/ ./doc/lua-doxygen.md ./doc/applications/ ./doc/likwid.cfg.md ./src/likwid.f90
INPUT = ./src/includes/likwid.h ./src/includes/likwid-marker.h ./doc/likwid-doxygen.md ./src/includes/perfmon_types.h ./src/includes/topology_types.h ./src/includes/power_types.h ./src/includes/tree_types.h ./doc/archs/ ./doc/lua-doxygen.md ./doc/applications/ ./doc/likwid.cfg.md ./src/likwid.F90

# This tag can be used to specify the character encoding of the source files
# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
Expand Down
2 changes: 2 additions & 0 deletions doc/likwid-doxygen.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ Optionally, a global configuration file \ref likwid.cfg can be given to modify s

\subsection Fortran90_Interface Fortran90 Interface
- \ref Fortran_Interface
- \ref Fortran_RocmGPU_Interface
- \ref Fortran_NvGPU_Interface

\section Architectures Supported Architectures
\subsection Architectures_X86 X86 Architectures
Expand Down
88 changes: 86 additions & 2 deletions src/likwid.f90 → src/likwid.F90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
! =======================================================================================
!
! Filename: likwid.f90
! Filename: likwid.F90
!
! Description: Marker API f90 module
!
Expand Down Expand Up @@ -124,7 +124,7 @@ subroutine likwid_markerResetRegion( regionTag )
character(*) :: regionTag
end subroutine likwid_markerResetRegion


#ifdef LIKWID_WITH_NVMON
!> \ingroup Fortran_NvGPU_Interface
!! \brief Initialize the Likwid NvMarker API
!! This routine initializes the NvMarker API for Fortran. It reads some
Expand Down Expand Up @@ -204,6 +204,90 @@ subroutine likwid_NvMarkerResetRegion( regionTag )
character(*) :: regionTag
end subroutine likwid_NvMarkerResetRegion

#endif /* LIKWID_WITH_NVMON */

#ifdef LIKWID_WITH_ROCMON
!> \ingroup Fortran_RocmGPU_Interface
!! \brief Initialize the Likwid RocmonMarker API
!! This routine initializes the RocmonMarker API for Fortran. It reads some
!! environment commonly set by likwid-perfctr.
!! \note Must be called once in a serial region.
subroutine likwid_RocmMarkerInit()
end subroutine likwid_RocmMarkerInit

!> \ingroup Fortran_RocmGPU_Interface
!! \brief Setup performance counters for the next event set
!! If multiple groups should be measured this function
!! switches to the next group in a round robin fashion.
!! Each call reprogramms the performance counters for the current CPU,
!! \note Do not call it while measuring a code region.
subroutine likwid_RocmMarkerNextGroup()
end subroutine likwid_RocmMarkerNextGroup

!> \ingroup Fortran_RocmGPU_Interface
!! \brief Close the Likwid RocmonMarker API
!! Close the Likwid Marker API and write measured results to temporary file
!! for evaluation done by likwid-perfctr
!! \note Must be called once in a serial region and no further
!! Likwid calls should be used
subroutine likwid_RocmMarkerClose()
end subroutine likwid_RocmMarkerClose

!> \ingroup Fortran_RocmGPU_Interface
!! \brief Register a code region
!! Initializes the hash table with an empty entry to reduce the overhead
!! at likwid_RocmMarkerStartRegion()
subroutine likwid_RocmMarkerRegisterRegion( regionTag )
!> \param regionTag Name for the code region for later identification
character(*) :: regionTag
end subroutine likwid_RocmMarkerRegisterRegion


!> \ingroup Fortran_RocmGPU_Interface
!! \brief Start the measurement for a code region
!! Reads the currently running event set and store the results as start values.
!! for the measurement group identified by regionTag
subroutine likwid_RocmMarkerStartRegion( regionTag )
!> \param regionTag Name for the code region for later identification
character(*) :: regionTag
end subroutine likwid_RocmMarkerStartRegion

!> \ingroup Fortran_RocmGPU_Interface
!! \brief Stop the measurement for a code region
!! Reads the currently running event set and accumulate the difference between
!! stop and start data in the measurement group identified by regionTag.
subroutine likwid_RocmMarkerStopRegion( regionTag )
!> \param regionTag Name for the code region for later identification
character(*) :: regionTag
end subroutine likwid_RocmMarkerStopRegion

!> \ingroup Fortran_RocmGPU_Interface
!! \brief Get accumulated measurement results for a code region
!! Get the accumulated data in the measurement group identified by regionTag
!! for the current thread.
!! \warning Experimental
!! subroutine likwid_markerGetRegion( regionTag, nr_events, events, time, count )
!> \param regionTag [in] Name for the code region for later identification
!! \param nr_events [in,out] Length of the events array
!! \param events [out] Events array to store intermediate results
!! \param time [out] Accumulated measurement time
!! \param count [out] Call count of the region
!! character(*) :: regionTag
!! INTEGER :: nr_events
!! DOUBLE PRECISION, DIMENSION(*) :: events
!! DOUBLE PRECISION :: time
!! INTEGER :: count
!! end subroutine likwid_markerGetRegion

!> \ingroup Fortran_RocmGPU_Interface
!! \brief Reset the counters for a code region to zero
subroutine likwid_RocmMarkerResetRegion( regionTag )
!> \param regionTag Name for the code region for later identification
character(*) :: regionTag
end subroutine likwid_RocmMarkerResetRegion

#endif LIKWID_WITH_ROCMON

end interface

end module likwid
Expand Down
92 changes: 92 additions & 0 deletions src/likwid_f90_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,95 @@ likwid_nvmarkerresetregion_(char* regionTag, int len)
free(tmp);
}
#endif

#ifdef LIKWID_WITH_ROCMON
void __attribute__ ((visibility ("default") ))
likwid_rocmmarkerinit_(void)
{
rocmon_markerInit();
}


void __attribute__ ((visibility ("default") ))
likwid_rocmmarkerclose_(void)
{
rocmon_markerClose();
}

void __attribute__ ((visibility ("default") ))
likwid_rocmmarkernextgroup_(void)
{
rocmon_markerNextGroup();
}

void __attribute__ ((visibility ("default") ))
likwid_rocmmarkerregisterregion_(char* regionTag, int len)
{
char* tmp = (char*) malloc((len+1) * sizeof(char) );
strncpy(tmp, regionTag, len * sizeof(char) );

for (int i=(len-1); len > 0; len--)
{
if (tmp[i] != ' ') {
tmp[i+1] = 0;
break;
}
}

rocmon_markerRegisterRegion( tmp );
free(tmp);
}

void __attribute__ ((visibility ("default") ))
likwid_rocmmarkerstartregion_(char* regionTag, int len)
{
char* tmp = (char*) malloc((len+1) * sizeof(char) );
strncpy(tmp, regionTag, len * sizeof(char) );

for (int i=(len-1); len > 0; len--)
{
if (tmp[i] != ' ') {
tmp[i+1] = 0;
break;
}
}

rocmon_markerStartRegion( tmp );
free(tmp);
}

void __attribute__ ((visibility ("default") ))
likwid_rocmmarkerstopregion_(char* regionTag, int len)
{
char* tmp = (char*) malloc((len+1) * sizeof(char));
strncpy(tmp, regionTag, len * sizeof(char) );

for (int i=(len-1); len > 0; len--)
{
if (tmp[i] != ' ') {
tmp[i+1] = 0;
break;
}
}

rocmon_markerStopRegion( tmp );
free(tmp);
}

void __attribute__ ((visibility ("default") ))
likwid_rocmmarkerresetregion_(char* regionTag, int len)
{
char* tmp = (char*) malloc((len+1) * sizeof(char));
strncpy(tmp, regionTag, len * sizeof(char) );

for (int i=(len-1); len > 0; len--)
{
if (tmp[i] != ' ') {
tmp[i+1] = 0;
break;
}
}
rocmon_markerResetRegion( tmp);
free(tmp);
}
#endif /* LIKWID_WITH_ROCMON */

0 comments on commit 1240792

Please sign in to comment.