Unable to allocate linked list pointer in device code in Cuda Fortran

Hi, why the above code post by bleback cannot be compiled and with the error ‘PGF90-F-0155-Compiler failed to translate accelerator region (see -Minfo messages): Unsupported procedure’? I found the error may be caused by ‘allocate(pointer)’, how to allocate linked list pointer in device code?

Thanks a lot.

-Yu

how to allocate linked list pointer in device code?

To reiterate what Brent posted, using linked list is a poor choice for a data structure with GPU programming and parallel programming in general. Brent does given an example on how to do this, but it’s not recommended.

‘PGF90-F-0155-Compiler failed to translate accelerator region (see -Minfo messages): Unsupported procedure’? I found the error may be caused by ‘allocate(pointer)’,

Does the message tell you which procedure isn’t supported?

Device allocation has been supported for quite awhile (with some limits), so I’d need more detail and preferable a minimal reproducing example to understand why you would be getting this error.

Thanks, Mat

I used the code posted by Brent, but failed. Here is the resoure file, please help me see what the problem is. Many thanks.
linked_list_test.f90 (987 Bytes)

Looks like we didn’t add this support until 21.3

% nvfortran -cuda linked_list_test.f90 -V21.1 -fast
NVFORTRAN-F-0155-Compiler failed to translate accelerator region (see -Minfo messages): Unsupported procedure (linked_list_test.f90: 1)
NVFORTRAN/x86-64 Linux 21.1-0: compilation aborted
% nvfortran -cuda linked_list_test.f90 -V21.3 -fast
%

You’ll need to switch to using Linux or WSL2 with a more recent compiler version.

-Mat

Thank you, Mat

I tried it, too, and the result like you said. So it seems that I need to transfer my codes to Linux platform and compile it using a more recent compiler version because the Windows version is still not available.

Another question, my code consists of many fortran subroutine, I found this mistake:

only exists in one of my subroutines. So can I only write this subroutine into C++ language and compile it into external library by using recent CUDA Toolkit (NVCC compiler with CUDA C++) in Windows platform, then I compile my other fortran codes by using PGI Windows version and write interface calling CUDA C++ external library? I don’t know whether this operation will be supported?

-Yu

CUDA Fortran is interoperable with CUDA C. Though you do need to worry about general Fortran to C binding and interoperability of data types. Best to use C instead of C++ (at least for the interfaces to Fortran), since C++ name mangling is difficult to work with.

Thank you very much, Mat

Now I switch to use the latest version 22.5 of the HPC compiler on Linux, but I find another question made me confused. In my codes, I use the library ‘cuSPARSE’, it can successfully compiled in previous PGI compiler windows version 19.10, while the error occurs in HPC 22.5 on Linux with ‘undefined reference to cusparseCreateSolveAnalysisInfo, cusparseDcsrsv_analysis, cusparseDcsrsv_solve’. I read the documension and I don’t find the name and usage of these three function changed. Do you know why the error occurs? If the ‘cuSPARSE’ is not included and called in my codes correctly, the error should also occur in other places where the library is called.

-Yu

Hi Yu,

The “csrsv” routines were removed from cuSPARSE several releases ago. There’s “csrsv2” routines, but these have been deprecated as well. These should be changed to use the “SpSv” routines.

See: cuSPARSE :: CUDA Toolkit Documentation
and cuSPARSE :: CUDA Toolkit Documentation

-Mat

Yes, that’s true. Thank you very much, Mat.

Hi Mat,

After the kernel function finishes, I want to transmit some data from GPU to CPU, the code is “Istat = cudaMemcpy (Array, Array_D, Num)” and the dimensions of these two arrays are the same. But it fails with the error “0: copyout Memcpy (host=0x1648c0c0, dev=0x7f2a72e04c00, size=4) FAILED: 700(an illegal memory access was encountered)”, I’ve been debugging for a long time and haven’t found anything wrong, do you know what this error probably caused by?

Thank you.

