Skip to content

[Feature]: Accept 'integer' besides 'type(c_ptr)' with hipDeviceGetAttribute #239

@tob2

Description

@tob2

Suggestion Description

The C implementation takes a pointer to an integer, i.e. int *p.

Thus, the naive and also most sensible way to call it for Fortan is:

  integer(c_int) :: ival
  my_err = hipDeviceGetAttribute (ival, attr, dev)

However, the current implementation requires a 'type(c_ptr)', i.e.

  integer(c_int), TARGET :: ival
  my_err = hipDeviceGetAttribute ( C_LOC (ival), attr, dev)

Thus, it would be very useful to accept integer(c_int) (passed by reference) — instead/besides type(c_ptr) (passed by value).

As there is already a generic interface, this can be achieved by copying the existing specific interface and changing "type(c_ptr),value" to "integer(c_int)" (without 'value')) — and changing the specific name, here by appending a second underscore.

Namely:

--- a/lib/hipfort/hipfort.f
+++ b/lib/hipfort/hipfort.f
@@ -520,24 +520,46 @@ module hipfort
   interface hipDeviceGetAttribute
 #ifdef USE_CUDA_NAMES
     function hipDeviceGetAttribute_(pi,attr,deviceId) bind(c, name="cudaDeviceGetAttribute")
 #else
     function hipDeviceGetAttribute_(pi,attr,deviceId) bind(c, name="hipDeviceGetAttribute")
 #endif
       use iso_c_binding
 #ifdef USE_CUDA_NAMES
       use hipfort_cuda_errors
 #endif
       use hipfort_enums
       use hipfort_types
       implicit none
 #ifdef USE_CUDA_NAMES
       integer(kind(cudaSuccess)) :: hipDeviceGetAttribute_
 #else
       integer(kind(hipSuccess)) :: hipDeviceGetAttribute_
 #endif
       type(c_ptr),value :: pi
       integer(kind(hipDeviceAttributeCudaCompatibleBegin)),value :: attr
       integer(c_int),value :: deviceId
     end function
 
+#ifdef USE_CUDA_NAMES
+    function hipDeviceGetAttribute__(pi,attr,deviceId) bind(c, name="cudaDeviceGetAttribute")
+#else
+    function hipDeviceGetAttribute__(pi,attr,deviceId) bind(c, name="hipDeviceGetAttribute")
+#endif
+      use iso_c_binding
+#ifdef USE_CUDA_NAMES
+      use hipfort_cuda_errors
+#endif
+      use hipfort_enums
+      use hipfort_types
+      implicit none
+#ifdef USE_CUDA_NAMES
+      integer(kind(cudaSuccess)) :: hipDeviceGetAttribute__
+#else
+      integer(kind(hipSuccess)) :: hipDeviceGetAttribute__
+#endif
+      integer(c_int) :: pi    ! <<< this line is different (plus the second '_' (trice) in the function name/ return value)
+      integer(kind(hipDeviceAttributeCudaCompatibleBegin)),value :: attr
+      integer(c_int),value :: deviceId
+    end function
+
   end interface

Operating System

No response

GPU

No response

ROCm Component

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions