Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SYCLomatic][--gen-build-script] Fix the bug that the TARGET path is incorrect in the generated Makefile if TARGET has an absolute path #2529

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions clang/lib/DPCT/MigrateScript/GenMakefile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ static void getCompileInfo(
continue;
}

SmallString<512> TargetNameStr(TargetName);
if (path::is_absolute(TargetNameStr)) {
llvm::sys::path::replace_path_prefix(TargetNameStr,
InRoot.getCanonicalPath(), ".");
}
TargetName = TargetNameStr.c_str();

clang::tooling::UnifiedPath OutDirectory =
dpct::appendPath(Directory, TargetName);
// Use relative path to out-root directory.
Expand Down
17 changes: 17 additions & 0 deletions clang/test/dpct/gen_build_script2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CC = nvcc
TARGET = hello
WORK_DIR = $(shell pwd)

all: $(TARGET)

$(TARGET).o:$(TARGET).cu
$(CC) -c -o $(TARGET).o $(TARGET).cu

$(TARGET): $(TARGET).o
$(CC) -o $(WORK_DIR)/$(TARGET) $(TARGET).o

clean:
rm -f $(TARGET) $(TARGET).o



16 changes: 16 additions & 0 deletions clang/test/dpct/gen_build_script2/Makefile.dpct.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// CHECK: INCLUDE_SYCL := $(ROOT_DIR)/../include
// CHECK: INCLUDE_CL := $(ROOT_DIR)/../include/sycl
// CHECK: TARGET_0_SRC_0 = ./hello.dp.cpp
// CHECK: TARGET_0_OBJ_0 = ./hello.dp.o
// CHECK: TARGET_0_FLAG_0 = ${FLAGS}
// CHECK: TARGET_0 := ./hello
// CHECK: TARGET := ${TARGET_0}
// CHECK: .PHONY:all clean
// CHECK: OBJS_0 := ${TARGET_0_OBJ_0}
// CHECK: all: $(TARGET)
// CHECK: $(TARGET_0): $(OBJS_0)
// CHECK: $(CC) -fsycl -o $@ $^ $(LIB)
// CHECK: $(TARGET_0_OBJ_0):$(TARGET_0_SRC_0)
// CHECK: $(CC) -fsycl -c ${TARGET_0_SRC_0} -o ${TARGET_0_OBJ_0} $(TARGET_0_FLAG_0)
// CHECK: clean:
// CHECK: rm -f ${OBJS_0} $(TARGET)
20 changes: 20 additions & 0 deletions clang/test/dpct/gen_build_script2/hello.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// UNSUPPORTED: system-windows
// RUN: cat %s > %T/hello.cu
// RUN: cat %S/Makefile > %T/Makefile
// RUN: cd %T/
// RUN: intercept-build /usr/bin/make -B
// RUN: dpct -in-root ./ -out-root out -p ./ -gen-build-script --cuda-include-path="%cuda-path/include"
// RUN: cat %S/Makefile.dpct.ref >%T/Makefile.dpct.check
// RUN: cat %T/out/Makefile.dpct >> %T/Makefile.dpct.check
// RUN: FileCheck --match-full-lines --input-file %T/Makefile.dpct.check %T/Makefile.dpct.check
// RUN: %if build_lit %{cd out && make -f Makefile.dpct %}

// CHECK: void hello() {}
__global__ void hello() {}

int main() {
hello<<<1, 1>>>();
cudaDeviceSynchronize();

return 0;
}