How to use cudaMemset3D in Cuda Fortran

hello!
In cuda fortran. cuda 11.4 pgfortran
we try to set int value=9 to a 3D arrary “idev”.
however,after
error = cudaMalloc3D(devPtr, extent)
error =cudaMemset3D(devPtr, 9, extent)
devPtr%ptr is a pointer

while we try to use call c_f_pointer(devPtr%ptr, idev, ishap)
the value of the returned “idev” !=9
**
program cublasTest
use cublas
use cudafor
use iso_c_binding

  implicit none

  INTEGER,PARAMETER::m = 600
  INTEGER,PARAMETER::n = 300
  INTEGER,PARAMETER::p = 3

  integer,pointer,device :: idev(:,:,:)
  integer ishap(3)
  type(cudaPitchedPtr) :: devPtr
  type(cudaExtent) :: extent
  INTEGER::i,wz(m,n,p),error

  extent%width = m
  extent%height = n
  extent%depth = p

  error = cudaMalloc3D(devPtr, extent)
 
  ishap(1) = devPtr%pitch / 4
  ishap(2) = n
  ishap(3) = p

  call c_f_pointer(devPtr%ptr, idev, ishap)

  error = cudaMemset3D(devPtr, 9, extent)

  call c_f_pointer(devPtr%ptr, idev, ishap)

  wz=idev(1:m,1:n,1:p)

  write(*,*),'wz =',wz(1,1,:)

end program cublasTest
**

the code is compiled and executed without errors.
**
pgfortran -acc -Mcuda -o a.out a.f90
**
the results is:
**
wz = 151587081 151587081 151587081
**
Question:
How can i set idev=9 through cudaMemset3D IN FORTRAN.
AND. will cudaMemset3D quicker than idev(:,:,:)=9

test_cuda7.f90 (914 Bytes)

Thank you for your help,

hwei

I would not use cudaMemset3D. Just a normal assignment between host and device arrays is much easier, and will perform as good or better.

thanks so much.
I am not very familiar with Cuda fortran programming. Do you mean: if give the 3D array idev(:,:,:) a value (e.g., value=9) on the device, just
" idev(:,:,:) =9 "
will be good?

I just want to find a way to set 3D array = value quicker.
will opeanacc be quicker?

Yes, just
integer, device :: idev(m,n,p)
idev = 9

Should be fast, about as fast as possible.

wow. thanks a lot
Here, just for learn cudamemset3D(),
if i want set idev = 9 by cudamemset3D() successfully,
what sentence should i use, after error = cudaMemset3D(devPtr, 9, extent) ?

i had fixed it.
Just a similar mistake to cudaMemset3D in cuda C. for my pgfortran option and program.
cudaMemset3D
integer function cudaMemset3D(pitchptr, value, cext)
type(cudaPitchedPtr) :: pitchptr
integer :: value
type(cudaExtent) :: cext

The ‘value’ should not be ‘integer’, indeed all 4 bytes of the element in idev is set =9.

that’s why i get 151587081 ,when i set value=9.
just 151587081=16843009*9

hwei