Skip to content

Commit a2eb368

Browse files
committed
2 parents ee48ecf + df30c18 commit a2eb368

8 files changed

Lines changed: 643 additions & 12 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ Thumbs.db
5959

6060
# Generated documentation
6161
/docs/
62+
63+
# CodeQL artifacts
64+
_codeql_detected_source_root

INSTALL

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ sudo make install
4141
- **NVIDIA cuBLAS library** (included with CUDA Toolkit)
4242
- **CUDA-capable GPU**
4343

44+
### Optional Dependencies (for AMD GPU support)
45+
46+
- **AMD ROCm platform** (>= 4.0 recommended)
47+
- **hipBLAS library** (included with ROCm)
48+
- **ROCm-capable GPU**
49+
4450
## Installation on Different Systems
4551

4652
### Ubuntu/Debian
@@ -57,6 +63,12 @@ For NVIDIA GPU support:
5763
# See: https://developer.nvidia.com/cuda-downloads
5864
```
5965

66+
For AMD GPU support:
67+
```bash
68+
# Install ROCm from AMD's repository
69+
# See: https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html
70+
```
71+
6072
For building from Git:
6173
```bash
6274
sudo apt-get install autoconf automake libtool
@@ -97,6 +109,13 @@ To build only the CPU version (even if CUDA is available):
97109
./configure --disable-nvidia
98110
```
99111

112+
### Disabling AMD GPU Library
113+
114+
To build only the CPU version (even if ROCm is available):
115+
```bash
116+
./configure --disable-amd
117+
```
118+
100119
### Specifying CUDA Installation Directory
101120

102121
If CUDA is installed in a non-standard location:
@@ -109,6 +128,18 @@ Example:
109128
./configure --with-cuda=/opt/cuda-11.8
110129
```
111130

131+
### Specifying ROCm Installation Directory
132+
133+
If ROCm is installed in a non-standard location:
134+
```bash
135+
./configure --with-rocm=/path/to/rocm
136+
```
137+
138+
Example:
139+
```bash
140+
./configure --with-rocm=/opt/rocm
141+
```
142+
112143
### Specifying BLAS Library
113144

114145
To use a specific BLAS library:
@@ -140,6 +171,12 @@ To install in a custom location (default is /usr/local):
140171
You can combine multiple options:
141172
```bash
142173
./configure --prefix=$HOME/local --with-cuda=/opt/cuda --with-blas="-lopenblas"
174+
175+
# Or for AMD GPU
176+
./configure --prefix=$HOME/local --with-rocm=/opt/rocm --with-blas="-lopenblas"
177+
178+
# Or build both GPU libraries
179+
./configure --with-cuda=/opt/cuda --with-rocm=/opt/rocm
143180
```
144181

145182
## Build and Installation Steps
@@ -155,6 +192,7 @@ The configure script will:
155192
- Detect available compilers
156193
- Check for required libraries
157194
- Auto-detect CUDA/cuBLAS if available
195+
- Auto-detect ROCm/hipBLAS if available
158196
- Display a configuration summary
159197

160198
Example output:
@@ -174,6 +212,12 @@ Example output:
174212
CUDA_CFLAGS: -I/usr/local/cuda/include
175213
CUDA_LDFLAGS: -L/usr/local/cuda/lib64
176214
CUDA_LIBS: -lcudart -lcublas
215+
216+
AMD GPU: enabled
217+
ROCM_PATH: /opt/rocm
218+
ROCM_CFLAGS: -I/opt/rocm/include
219+
ROCM_LDFLAGS: -L/opt/rocm/lib
220+
ROCM_LIBS: -lamdhip64 -lhipblas
177221
========================================
178222
```
179223

@@ -187,6 +231,7 @@ make
187231
This will create:
188232
- `src/.libs/libsimple_gpu-cpu.so` - CPU-only library
189233
- `src/.libs/libsimple_gpu-nvidia.so` - NVIDIA GPU library (if CUDA was detected)
234+
- `src/.libs/libsimple_gpu-amd.so` - AMD GPU library (if ROCm was detected)
190235

191236
### 3. Test
192237

@@ -241,6 +286,13 @@ Explicitly disable NVIDIA support:
241286
./configure --disable-nvidia
242287
```
243288