Given kernels are launched asynchronously, if you don’t catch kernel errors, they’ll appear when doing the next Cuda operation… Hence, I’d look to the kernel executed just before the memcpy since it’s likely where the illegal error message is coming from.

-Mat

Thanks Mat.

The above error is really due to the kernel internal error (i.e., the wrong usage of linked list pointer in the kernel).

In the kernel, I create a linked list:

      Module Linked_List_GPU 

      Implicit None
      
	  Type :: List_GPU 
		  Integer :: Column
		  Double Precision :: Value
		  Type (List_GPU), Device, Pointer :: Next
	  End Type
	  Type (List_GPU), Device, Pointer :: Head, Tail
	  Type (List_GPU), Device, Pointer :: Pointer_Row_Start(:)
	  
      End Module Linked_List_GPU     

Then, in a device subroutine, I use the linked list as follows:

      Attributes(Device) Subroutine Form_Linked_List_GPU()

      Use Linked_List_GPU

      Type (List_GPU), Pointer :: Pointer0, Pointer1, Pointer2, New_Value

      ...

      Pointer0 => Pointer_Row_Start(a)%Next     
      Pointer1 => Pointer0
      Pointer2 => Pointer0

      Pointer1 => Pointer2    
      Pointer2 => Pointer2%next

      Allocate(New_Value) 
      Pointer1%Next => New_Value		  
      New_Value%Next => Pointer2   
				  
      ...

When the kernel runs to “Pointer2 => Pointer2%next”, it fails and directly returns to the host subroutine without printing any error information. Do you know why this code is wrong?

-Yu

Best guess is that Pointer2 has a bad address so when it’s dereferenced, the illegal address error occurs. Which if correct, means “Pointer_Row_Start(a)%Next” is bad.

How is “Pointer_Row_Start(a)%Next” created? Does it contain a valid device address?

Yes, Mat. I also think “Pointer_Row_Start(a)%Next” is bad, and the device address is illegal. As you can see, I define “Pointer_Row_Start(:)” with the attribute “device” in the module, because I want to use it in the device, and then I allocate and initialize “Pointer_Row_Start(:)” in the host program as follows:

      Program Linked_List_Test

      Use Linked_List_GPU

      ...

      Allocate(Pointer_Row_Start(Number))

      ...

      Do I=1,Number
		 If ( .Not.Associated(Head) ) Then	
			Allocate( Head )	
			Tail => Head
			Nullify(Tail%Next)
			Tail%Value  = 0
			Tail%Column = 0
			Pointer_Row_Start(I)%Next => Tail
		 Else
			Allocate( Tail%Next )
			Tail => Tail%Next
			Nullify(Tail%Next)
			Tail%Value  = 0
			Tail%Column = 0
			Pointer_Row_Start(I)%Next => Tail
		 End If
	  End Do
      ...

My original intention is to create a linked list on GPU and then save Value and Column on GPU. But I find although I define these pointers (i.e., Pointer_Row_Start(:), Head, Tail, Next) with the attribute “device”, it seems that these pointers still exist on CPU, not contain a valid device address, because I can output the value and column of these pointers in the host, while device data is not allowed to be I/O in the host in principle. So I think the usage of the linked list pointer is wrong, do you know how to define and use the linked list pointer, to ensure them containing a valid device address, executed and stored the value and column on GPU?

At first, to ensure the variables related to the linked list defined on GPU, I also define the Column and Value of the derived data with the attribute “device”, like this:

	  Type :: List_GPU 
		  Integer, Device :: Column
		  Double Precision, Device :: Value
		  Type (List_GPU), Device, Pointer :: Next
	  End Type

But it seems that the compiler does not allow this, and the error occurs during compilation. So I’m very worried that although my pointers have the attribute “device”, but the Column and Value don’t have the attribute “device”, resulting in that my linked list is not completely located on GPU.

Thank you very much, Mat.

-Yu

Hi Yu,

