Skip to content

Commit 828c145

Browse files
committed
feat: enable CPU compilation of CUDA projects.
1 parent 2b6f876 commit 828c145

3 files changed

Lines changed: 42 additions & 2 deletions

File tree

nsy/cuda/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
nsy
22
nsy.o
3+
nsy.cpp
34
nsy.cu.hip

nsy/cuda/Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CXXFLAGS := -O3 -Wall -Wno-pedantic
55
ifeq ($(CXX), nvcc)
66
CXXFLAGS := -Xcompiler "$(CXXFLAGS)"
77
endif
8+
LDFLAGS :=
89

910
TARGET := nsy
1011

@@ -14,14 +15,25 @@ OBJECTS := $(patsubst %.cu, %.o, $(SOURCES))
1415
all: $(TARGET)
1516

1617
$(TARGET): $(OBJECTS)
17-
$(CXX) $(CXXFLAGS) -o $@ $^
18+
$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $^
19+
20+
ifneq (,$(filter $(CXX),clang clang++))
21+
CXXFLAGS += -march=native -std=c++17
22+
LDFLAGS += -ltbb
23+
24+
_SOURCES := $(SOURCES)
25+
SOURCES := $(patsubst %.cu, %.cpp, $(SOURCES))
26+
27+
$(SOURCES): $(_SOURCES)
28+
hipify-clang --hip-kernel-execution-syntax -o $@ $<
29+
endif
1830

1931
ifeq ($(CXX), hipcc)
2032
_SOURCES := $(SOURCES)
2133
SOURCES := $(patsubst %.cu, %.cu.hip, $(SOURCES))
2234

2335
$(SOURCES): $(_SOURCES)
24-
hipify-clang $<
36+
hipify-clang -o $@ $<
2537
endif
2638

2739
$(OBJECTS): $(SOURCES)
@@ -30,4 +42,5 @@ $(OBJECTS): $(SOURCES)
3042
clean:
3143
rm -f nsy
3244
rm -f nsy.o
45+
rm -f nsy.cpp
3346
rm -f nsy.cu.hip

nsy/cuda/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Build for CPU
2+
3+
Requirements: clang compiler, [HIP-CPU](https://github.com/ROCm/HIP-CPU)
4+
5+
```
6+
export CXX=clang++
7+
make
8+
```
9+
10+
# Build for NVIDIA GPUs
11+
12+
Requirements: NVIDIA Cuda compiler
13+
14+
```
15+
export CXX=nvcc
16+
make
17+
```
18+
19+
# Build for AMDGPUs
20+
21+
Requirements: HIP C++ compiler, AMD clang compiler
22+
23+
```
24+
export CXX=hipcc
25+
make
26+
```

0 commit comments

Comments
 (0)