289+
### Configure detects ROCm but you don't want it
290+
291+
Explicitly disable AMD support:
292+
```bash
293+
./configure --disable-amd
294+
```
295+
244296
### Libraries not found at runtime
245297

246298
After installation, you may need to update your library path:
@@ -315,7 +367,8 @@ If you encounter issues:
315367
1. Check that all prerequisites are installed
316368
2. Review the configuration summary output
317369
3. Check `config.log` for detailed error messages
318-
4. Ensure CUDA libraries are in your library path (for GPU version)
319-
5. Run tests with `make check` to verify the build
370+
4. Ensure CUDA libraries are in your library path (for NVIDIA GPU version)
371+
5. Ensure ROCm libraries are in your library path (for AMD GPU version)
372+
6. Run tests with `make check` to verify the build
320373

321374
For additional help, please file an issue on the GitHub repository.

Makefile.am

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
ACLOCAL_AMFLAGS = -I m4
22
AM_CPPFLAGS = -I$(srcdir)/include
33

4-
EXTRA_DIST = README.md LICENSE pkgconfig/simple_gpu-cpu.pc.in pkgconfig/simple_gpu-nvidia.pc.in
4+
EXTRA_DIST = README.md LICENSE pkgconfig/simple_gpu-cpu.pc.in pkgconfig/simple_gpu-nvidia.pc.in pkgconfig/simple_gpu-amd.pc.in
55

66
include_HEADERS = include/simple_gpu.h include/simple_gpu.F90
77

@@ -13,6 +13,10 @@ if BUILD_NVIDIA
1313
pkgconfig_DATA += pkgconfig/simple_gpu-nvidia.pc
1414
endif
1515

16+
if BUILD_AMD
17+
pkgconfig_DATA += pkgconfig/simple_gpu-amd.pc
18+
endif
19+
1620
# ===== Source library section (from src/Makefile.am) =====
1721
lib_LTLIBRARIES = libsimple_gpu-cpu.la
1822

@@ -33,6 +37,16 @@ libsimple_gpu_nvidia_la_LIBADD = $(CUDA_LIBS)
3337
libsimple_gpu_nvidia_la_LDFLAGS = -version-info 1:0:0 $(CUDA_LDFLAGS)
3438
endif
3539

40+
# AMD GPU version library (conditional)
41+
if BUILD_AMD
42+
lib_LTLIBRARIES += libsimple_gpu-amd.la
43+
libsimple_gpu_amd_la_SOURCES = src/gpu_amd.c include/simple_gpu.F90
44+
libsimple_gpu_amd_la_CFLAGS = -I$(top_srcdir)/include $(ROCM_CFLAGS)
45+
libsimple_gpu_amd_la_FCFLAGS =
46+
libsimple_gpu_amd_la_LIBADD = $(ROCM_LIBS)
47+
libsimple_gpu_amd_la_LDFLAGS = -version-info 1:0:0 $(ROCM_LDFLAGS)
48+
endif
49+
3650
# ===== Tests section (from tests/Makefile.am) =====
3751
# CPU tests (always built)
3852
TESTS = \
@@ -158,6 +172,77 @@ tests_test_sgeam_gpu_LDADD = libsimple_gpu-nvidia.la
158172
tests_test_sgeam_gpu_LDFLAGS = -ldl
159173
endif
160174