Since you didn’t provide a reproducing example code, it’s a bit difficult to say what’s wrong here. It appears you may be trying to build the list from the host, which would be problematic given you’d be allocating host addresses.

If this is being done on the device, you’d have a separate problem in that each “Pointer_Row_Start” element will most likely have it’s own value and column, it’s not getting the values from “tail”, just the next pointer is updated. Hence, I’d probably make this an array of a type that contains the pointer to the node.

Another item I not sure about is that you name the array “Pointer_Row_Start” which implies to me that each contains the starting head node of a list (row). But how you’ve coded here it seem more a quick way to index into the list without having to traverse it.

Again, we don’t recommend using linked list. They are poor choice for use in parallel programming. It might be better if each thread managed it’s own row, but it’s likely that using multidimensional arrays of types would be better. Though, you probably have your reasons as to why to use linked lists, so I wont question.

Below are two example codes that I just wrote, the first if you want Pointer_Row_Start to be a quick index into the list, and the second if Pointer_Row_Start has it’s own list. I can’t say if this is the best or most efficient way to write these (given I don’t use linked lists on GPUs), but hopefully will help you work through the issue you’re having with your code.

Example 1

% cat linked.cuf
MODULE ListModule
  IMPLICIT NONE

  TYPE node
     Integer :: Column
     DOUBLE PRECISION              :: value;
     TYPE(node), POINTER :: next;
  END TYPE node

  TYPE node_list
    TYPE(node), POINTER :: node;
  end type node_list

  type(node_list), allocatable, dimension(:), device :: Pointer_Row_Start

end module ListModule

module test
  use listmodule

  CONTAINS
    ATTRIBUTES(GLOBAL) SUBROUTINE createList(Number)
    IMPLICIT NONE
    integer, value :: Number
    type( node ), pointer, device :: head, tail, next
    integer :: i
    do i=1,Number
       if (.not.associated(head)) then
         allocate(head)
         tail=>head
         nullify(tail%next)
         tail%value=i
         tail%column=i
         Pointer_Row_Start(i)%node => tail
       else
         allocate(next)
         tail%next => next
         tail=>tail%next
         nullify(next)
         nullify(tail%next)
         tail%value=i
         tail%column=i
         Pointer_Row_Start(i)%node => tail
       endif
    end do
    End subroutine createList

    ATTRIBUTES(GLOBAL) SUBROUTINE printList(start)
      integer, value :: start
      type( node ), pointer :: curr

      print *, "=== START at ", start, "==========="
      curr => Pointer_Row_Start(start)%node
      do while(associated(curr))
         print *, curr%value, curr%column
         curr=>curr%next
      end do

    end subroutine printList
END MODULE test


PROGRAM LinkedList
  USE listmodule
  use test
  USE CUDAFOR

  integer :: Number
  Number=32
  allocate(Pointer_Row_Start(Number))
  CALL createList<<<1,1>>>(Number)
  CALL printList<<<1,1>>>(1)
  CALL printList<<<1,1>>>(30)
  N=cudaDeviceSynchronize()
END PROGRAM LinkedList
% nvfortran linked.cuf; a.out
 === START at             1 ===========
    1.000000000000000                 1
    2.000000000000000                 2
    3.000000000000000                 3
    4.000000000000000                 4
    5.000000000000000                 5
    6.000000000000000                 6
    7.000000000000000                 7
    8.000000000000000                 8
    9.000000000000000                 9
    10.00000000000000                10
    11.00000000000000                11
    12.00000000000000                12
    13.00000000000000                13
    14.00000000000000                14
    15.00000000000000                15
    16.00000000000000                16
    17.00000000000000                17
    18.00000000000000                18
    19.00000000000000                19
    20.00000000000000                20
    21.00000000000000                21
    22.00000000000000                22
    23.00000000000000                23
    24.00000000000000                24
    25.00000000000000                25
    26.00000000000000                26
    27.00000000000000                27
    28.00000000000000                28
    29.00000000000000                29
    30.00000000000000                30
    31.00000000000000                31
    32.00000000000000                32
 === START at            30 ===========
    30.00000000000000                30
    31.00000000000000                31
    32.00000000000000                32

