ROCm / hipfort

Fortran interfaces for ROCm libraries
https://rocm.docs.amd.com/projects/hipfort/en/latest/
Other
69 stars 37 forks source link

Add support for ROCTX #149

Closed lmoriche closed 5 months ago

lmoriche commented 7 months ago

Add bindings for the roctxMarkA, roctxRangePushA, roctxRangePop, roctxRangeStartA, and roctxRangeStop ROCTX API functions.

Add a rudimentary test in teat/f2003/roctx. The test pushes a ROCTX range around a kernel dispatch and device synchronization. The test uses rocprof to trace both HIP events and ROCTX events.

cgmb commented 7 months ago

@domcharrier, we're thinking we'll manually put this interface in, rather than using the binding generator. We should still be able to use the generator for updates once it's available.

I would benefit from your expertise on this review, if you have time to spare it.

domcharrier commented 7 months ago

Interface design

Automatic code generation

This library will likely not grow dramatically in the future. So a handwritten version is fine. However, it can also be generated extremely easily. For now, keep it as it is, but you might prefer the automatically generated version in the future simply to keep track with documentation changes and the copyright year in the license text.

Conclusion

Your solution that asks the user to append c_null_char is probably the most user-friendly that one can do without adding significant and possibly fragile infrastructure to manage temporary copies of input buffers. A manually-written version is fine. In any case, it will be easy to replace it by an automatically generated version later at any time later on.

bcornille commented 6 months ago

At a minimum, the function names should match the C API without the "A" suffixes.

https://rocm.docs.amd.com/projects/roctracer/en/latest/roctracer_spec.html#roctx-application-code-annotation-api

The c_null_char requirement should also be well documented in the ROCm documentation.

https://rocm.docs.amd.com/projects/hipfort/en/latest/reference/supported_apis.html

Not having users need to append c_null_char would be much preferable. It surprises me that the roctx interfaces don't make copies internally. I would expect there to be lifetime issues if anyone tried to dynamically create a temporary strings to pass to the API.

domcharrier commented 6 months ago

@lmoriche @cgmb

Regarding @bcornille 's observation of the A suffix. I assume you chose that as the roctx header file contains macros like the one below:

#define roctxMark(message) roctxMarkA(message)

where roctxMarkA will be the name of the function symbol in the roctx shared object.

Note that you can use the bind(c,name="...") to your advantage here:

function roctxRangeStart(message) bind(c, name="roctxRangeStartA")
cgmb commented 6 months ago

Note that you can use the bind(c,name="...") to your advantage here:

function roctxRangeStart(message) bind(c, name="roctxRangeStartA")

Let's go with this. I'll apply those changes and we can get this merged.