175+
# AMD GPU tests (only when AMD is available)
176+
if BUILD_AMD
177+
TESTS += \
178+
tests/test_ddot_amd \
179+
tests/test_sdot_amd \
180+
tests/test_dgemv_amd \
181+
tests/test_sgemv_amd \
182+
tests/test_dgemm_amd \
183+
tests/test_sgemm_amd \
184+
tests/test_dgeam_amd \
185+
tests/test_sgeam_amd
186+
187+
check_PROGRAMS += \
188+
tests/test_ddot_amd \
189+
tests/test_sdot_amd \
190+
tests/test_dgemv_amd \
191+
tests/test_sgemv_amd \
192+
tests/test_dgemm_amd \
193+
tests/test_sgemm_amd \
194+
tests/test_dgeam_amd \
195+
tests/test_sgeam_amd
196+
197+
# DDOT AMD test
198+
tests_test_ddot_amd_SOURCES = tests/test_ddot.F90
199+
tests_test_ddot_amd_FCFLAGS = -I$(top_builddir)
200+
tests_test_ddot_amd_LDADD = libsimple_gpu-amd.la
201+
tests_test_ddot_amd_LDFLAGS = -ldl
202+
203+
# SDOT AMD test
204+
tests_test_sdot_amd_SOURCES = tests/test_sdot.F90
205+
tests_test_sdot_amd_FCFLAGS = -I$(top_builddir)
206+
tests_test_sdot_amd_LDADD = libsimple_gpu-amd.la
207+
tests_test_sdot_amd_LDFLAGS = -ldl
208+
209+
# DGEMV AMD test
210+
tests_test_dgemv_amd_SOURCES = tests/test_dgemv.F90
211+
tests_test_dgemv_amd_FCFLAGS = -I$(top_builddir)
212+
tests_test_dgemv_amd_LDADD = libsimple_gpu-amd.la
213+
tests_test_dgemv_amd_LDFLAGS = -ldl
214+
215+
# SGEMV AMD test
216+
tests_test_sgemv_amd_SOURCES = tests/test_sgemv.F90
217+
tests_test_sgemv_amd_FCFLAGS = -I$(top_builddir)
218+
tests_test_sgemv_amd_LDADD = libsimple_gpu-amd.la
219+
tests_test_sgemv_amd_LDFLAGS = -ldl
220+
221+
# DGEMM AMD test
222+
tests_test_dgemm_amd_SOURCES = tests/test_dgemm.F90
223+
tests_test_dgemm_amd_FCFLAGS = -I$(top_builddir)
224+
tests_test_dgemm_amd_LDADD = libsimple_gpu-amd.la
225+
tests_test_dgemm_amd_LDFLAGS = -ldl
226+
227+
# SGEMM AMD test
228+
tests_test_sgemm_amd_SOURCES = tests/test_sgemm.F90
229+
tests_test_sgemm_amd_FCFLAGS = -I$(top_builddir)
230+
tests_test_sgemm_amd_LDADD = libsimple_gpu-amd.la
231+
tests_test_sgemm_amd_LDFLAGS = -ldl
232+
233+
# DGEAM AMD test
234+
tests_test_dgeam_amd_SOURCES = tests/test_dgeam.F90
235+
tests_test_dgeam_amd_FCFLAGS = -I$(top_builddir)
236+
tests_test_dgeam_amd_LDADD = libsimple_gpu-amd.la
237+
tests_test_dgeam_amd_LDFLAGS = -ldl
238+
239+
# SGEAM AMD test
240+
tests_test_sgeam_amd_SOURCES = tests/test_sgeam.F90
241+
tests_test_sgeam_amd_FCFLAGS = -I$(top_builddir)
242+
tests_test_sgeam_amd_LDADD = libsimple_gpu-amd.la
243+
tests_test_sgeam_amd_LDFLAGS = -ldl
244+
endif
245+
161246
# Clean up Fortran module files
162247
CLEANFILES = *.mod
163248

README.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ A simple and easy-to-use library for GPU computing in Fortran, providing transpa
1010

1111
Simple GPU is a library designed to simplify GPU computing in Fortran applications. It provides:
1212

13-
- **Dual implementation**: CPU-only version using standard BLAS, and GPU-accelerated version using NVIDIA cuBLAS
13+
- **Dual implementation**: CPU-only version using standard BLAS, and GPU-accelerated version using NVIDIA cuBLAS or AMD hipBLAS
1414
- **Transparent interface**: Same Fortran API for both CPU and GPU versions
1515
- **Memory management**: Easy GPU memory allocation and data transfer
1616
- **BLAS operations**: Common BLAS operations (GEMM, GEMV, DOT, GEAM) for both single and double precision
17-
- **Stream support**: Asynchronous operations through CUDA streams
17+
- **Stream support**: Asynchronous operations through CUDA or HIP streams
1818