Example 2:

% cat linkedRow.cuf
MODULE ListModule
  IMPLICIT NONE

  TYPE node
     Integer :: Column
     DOUBLE PRECISION              :: value;
     TYPE(node), POINTER :: next;
  END TYPE node

  TYPE node_list
    TYPE(node), POINTER :: head;
  end type node_list

  type(node_list), allocatable, dimension(:), device :: Pointer_Row_Start

end module ListModule

module test
  use listmodule

  CONTAINS
    ATTRIBUTES(GLOBAL) SUBROUTINE createRow(rowid,numnodes)
    IMPLICIT NONE
    integer, value :: rowid,numnodes
    type( node ), pointer, device ::  head,curr, next
    integer :: i

    nullify(head)
    Pointer_Row_Start(rowid)%head=>head
    do i=1,numnodes
       if (.not.associated(head)) then
         allocate(head)
         Pointer_Row_Start(rowid)%head=>head
         curr=>head
         curr%value=rowid
         curr%column=i
         nullify(curr%next)
      else
         allocate(next)
         curr%next=>next
         curr=>next
         nullify(curr%next)
         curr%value=rowid
         curr%column=i
      endif
    end do

    End subroutine createRow

    ATTRIBUTES(GLOBAL) SUBROUTINE printRow(rowid)
      integer, value :: rowid
      type( node ), pointer :: curr

      print *, "=== Row ", rowid , "==========="
      curr => Pointer_Row_Start(rowid)%head
      do while(associated(curr))
         print *, curr%value, curr%column
         curr=>curr%next
      end do

    end subroutine printRow
END MODULE test


PROGRAM LinkedList
  USE listmodule
  use test
  USE CUDAFOR

  integer :: numRows, rowid
  numRows=32
  allocate(Pointer_Row_Start(numRows))
  do rowid=1,numRows
     CALL createRow<<<1,1>>>(rowid,rowid-1)
  enddo
  do rowid=1,numRows
     CALL printRow<<<1,1>>>(rowid)
  enddo
  N=cudaDeviceSynchronize()
