Skip to content

Commit 237234a

Browse files
authored
[SYCLomatic] Fix the build issue that dnnl_utils.hpp is not included before sycl.hpp #854
Solution: include dnnl_utils.hpp in main source file if it has used DNN syntactics. Signed-off-by: Hao Wang <[email protected]>
1 parent ad4bf40 commit 237234a

File tree

4 files changed

+38
-3
lines changed

4 files changed

+38
-3
lines changed

clang/lib/DPCT/AnalysisInfo.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,12 @@ std::optional<HeaderType> DpctFileInfo::findHeaderType(StringRef Header) {
979979
}
980980

981981
void DpctFileInfo::insertHeader(HeaderType Type, unsigned Offset) {
982+
if (Type == HT_DPL_Algorithm || Type == HT_DPL_Execution ||
983+
Type == HT_DPCT_DNNL_Utils) {
984+
if (this != DpctGlobalInfo::getInstance().getMainFile().get())
985+
DpctGlobalInfo::getInstance().getMainFile()->insertHeader(
986+
Type, FirstIncludeOffset);
987+
}
982988
if (HeaderInsertedBitMap[Type])
983989
return;
984990
HeaderInsertedBitMap[Type] = true;
@@ -996,9 +1002,6 @@ void DpctFileInfo::insertHeader(HeaderType Type, unsigned Offset) {
9961002
case HT_DPL_Algorithm:
9971003
case HT_DPL_Execution:
9981004
case HT_DPCT_DNNL_Utils:
999-
if (this != DpctGlobalInfo::getInstance().getMainFile().get())
1000-
DpctGlobalInfo::getInstance().getMainFile()->insertHeader(
1001-
Type, FirstIncludeOffset);
10021005
concatHeader(OS, getHeaderSpelling(Type));
10031006
return insertHeader(OS.str(), FirstIncludeOffset,
10041007
InsertPosition::IP_AlwaysLeft);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: echo
2+
// CHECK: #include <dpct/dnnl_utils.hpp>
3+
// CHECK: #include <sycl/sycl.hpp>
4+
// CHECK: #include <dpct/dpct.hpp>
5+
#include "dnn.h"
6+
7+
int test(cudnnHandle_t handle){
8+
9+
cudnnCreate(&handle);
10+
return 0;
11+
12+
}

clang/test/dpct/header_order/dnn.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include <cudnn.h>
2+
3+
int test(cudnnHandle_t handle);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: dpct -in-root %S -out-root %T/header_order %S/test.cu %S/dnn.cu --cuda-include-path="%cuda-path/include" -- -std=c++14 -x cuda --cuda-host-only
2+
// RUN: FileCheck --input-file %T/header_order/test.dp.cpp --match-full-lines %s
3+
// RUN: FileCheck --input-file %T/header_order/dnn.dp.cpp --match-full-lines %s
4+
// CHECK: #include <dpct/dnnl_utils.hpp>
5+
// CHECK: #include <sycl/sycl.hpp>
6+
// CHECK: #include <dpct/dpct.hpp>
7+
#include <stdlib.h>
8+
#include <iostream>
9+
#include <algorithm>
10+
11+
#include "dnn.h"
12+
13+
int main(){
14+
cudnnHandle_t handle;
15+
test(handle);
16+
return 0;
17+
}

0 commit comments

Comments
 (0)