Skip to content
This repository was archived by the owner on Jul 7, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
9a6e6ef
Start stability test suite for full app.
domcharrier Sep 29, 2021
61efb5c
fort2hip/scanner: Move translator calls into scanner
domcharrier Oct 11, 2021
12e4fae
Initial implementation of default clause behaviour
domcharrier Oct 11, 2021
fc316c1
WiP on acc declare for programs/subprograms (unstable)
domcharrier Oct 12, 2021
5845a4f
WiP: More drafting on declare (unstable)
domcharrier Oct 13, 2021
8360355
WiP towards declare (unstable).
domcharrier Oct 13, 2021
9492495
Merge branch 'main' into develop-acc
domcharrier Oct 14, 2021
9277f10
Merge branch 'main' into develop-acc
domcharrier Oct 14, 2021
9c79f42
Merge branch 'main' into develop-acc
domcharrier Oct 14, 2021
3e15474
WiP towards acc declare in subroutines (unstable)
domcharrier Oct 14, 2021
8de6ead
WiP on declare: Add working example with declare in subroutine
domcharrier Oct 14, 2021
fb25e6b
WiP on acc declare wrt allocatable/pointer vars
domcharrier Oct 15, 2021
e9c4ea1
WiP on module var declare (unstable)
domcharrier Oct 18, 2021
3d54735
WiP on acc declare (unstable)
domcharrier Oct 19, 2021
ff23395
WiP on acc declare (unstable,testing)
domcharrier Oct 19, 2021
a0429d3
WiP on acc declare: Add example (unstable)
domcharrier Oct 19, 2021
b15d170
WiP on declare output formatting
domcharrier Oct 19, 2021
5775e5e
WiP on declare output formatting
domcharrier Oct 19, 2021
4440458
Merge branch 'develop-acc' of github.com:RocmSoftwarePlatform/gpufort…
domcharrier Oct 25, 2021
d5803da
WiP/gpufort acc runtime: reuse buffers & make tuneable
domcharrier Oct 25, 2021
1acbb93
bugfix: tr*_dir*.py.in: Add missing arg to intrnl fun
domcharrier Oct 26, 2021
d23cd4f
bugfix: linemapper: detect additional line cont. expr
domcharrier Oct 26, 2021
328af33
BUGFIX/translator: Fix syntax error
domcharrier Oct 28, 2021
78825fb
Add gpufort & linemapper feature
domcharrier Oct 28, 2021
ab35838
examples/openacc/vector-add-declare: Rename example
domcharrier Oct 28, 2021
c5e528c
gpufort_acc_runtime: Add opt arg to indicate module variables
domcharrier Oct 28, 2021
527f587
scoper/search_*_for_*: Allow to turn error/warning off
domcharrier Oct 28, 2021
daf779c
BUGFIX/gpufort_acc_runtime: gpufort_acc_present_... dummy arg order
domcharrier Nov 3, 2021
ad93815
REFACTOR/gpufort_acc_rt: Combine 4 opt args into enum arg
domcharrier Nov 4, 2021
bea2ac0
gpufort_options: Change default of DUMP_LINEMAPS: False
sael9740 Nov 5, 2021
bec6a16
WiP on array descriptor structs: Add C++ datatypes and tests.
domcharrier Nov 9, 2021
56a7d98
WiP on array and derived type mapping: Add Fortran array wrapper (unt…
domcharrier Nov 9, 2021
dcd5ae8
Central Makefile + multiple linked changes
domcharrier Nov 10, 2021
0e02b21
gpufort_options: change config default value of DUMP_LINEMAPS
domcharrier Nov 10, 2021
773b830
Makefile: mv mod files into platform subfolder
domcharrier Nov 10, 2021
a5760c8
WiP on gpufort array type interfacing (unstable)
domcharrier Nov 10, 2021
4ca3455
WiP on array types: Add interoperability example.
domcharrier Nov 11, 2021
06567c8
gpufort/include: Manually create cudafor hip.cpp files
domcharrier Nov 11, 2021
4434f25
Merge branch 'develop-acc' of github.com:RocmSoftwarePlatform/gpufort…
domcharrier Nov 11, 2021
3eb2b70
gpufort arrays: Rename + hostptr&devptr Fortran pointer creation
domcharrier Nov 12, 2021
22a863e
Simplify a few examples.
domcharrier Nov 12, 2021
df5b181
Central Makefile: Extract and use make_directories target
domcharrier Nov 12, 2021
fa61ed4
BUGFIX: Create empty cudafor-fort2hip.hip.cpp as cudafor apps expect it
domcharrier Nov 12, 2021
bc54315
Delete todos.md
domcharrier Nov 12, 2021
62ea370
FEATURE: Add size/lbound/ubound to C++ gpufort array; add example
domcharrier Nov 12, 2021
46e7657
Merge branch 'develop-acc' of github.com:RocmSoftwarePlatform/gpufort…
domcharrier Nov 12, 2021
82b774a
gpufort-arrays/vector-add: Simplify; all args -> references on C++ side
domcharrier Nov 12, 2021
1b228de
gpufort_arrays: Multiple new allocation and synchronization modes
domcharrier Nov 15, 2021
a7d8f40
gpufort_arrays/vector-add-non-interoperable-types: Add example
domcharrier Nov 15, 2021
a2a832d
gpufort_acc_runtime: Fix several issues
domcharrier Nov 15, 2021
505a920
gpufort_arrays: + ifaces for host/dev ptr wrapping
domcharrier Nov 16, 2021
52c7b9d
REFACTOR: Use singular for gpufort header & module names
domcharrier Nov 17, 2021
e21f7fe
vector-add-non-interop*: Showcase nested struct init and access.
domcharrier Nov 17, 2021
7e67cba
Add some developer comments
domcharrier Nov 17, 2021
42c692b
Readd gpufort_array/vector-add example
domcharrier Nov 17, 2021
3822779
gpufort_array.h: Add __host__ print host/device data routine
domcharrier Nov 17, 2021
1005738
exa*/gpufort*/non-interop*-types: Change 1 original member to pointer
domcharrier Nov 18, 2021
fb9e5e4
test/gpufort_array/*: Change file names as expected by Makefile
domcharrier Nov 18, 2021
42077ae
studies/gf*/interop*: Add c_funptr callback example
domcharrier Nov 18, 2021
dc31f29
Add previously missing file
domcharrier Nov 18, 2021
513ef89
gpufort_array: Introduce explicit async routines
domcharrier Nov 18, 2021
a10983b
exam*/gpufort*/vector-add-interop*: Add example showcasing init of in…
domcharrier Nov 18, 2021
8ca576a
test/linemapper: Add multiline directive & singline if tests.
domcharrier Nov 25, 2021
0675bbf
Add previously missing test files.
domcharrier Nov 25, 2021
7d218fb
Merge branch 'develop-acc' of github.com:RocmSoftwarePlatform/gpufort…
domcharrier Nov 25, 2021
7d2c2ee
WiP: Update test collection (test3-5 fail)
domcharrier Nov 29, 2021
3a0cad8
Merge branch 'develop-acc' of github.com:rocmsoftwareplatform/gpufort…
domcharrier Nov 29, 2021
bbded71
Add slides on GPUFORT arrays
domcharrier Dec 1, 2021
ef79dce
BUGFIX:translator: logical expr and => expr in decl RHS
domcharrier Dec 2, 2021
ab67887
WiP: Try to support comments in multi-line statements
domcharrier Dec 2, 2021
4ed0827
WiP
domcharrier Dec 3, 2021
4ea4fc6
Finalise inline comment reloc
domcharrier Dec 6, 2021
f79e47d
Add index entry for CUDA builtin variables
domcharrier Dec 6, 2021
b9186fc
Merge pull request #37 from ROCmSoftwarePlatform/bugfix/comments-in-m…
domcharrier Dec 6, 2021
d319b1c
linemapper: Put inline comments behind statements
domcharrier Dec 6, 2021
ad5d85b
BUGFIX/parsingutils: Check string length before checking char
domcharrier Dec 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.PHONY: clean_all gpufort_headers gpufort_sources lib/$(LIBGPUFORT) lib/$(LIBGPUFORT_ACC)

SUFFIX = $(if $(HIP_PLATFORM),$(HIP_PLATFORM),amd)
LIBGPUFORT = libgpufort_$(SUFFIX).a
LIBGPUFORT_ACC = libgpufort_acc_$(SUFFIX).a

GPUFORT_DIR = $(shell gpufort --path)
GPUFORT_ACC_DIR = $(GPUFORT_DIR)/runtime/gpufort_acc_runtime

all: | gpufort_headers lib/$(LIBGPUFORT) lib/$(LIBGPUFORT_ACC) make_directories

gpufort_headers:
make -C $(GPUFORT_DIR)/include all

gpufort_sources:
make -C $(GPUFORT_DIR)/src gpufort_sources

lib/$(LIBGPUFORT): | gpufort_headers gpufort_sources make_directories
make -C $(GPUFORT_DIR)/src $(LIBGPUFORT)
mv $(GPUFORT_DIR)/src/$(LIBGPUFORT) $(GPUFORT_DIR)/lib
mv $(GPUFORT_DIR)/src/*.mod $(GPUFORT_DIR)/include/$(SUFFIX)/
make -C $(GPUFORT_DIR)/src clean

lib/$(LIBGPUFORT_ACC): make_directories
make -C $(GPUFORT_ACC_DIR)/ lib/$(LIBGPUFORT_ACC)
mv $(GPUFORT_ACC_DIR)/lib/$(LIBGPUFORT_ACC)\
$(GPUFORT_DIR)/lib/
mv $(GPUFORT_ACC_DIR)/include/*.mod\
$(GPUFORT_DIR)/include/$(SUFFIX)/
#-mv $(GPUFORT_ACC_DIR)/include/*.h\
# $(GPUFORT_DIR)/include/$(SUFFIX)
make -C $(GPUFORT_ACC_DIR)/ clean

make_directories:
mkdir -p $(GPUFORT_DIR)/lib
mkdir -p $(GPUFORT_DIR)/include/$(SUFFIX)

clean_all:
make -C $(GPUFORT_DIR)/include clean_all
make -C $(GPUFORT_DIR)/src clean_all
rm -f lib/$(LIBGPUFORT) lib/$(LIBGPUFORT_ACC)
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ by GPUFORT will in most cases require manual reviewing and fixing.

Please take a look at the (slightly outdated) [user guide](https://rocmsoftwareplatform.github.io/gpufort/).

### Quick start for generating and compiling HIP code form Fortran

Before you can run HIP code generated by GPUFORT, you need to
build the GPUFORT static libraries and/or
offloading runtime for AMD and/or NVIDIA devices.
Assuming HIPFORT is installed, you can compile them via:

```bash
HIP_PLATFORM=amd FC=hipfc make all # use HIP_PLATFORM=nvidia for NVIDIA devices
```

If the compilation is successful, take a look at the
CUDA Fortran and OpenACC examples in the `examples/` subdirectory,
which all come with a Makefile for generating code and building
the examples.

## Implementation details

[This presentation](https://github.com/ROCmSoftwarePlatform/gpufort/blob/main/gpufort_slides.pdf)
Expand Down
8 changes: 8 additions & 0 deletions examples/gpufort_array/vector-add-hipmalloc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CFLAGS = -g -ggdb

vector-add:
hipcc $(shell gpufort --cpp_config) $(CFLAGS) -c main-kernels.hip.cpp -o main-kernels.hip.o
hipfc $(shell gpufort --gfortran_config) main-kernels.hip.o vector-add.f90 -o vector-add $(shell gpufort --ldflags)

clean:
rm -f *.mod *.o vector-add
45 changes: 45 additions & 0 deletions examples/gpufort_array/vector-add-hipmalloc/main-kernels.hip.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// This file was generated by gpufort
#ifndef __KERNELS_HIP_CPP__
#define __KERNELS_HIP_CPP__
#include "hip/hip_runtime.h"
#include "hip/hip_complex.h"
#include "gpufort.h"
#include "gpufort_array.h"


// BEGIN main_26_e28c45
/*
HIP C++ implementation of the function/loop body of:

!$cuf kernel do(1) <<<grid, tBlock>>>
do i=1,size(y_d,1)
y_d(i) = y_d(i) + a*x_d(i)
end do

*/

__global__ void vecadd_kernel(
gpufort::array1<float> y_d,
const float a,
const gpufort::array1<float> x_d
) {
int i = 1 + (1)*(threadIdx.x + blockIdx.x * blockDim.x);
if (loop_cond(i,y_d.size(1),1)) {
y_d(i)= y_d(i) + a*x_d(i);
}
}

extern "C" void launch_vecadd_kernel_(
const dim3& grid,
const dim3& block,
const int& sharedmem,
hipStream_t& stream,
gpufort::array1<float>& y_d,
const float& a,
const gpufort::array1<float>& x_d
) {
// launch kernel
hipLaunchKernelGGL((vecadd_kernel), grid, block, sharedmem, stream, y_d, a, x_d);
}
// END vecadd_kernel
#endif // __KERNELS_HIP_CPP__
30 changes: 30 additions & 0 deletions examples/gpufort_array/vector-add-hipmalloc/vector-add.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
program main
use hipfort
use hipfort_check
use gpufort_array
implicit none
integer, parameter :: N = 40000
real :: x(N), y(N), a
real,pointer :: x_d(:), y_d(:)
type(dim3) :: grid, tBlock
type(c_ptr) :: stream = c_null_ptr
!
tBlock = dim3(256,1,1)
grid = dim3(ceiling(real(N)/tBlock%x),1,1)

x = 1.0; y = 2.0; a = 2.0

call hipCheck(hipMalloc(x_d,source=x))
call hipCheck(hipMalloc(y_d,source=y))

call launch_vecadd_kernel(grid,tBlock,0,stream,&
gpufort_array_wrap_device_ptr(y_d,lbound(y)),a,&
gpufort_array_wrap_device_ptr(x_d))
call hipCheck(hipStreamSynchronize(stream))

call hipCheck(hipMemcpy(y,y_d,hipMemcpyDeviceToHost))
call hipCheck(hipFree(x_d))
call hipCheck(hipFree(y_d))

write(*,*) 'Max error: ', maxval(abs(y-4.0))
end program main
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CFLAGS = -g -ggdb

vector-add:
hipcc $(shell gpufort --cpp_config) $(CFLAGS) -c main-kernels.hip.cpp -o main-kernels.hip.o
hipfc $(shell gpufort --gfortran_config) main-kernels.hip.o vector-add.f90 -o vector-add $(shell gpufort --ldflags)

clean:
rm -f *.mod *.o vector-add
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// This file was generated by gpufort
#ifndef __KERNELS_HIP_CPP__
#define __KERNELS_HIP_CPP__
#include "hip/hip_runtime.h"
#include "hip/hip_complex.h"
#include "gpufort.h"
#include "gpufort_array.h"

// C++ structs with same layout as Fortran interop types
struct node_t {
float val;
};

struct mesh_t {
float a;
gpufort::array1<node_t> x;
gpufort::array1<float> y;
};

/*
HIP C++ implementation of the function/loop body of:

!$cuf kernel do(1) <<<grid, tBlock>>>
do i=1,size(mesh%y,1)
mesh%y(i) = mesh%y(i) + mesh%a*mesh%x(i)%val
end do
*/

__global__ void vecadd_kernel(mesh_t mesh) {
int i = 1 + (1)*(threadIdx.x + blockIdx.x * blockDim.x);
if (loop_cond(i,mesh.y.size(1),1)) {
mesh.y(i)= mesh.y(i) + mesh.a*mesh.x(i).val;
}
}

extern "C" void launch_vecadd_kernel_auto_(
const int& sharedmem,
hipStream_t& stream,
mesh_t& mesh
) {
const int vecadd_kernel_blockX = 128;
dim3 block(vecadd_kernel_blockX);
const int vecadd_kernel_NX = (1 + ((mesh.y.size(1)) - (1)));
const int vecadd_kernel_gridX = divideAndRoundUp( vecadd_kernel_NX, vecadd_kernel_blockX );
dim3 grid(vecadd_kernel_gridX);

// launch kernel
hipLaunchKernelGGL((vecadd_kernel), grid, block, sharedmem, stream, mesh);
//mesh.y.print_device_data(std::cout,"prefix",gpufort::PrintMode::PrintCValues);
}
#endif // __KERNELS_HIP_CPP__
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
module types
use iso_c_binding
use gpufort_array

! interoperable types
type,bind(c) :: node_t
real(c_float) :: val
end type

type,bind(c) :: mesh_t
real(c_float) :: a
type(gpufort_array1) :: x ! array of type `node_t`
type(gpufort_array1) :: y ! array of type `real(c_float)`
end type
end module

program main
use types
use hipfort
use hipfort_check
implicit none
integer, parameter :: N = 40000
!
type(mesh_t) :: mesh
real(c_float),pointer :: mesh_t_y(:)
!
call init_mesh()
call gpufort_array_hostptr(mesh%y,mesh_t_y)

call launch_vecadd_kernel_auto(0,c_null_ptr,mesh)
call hipCheck(gpufort_array_copy_to_host(mesh%y))

write(*,*) 'Max error: ', maxval(abs(mesh_t_y-4.0))

call destroy_mesh()
contains
subroutine init_mesh()
use gpufort_array
use iso_c_binding
implicit none
integer i
type(node_t) :: node_t_dummy
type(node_t),pointer :: mesh_t_x(:)
real(c_float),pointer :: mesh_t_y(:)

! Init scalar
mesh%a = 2.0

! Init basic datatype array member
call hipCheck(gpufort_array_init(mesh%y,&
c_float,sizes=[N],lbounds=[1],&
alloc_mode=gpufort_array_alloc_pinned_host_alloc_device))
call gpufort_array_hostptr(mesh%y,mesh_t_y) ! Get Fortran pointer to host data (overloaded routine exists for basic datatypes.
!
mesh_t_y(:) = 2.0 ! Also sets lower bounds.
call hipCheck(gpufort_array_copy_to_device(mesh%y))

! Init struct member.
call hipCheck(gpufort_array_init(mesh%x,&
int(c_sizeof(node_t_dummy),c_int),&
sizes=[N],lbounds=[1],&
alloc_mode=gpufort_array_alloc_pinned_host_alloc_device))
!
! Get Fortran pointer to host data. No overloaded routine exists (must be type-specific).
! In this case, you must/can set lower bounds manually if they are different from 1 and
! the initial data is depending on the index.
call c_f_pointer(mesh%x%data%data_host,mesh_t_x,shape=[N])
!mesh_t_x(1:) => mesh_t_x ! Set lower bounds
mesh_t_x(:)%val = 1
call hipCheck(gpufort_array_copy_to_device(mesh%x))
end subroutine

! (will be) autogenerated by GPUFORT
subroutine destroy_mesh()
use gpufort_array
use iso_c_binding
implicit none
call hipCheck(gpufort_array_destroy(mesh%x))
call hipCheck(gpufort_array_destroy(mesh%y))
end subroutine
end program main
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CFLAGS = -g -ggdb

vector-add:
hipcc $(shell gpufort --cpp_config) $(CFLAGS) -c main-kernels.hip.cpp -o main-kernels.hip.o
hipfc $(shell gpufort --gfortran_config) main-kernels.hip.o vector-add.f90 -o vector-add $(shell gpufort --ldflags)

clean:
rm -f *.mod *.o vector-add
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This file was generated by gpufort
#ifndef __KERNELS_HIP_CPP__
#define __KERNELS_HIP_CPP__
#include "hip/hip_runtime.h"
#include "hip/hip_complex.h"
#include "gpufort.h"
#include "gpufort_array.h"

// C++ structs with same layout as Fortran interop types
struct node_t {
float val;
};

struct mesh_t {
float a;
gpufort::array1<node_t> x;
gpufort::array1<float> y;
};

/*
HIP C++ implementation of the function/loop body of:

!$cuf kernel do(1) <<<grid, tBlock>>>
do i=1,size(mesh%y,1)
mesh%y(i) = mesh%y(i) + mesh%a*mesh%x(i)%val
end do
*/

__global__ void vecadd_kernel(mesh_t mesh) {
int i = 1 + (1)*(threadIdx.x + blockIdx.x * blockDim.x);
if (loop_cond(i,mesh.y.size(1),1)) {
mesh.y(i)= mesh.y(i) + mesh.a*mesh.x(i).val;
}
}

extern "C" void launch_vecadd_kernel_auto_(
const int& sharedmem,
hipStream_t& stream,
mesh_t& mesh
) {
const int vecadd_kernel_blockX = 128;
dim3 block(vecadd_kernel_blockX);
const int vecadd_kernel_NX = (1 + ((mesh.y.size(1)) - (1)));
const int vecadd_kernel_gridX = divideAndRoundUp( vecadd_kernel_NX, vecadd_kernel_blockX );
dim3 grid(vecadd_kernel_gridX);

// launch kernel
hipLaunchKernelGGL((vecadd_kernel), grid, block, sharedmem, stream, mesh);
}
#endif // __KERNELS_HIP_CPP__
Loading