END PROGRAM LinkedList
dev-sky5:/local/home/mcolgrove% nvfortran linkedRow.cuf ; a.out
 === Row             1 ===========
 === Row             2 ===========
    2.000000000000000                 1
 === Row             3 ===========
    3.000000000000000                 1
    3.000000000000000                 2
 === Row             4 ===========
    4.000000000000000                 1
    4.000000000000000                 2
    4.000000000000000                 3
 === Row             5 ===========
    5.000000000000000                 1
    5.000000000000000                 2
    5.000000000000000                 3
    5.000000000000000                 4
 === Row             6 ===========
    6.000000000000000                 1
    6.000000000000000                 2
    6.000000000000000                 3
    6.000000000000000                 4
    6.000000000000000                 5
 === Row             7 ===========
    7.000000000000000                 1
    7.000000000000000                 2
    7.000000000000000                 3
    7.000000000000000                 4
    7.000000000000000                 5
    7.000000000000000                 6
 === Row             8 ===========
    8.000000000000000                 1
    8.000000000000000                 2
    8.000000000000000                 3
    8.000000000000000                 4
    8.000000000000000                 5
    8.000000000000000                 6
    8.000000000000000                 7
 === Row             9 ===========
    9.000000000000000                 1
    9.000000000000000                 2
    9.000000000000000                 3
    9.000000000000000                 4
    9.000000000000000                 5
    9.000000000000000                 6
    9.000000000000000                 7
    9.000000000000000                 8
 === Row            10 ===========
    10.00000000000000                 1
    10.00000000000000                 2
    10.00000000000000                 3
    10.00000000000000                 4
    10.00000000000000                 5
    10.00000000000000                 6
    10.00000000000000                 7
    10.00000000000000                 8
    10.00000000000000                 9
 === Row            11 ===========
    11.00000000000000                 1
    11.00000000000000                 2
    11.00000000000000                 3
    11.00000000000000                 4
    11.00000000000000                 5
    11.00000000000000                 6
    11.00000000000000                 7
    11.00000000000000                 8
    11.00000000000000                 9
    11.00000000000000                10
 === Row            12 ===========
    12.00000000000000                 1
    12.00000000000000                 2
    12.00000000000000                 3
    12.00000000000000                 4
    12.00000000000000                 5
    12.00000000000000                 6
    12.00000000000000                 7
    12.00000000000000                 8
    12.00000000000000                 9
    12.00000000000000                10
    12.00000000000000                11
 === Row            13 ===========
    13.00000000000000                 1
    13.00000000000000                 2
    13.00000000000000                 3
    13.00000000000000                 4
    13.00000000000000                 5
    13.00000000000000                 6
    13.00000000000000                 7
    13.00000000000000                 8
    13.00000000000000                 9
    13.00000000000000                10
    13.00000000000000                11
    13.00000000000000                12
 === Row            14 ===========
    14.00000000000000                 1
    14.00000000000000                 2
    14.00000000000000                 3
    14.00000000000000                 4
    14.00000000000000                 5
    14.00000000000000                 6
    14.00000000000000                 7
    14.00000000000000                 8
    14.00000000000000                 9
    14.00000000000000                10
    14.00000000000000                11
    14.00000000000000                12
    14.00000000000000                13
 === Row            15 ===========
    15.00000000000000                 1
    15.00000000000000                 2
    15.00000000000000                 3
    15.00000000000000                 4
    15.00000000000000                 5
    15.00000000000000                 6
    15.00000000000000                 7
    15.00000000000000                 8
    15.00000000000000                 9
    15.00000000000000                10
    15.00000000000000                11
    15.00000000000000                12
    15.00000000000000                13
    15.00000000000000                14
 === Row            16 ===========
    16.00000000000000                 1
    16.00000000000000                 2
    16.00000000000000                 3
    16.00000000000000                 4
    16.00000000000000                 5
    16.00000000000000                 6
    16.00000000000000                 7
    16.00000000000000                 8
    16.00000000000000                 9
    16.00000000000000                10
    16.00000000000000                11
    16.00000000000000                12
    16.00000000000000                13
    16.00000000000000                14
    16.00000000000000                15
 === Row            17 ===========
    17.00000000000000                 1
    17.00000000000000                 2
    17.00000000000000                 3
    17.00000000000000                 4
    17.00000000000000                 5
    17.00000000000000                 6
    17.00000000000000                 7
    17.00000000000000                 8
    17.00000000000000                 9
    17.00000000000000                10
    17.00000000000000                11
    17.00000000000000                12
    17.00000000000000                13
    17.00000000000000                14
    17.00000000000000                15
    17.00000000000000                16
 === Row            18 ===========
    18.00000000000000                 1
    18.00000000000000                 2
    18.00000000000000                 3
    18.00000000000000                 4
    18.00000000000000                 5
    18.00000000000000                 6
    18.00000000000000                 7
    18.00000000000000                 8
    18.00000000000000                 9
    18.00000000000000                10
    18.00000000000000                11
    18.00000000000000                12
    18.00000000000000                13
    18.00000000000000                14
    18.00000000000000                15
    18.00000000000000                16
    18.00000000000000                17
 === Row            19 ===========
    19.00000000000000                 1
    19.00000000000000                 2
    19.00000000000000                 3
    19.00000000000000                 4
    19.00000000000000                 5
    19.00000000000000                 6
    19.00000000000000                 7
    19.00000000000000                 8
    19.00000000000000                 9
    19.00000000000000                10
    19.00000000000000                11
    19.00000000000000                12
    19.00000000000000                13
    19.00000000000000                14
    19.00000000000000                15
    19.00000000000000                16
    19.00000000000000                17
    19.00000000000000                18
 === Row            20 ===========
    20.00000000000000                 1
    20.00000000000000                 2
    20.00000000000000                 3
    20.00000000000000                 4
    20.00000000000000                 5
    20.00000000000000                 6
    20.00000000000000                 7
    20.00000000000000                 8
    20.00000000000000                 9
    20.00000000000000                10
    20.00000000000000                11
    20.00000000000000                12
    20.00000000000000                13
    20.00000000000000                14
    20.00000000000000                15
    20.00000000000000                16
    20.00000000000000                17
    20.00000000000000                18
    20.00000000000000                19
 === Row            21 ===========
    21.00000000000000                 1
    21.00000000000000                 2
    21.00000000000000                 3
    21.00000000000000                 4
    21.00000000000000                 5
    21.00000000000000                 6
    21.00000000000000                 7
    21.00000000000000                 8
    21.00000000000000                 9
    21.00000000000000                10
    21.00000000000000                11
    21.00000000000000                12
    21.00000000000000                13
    21.00000000000000                14
    21.00000000000000                15
    21.00000000000000                16
    21.00000000000000                17
    21.00000000000000                18
    21.00000000000000                19
    21.00000000000000                20
 === Row            22 ===========
    22.00000000000000                 1
    22.00000000000000                 2
    22.00000000000000                 3
    22.00000000000000                 4
    22.00000000000000                 5
    22.00000000000000                 6
    22.00000000000000                 7
    22.00000000000000                 8
    22.00000000000000                 9
    22.00000000000000                10
    22.00000000000000                11
    22.00000000000000                12
    22.00000000000000                13
    22.00000000000000                14
    22.00000000000000                15
    22.00000000000000                16
    22.00000000000000                17
    22.00000000000000                18
    22.00000000000000                19
    22.00000000000000                20
    22.00000000000000                21
 === Row            23 ===========
    23.00000000000000                 1
    23.00000000000000                 2
    23.00000000000000                 3
    23.00000000000000                 4
    23.00000000000000                 5
    23.00000000000000                 6
    23.00000000000000                 7
    23.00000000000000                 8
    23.00000000000000                 9
    23.00000000000000                10
    23.00000000000000                11
    23.00000000000000                12
    23.00000000000000                13
    23.00000000000000                14
    23.00000000000000                15
    23.00000000000000                16
    23.00000000000000                17
    23.00000000000000                18
    23.00000000000000                19
    23.00000000000000                20
    23.00000000000000                21
    23.00000000000000                22
 === Row            24 ===========
    24.00000000000000                 1
    24.00000000000000                 2
    24.00000000000000                 3
    24.00000000000000                 4
    24.00000000000000                 5
    24.00000000000000                 6
    24.00000000000000                 7
    24.00000000000000                 8
    24.00000000000000                 9
    24.00000000000000                10
    24.00000000000000                11
    24.00000000000000                12
    24.00000000000000                13
    24.00000000000000                14
    24.00000000000000                15
    24.00000000000000                16
    24.00000000000000                17
    24.00000000000000                18
    24.00000000000000                19
    24.00000000000000                20
    24.00000000000000                21
    24.00000000000000                22
    24.00000000000000                23
 === Row            25 ===========
    25.00000000000000                 1
    25.00000000000000                 2
    25.00000000000000                 3
    25.00000000000000                 4
    25.00000000000000                 5
    25.00000000000000                 6
    25.00000000000000                 7
    25.00000000000000                 8
    25.00000000000000                 9
    25.00000000000000                10
    25.00000000000000                11
    25.00000000000000                12
    25.00000000000000                13
    25.00000000000000                14
    25.00000000000000                15
    25.00000000000000                16
    25.00000000000000                17
    25.00000000000000                18
    25.00000000000000                19
    25.00000000000000                20
    25.00000000000000                21
    25.00000000000000                22
    25.00000000000000                23
    25.00000000000000                24
 === Row            26 ===========
    26.00000000000000                 1
    26.00000000000000                 2
    26.00000000000000                 3
    26.00000000000000                 4
    26.00000000000000                 5
    26.00000000000000                 6
    26.00000000000000                 7
    26.00000000000000                 8
    26.00000000000000                 9
    26.00000000000000                10
    26.00000000000000                11
    26.00000000000000                12
    26.00000000000000                13
    26.00000000000000                14
    26.00000000000000                15
    26.00000000000000                16
    26.00000000000000                17
    26.00000000000000                18
    26.00000000000000                19
    26.00000000000000                20
    26.00000000000000                21
    26.00000000000000                22
    26.00000000000000                23
    26.00000000000000                24
    26.00000000000000                25
 === Row            27 ===========
    27.00000000000000                 1
    27.00000000000000                 2
    27.00000000000000                 3
    27.00000000000000                 4
    27.00000000000000                 5
    27.00000000000000                 6
    27.00000000000000                 7
    27.00000000000000                 8
    27.00000000000000                 9
    27.00000000000000                10
    27.00000000000000                11
    27.00000000000000                12
    27.00000000000000                13
    27.00000000000000                14
    27.00000000000000                15
    27.00000000000000                16
    27.00000000000000                17
    27.00000000000000                18
    27.00000000000000                19
    27.00000000000000                20
    27.00000000000000                21
    27.00000000000000                22
    27.00000000000000                23
    27.00000000000000                24
    27.00000000000000                25
    27.00000000000000                26
 === Row            28 ===========
    28.00000000000000                 1
    28.00000000000000                 2
    28.00000000000000                 3
    28.00000000000000                 4
    28.00000000000000                 5
    28.00000000000000                 6
    28.00000000000000                 7
    28.00000000000000                 8
    28.00000000000000                 9
    28.00000000000000                10
    28.00000000000000                11
    28.00000000000000                12
    28.00000000000000                13
    28.00000000000000                14
    28.00000000000000                15
    28.00000000000000                16
    28.00000000000000                17
    28.00000000000000                18
    28.00000000000000                19
    28.00000000000000                20
    28.00000000000000                21
    28.00000000000000                22
    28.00000000000000                23
    28.00000000000000                24
    28.00000000000000                25
    28.00000000000000                26
    28.00000000000000                27
 === Row            29 ===========
    29.00000000000000                 1
    29.00000000000000                 2
    29.00000000000000                 3
    29.00000000000000                 4
    29.00000000000000                 5
    29.00000000000000                 6
    29.00000000000000                 7
    29.00000000000000                 8
    29.00000000000000                 9
    29.00000000000000                10
    29.00000000000000                11
    29.00000000000000                12
    29.00000000000000                13
    29.00000000000000                14
    29.00000000000000                15
    29.00000000000000                16
    29.00000000000000                17
    29.00000000000000                18
    29.00000000000000                19
    29.00000000000000                20
    29.00000000000000                21
    29.00000000000000                22
    29.00000000000000                23
    29.00000000000000                24
    29.00000000000000                25
    29.00000000000000                26
    29.00000000000000                27
    29.00000000000000                28
 === Row            30 ===========
    30.00000000000000                 1
    30.00000000000000                 2
    30.00000000000000                 3
    30.00000000000000                 4
    30.00000000000000                 5
    30.00000000000000                 6
    30.00000000000000                 7
    30.00000000000000                 8
    30.00000000000000                 9
    30.00000000000000                10
    30.00000000000000                11
    30.00000000000000                12
    30.00000000000000                13
    30.00000000000000                14
    30.00000000000000                15
    30.00000000000000                16
    30.00000000000000                17
    30.00000000000000                18
    30.00000000000000                19
    30.00000000000000                20
    30.00000000000000                21
    30.00000000000000                22
    30.00000000000000                23
    30.00000000000000                24
    30.00000000000000                25
    30.00000000000000                26
    30.00000000000000                27
    30.00000000000000                28
    30.00000000000000                29
 === Row            31 ===========
    31.00000000000000                 1
    31.00000000000000                 2
    31.00000000000000                 3
    31.00000000000000                 4
    31.00000000000000                 5
    31.00000000000000                 6
    31.00000000000000                 7
    31.00000000000000                 8
    31.00000000000000                 9
    31.00000000000000                10
    31.00000000000000                11
    31.00000000000000                12
    31.00000000000000                13
    31.00000000000000                14
    31.00000000000000                15
    31.00000000000000                16
    31.00000000000000                17
    31.00000000000000                18
    31.00000000000000                19
    31.00000000000000                20
    31.00000000000000                21
    31.00000000000000                22
    31.00000000000000                23
    31.00000000000000                24
    31.00000000000000                25
    31.00000000000000                26
    31.00000000000000                27
    31.00000000000000                28
    31.00000000000000                29
    31.00000000000000                30
 === Row            32 ===========
    32.00000000000000                 1
    32.00000000000000                 2
    32.00000000000000                 3
    32.00000000000000                 4
    32.00000000000000                 5
    32.00000000000000                 6
    32.00000000000000                 7
    32.00000000000000                 8
    32.00000000000000                 9
    32.00000000000000                10
    32.00000000000000                11
    32.00000000000000                12
    32.00000000000000                13
    32.00000000000000                14
    32.00000000000000                15
    32.00000000000000                16
    32.00000000000000                17
    32.00000000000000                18
    32.00000000000000                19
    32.00000000000000                20
    32.00000000000000                21
    32.00000000000000                22
    32.00000000000000                23
    32.00000000000000                24
    32.00000000000000                25
    32.00000000000000                26
    32.00000000000000                27
    32.00000000000000                28
    32.00000000000000                29
    32.00000000000000                30
    32.00000000000000                31