1919
## Features
2020

@@ -64,6 +64,11 @@ All BLAS operations have variants that accept 64-bit integers for dimensions. Th
6464
- NVIDIA cuBLAS library
6565
- CUDA-capable GPU
6666

67+
#### For AMD GPU version (optional):
68+
- AMD ROCm platform
69+
- hipBLAS library
70+
- ROCm-capable GPU
71+
6772
### Building from Source
6873

6974
1. **Generate configure script** (if building from git):
@@ -81,16 +86,21 @@ All BLAS operations have variants that accept 64-bit integers for dimensions. Th
8186
**Configuration options**:
8287
- `--disable-nvidia`: Disable NVIDIA GPU library even if CUDA is available
8388
- `--with-cuda=DIR`: Specify CUDA installation directory (default: `/usr/local/cuda`)
89+
- `--disable-amd`: Disable AMD GPU library even if ROCm is available
90+
- `--with-rocm=DIR`: Specify ROCm installation directory (default: auto-detect)
8491
- `--with-blas=LIB`: Specify BLAS library to use
8592

8693
**Example configurations**:
8794
```bash
8895
# CPU version only
89-
./configure --disable-nvidia
96+
./configure --disable-nvidia --disable-amd
9097

9198
# Specify CUDA location
9299
./configure --with-cuda=/opt/cuda
93100

101+
# Specify ROCm location
102+
./configure --with-rocm=/opt/rocm
103+
94104
# Use specific BLAS library
95105
./configure --with-blas="-lmkl_rt"
96106
```
@@ -112,7 +122,7 @@ All BLAS operations have variants that accept 64-bit integers for dimensions. Th
112122

113123
## Library Versions
114124

115-
Simple GPU provides two shared libraries:
125+
Simple GPU provides three shared libraries:
116126

117127
1. **libsimple_gpu-cpu.so**: CPU-only version
118128
- Uses standard BLAS library
@@ -124,7 +134,12 @@ Simple GPU provides two shared libraries:
124134
- Requires CUDA-capable GPU
125135
- Provides GPU acceleration for supported operations
126136

127-
Both libraries provide the same Fortran interface, allowing seamless switching between CPU and GPU implementations.
137+
3. **libsimple_gpu-amd.so**: AMD GPU version (if ROCm is available)
138+
- Uses AMD hipBLAS library
139+
- Requires ROCm-capable GPU
140+
- Provides GPU acceleration for supported operations
141+
142+
All libraries provide the same Fortran interface, allowing seamless switching between CPU and GPU implementations.
128143

129144
## Usage
130145

@@ -324,6 +339,9 @@ gfortran -o myapp myapp.f90 -lsimple_gpu-cpu
324339

325340
# GPU version (NVIDIA)
326341
gfortran -o myapp myapp.f90 -lsimple_gpu-nvidia
342+
343+
# GPU version (AMD)
344+
gfortran -o myapp myapp.f90 -lsimple_gpu-amd
327345
```
328346

329347
## Testing
@@ -371,12 +389,17 @@ Specify BLAS library explicitly:
371389

372390
### Runtime errors with GPU version
373391

374-
1. Ensure NVIDIA drivers are properly installed
375-
2. Check that CUDA libraries are in your library path:
392+
1. Ensure NVIDIA drivers are properly installed (for NVIDIA GPUs)
393+
2. Ensure ROCm drivers are properly installed (for AMD GPUs)
394+
3. Check that CUDA libraries are in your library path:
376395
```bash
377396
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
378397
```
379-
3. Verify GPU is accessible with `nvidia-smi`
398+
4. Check that ROCm libraries are in your library path:
399+
```bash
400+
export LD_LIBRARY_PATH=/opt/rocm/lib:$LD_LIBRARY_PATH
401+
```
402+
5. Verify GPU is accessible with `nvidia-smi` (NVIDIA) or `rocm-smi` (AMD)
380403

381404
## Contributing
382405

0 commit comments

Comments
 (0)