-Mat

Many thanks to you, Mat.

I successfully solved this problem according to your first example 1, which is exactly what I want to achieve!

Thank you again.

-Yu

Hi, Mat

I’m sorry to bother you again. I just write a F90 file to try to call cusparseSpSV, and the program can be compiled successfully but it fails with the error “Segmentation fault (Core dumped)” when running. According to the website cuSPARSE :: CUDA Toolkit Documentation and the official example file “spsv_csr_example.c”, I can hardly find the error in my code, could you please help me see it?

Here is the source files, one is the example c file from the official website, another is my source F90 code.

Thank you very much.

-Yu
GPU_Sparse_Solver.f90 (4.8 KB)
spsv_csr_example.c (9.6 KB)

Hi Yu,

I see two issues.

First “Alpha” should be a host variable, so remove the “device” attribute. This appears to be the source of the segv.

Second, the bufferSize being returned is in bytes, so declare “Buffer” to be an “integer(1)”. Not a big issue except you’d be allocating 4 times the amount of memory than needed.

FYI, we do ship a few CUDA Fortran cuSparse examples in the “<install_dir>///examples/CUDA-Libraries/cuSPARSE” directory which may be helpful.

-Mat

Thank you, Mat

The function cusparseSpSV can be used successfully, but I find only the upper or lower triangular part of the square matrix is taken into account in the computation. In cuSPARSE :: CUDA Toolkit Documentation, the introduction of cusparseSpSV is:

It did mention that the routine supports arbitrary sparsity for the input matrix, but only the upper or lower triangular part is taken into account in the computation.

In the “<install_dir>///examples/CUDA-Libraries/cuSPARSE” directory, I have seen many expamples but they are all cusparseSpMV. If I want to solve a system of linear equations whose coefficients are represented in a sparse matrix (CSR format, Double Precision), which function should I use? Considering all non-zero elements of the square matrix, not only the upper or lower triangular part.

This is out of my area of expertise so don’t have a specific recommendation, but perhaps cuSOLVER has more of what you’re looking for?