iT邦幫忙

1

建置tensorrt_demos遭遇的makefile問題(part2)

css 2022-12-09 17:37:55935 瀏覽
  • 分享至 

  • xImage

下面的makefile內容需要CUDA NVCC進行編譯

CC=g++
LD=ld
CXXFLAGS=-Wall -std=c++11 -g -O

NVCC=nvcc
#電腦:X86(64)架構
#顯示卡:GTX1650(運算能力參數為7.5:查詢官方網站) 

compute=75 #7.5==>所以參數設為75

#X86 64架構==>-M64 -gencode arch=compute_75,code=sm_75
NVCCFLAGS=-m64 -gencode arch=compute_$(compute),code=sm_$(compute) \
#              -gencode arch=compute_$(compute),code=compute_$(compute)

# TensorRT安裝位置
TENSORRT_INCS=-I"/C:/TensorRT-7.1.3.4/include"
TENSORRT_LIBS=-L"/C:/TensorRT-7.1.3.4/lib"

# INCS and LIBS
INCS=-I/C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v11.8/include $(TENSORRT_INCS) -I"/C:/MinGW/include" -I"plugin"
LIBS=-L/C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v11.8/lib/x64 $(TENSORRT_LIBS) -L"/C:/MinGW/lib" -Wl,--start-group -lnvinfer -lnvparsers -lnvinfer_plugin -lcudnn -lcublas -lnvToolsExt -lcudart -lrt -ldl -lpthread -Wl,--end-group

.PHONY: all clean

all: libyolo_layer.so

clean:
	rm -f *.so *.o

libyolo_layer.so: yolo_layer.o
	$(CC) -shared -o $@ $< $(LIBS)

yolo_layer.o: yolo_layer.cu yolo_layer.h
	$(NVCC) -ccbin $(CC) $(INCS) $(NVCCFLAGS) -Xcompiler -fPIC -c -o $@ $<

執行make結果....

PS D:\project\C++project\tensorrt_demos\plugins> make
nvcc -ccbin g++ -I/C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v11.8/include -I"/C:/TensorRT-7.1.3.4/include" -I"/C:/MinGW/include" -I"plugin" -m64 -gencode arch=compute_75,code=sm_75  -Xcompiler -fPIC -c -o yolo_layer.o yolo_layer.cu
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
Makefile:40: recipe for target 'yolo_layer.o' failed
make: *** [yolo_layer.o] Error 1

猜測 NVCC指令中參數出問題,還望各位高手大大幫我解惑??


2023/02/05補充說明:

最近終於把整個小專案達到一個階段,以下是說明及後來解決方案:

1.小專案是想把YOLOV4(DARKNET:訓練過的權重以及定義檔) 透過TENSORRT優化成一個引擎檔(engine file)加快推論的速度,之後將TENSORRT相關的C++程式封裝成一個DLL供C#呼叫。

2.當初是採用網路上大神們的開放程式碼方案,會有這樣的訊息原來僅僅代表原始碼中有"語法錯誤"造成CUDA的NCC編譯不過,畢竟那些程式碼有些時間,TENSORRT API對接的參數有些改變,(自己學藝不精,開始只會一味照抄)。

3.花了一段時間學習,才發現由於這些程式碼中一部分給CUDA的NCC編譯,一部分是給C++編譯器編譯,在IDE中有時它不會顯示NCC編譯不過的錯誤部分。

4.之所以會發現,是因為把這些程式碼放置進visual studio時類似的錯誤訊息再次困擾這我,之後我改成一小塊一小塊的COMPILE才發現原因。

5.例如:以前這個method是這樣

void MishPlugin::serialize(void* buffer) const

後來改成要多加noexcept(head檔修正):

void MishPlugin::serialize(void* buffer) const noexcept

因為這部分是交給NCC去編譯的,所以在visual Studio中C++編譯器是不會報錯等到交給 NCC編譯才會發現堆接參數不對死翹翹

6.所以出這樣的訊息大多不是我開始以為環境設定的問題,而是程式碼中有語法問題

nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
Makefile:40: recipe for target 'yolo_layer.o' failed
make: *** [yolo_layer.o] Error 1
以上是我針對這個問題的解決過程。感謝
/images/emoticon/emoticon13.gif
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
re.Zero
iT邦研究生 5 級 ‧ 2022-12-10 00:19:56
最佳解答

你要不要試試使用 make VERBOSE=1 看詳細的流程輸出? (雖然不一定能看出問題就是了~)

make VERBOSE=1 是 CMake 的,如果你是用其他的可能要網路搜尋一下。

如果對輸出 make 詳細流程有興趣的話,可參考 "How do I force make/GCC to show me the commands?" 的討論。

(因為你的 make 給的訊息滿少的,我經驗不足連個所以然都沒法猜,只能提出除錯的方法,抱歉~)

看更多先前的回應...收起先前的回應...
css iT邦新手 5 級 ‧ 2022-12-11 12:57:55 檢舉

恩恩 我按照您的說法,我採用這樣的指令make --debug=V

PS D:\project\C++project\tensorrt_demos\plugins> make --debug=V
GNU Make 3.82.90
Built for i686-pc-mingw32
Copyright (C) 1988-2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Reading makefiles...
Reading makefile 'Makefile'...
Updating goal targets....
Considering target file 'all'.
 File 'all' does not exist.
  Considering target file 'libyolo_layer.so'.
   File 'libyolo_layer.so' does not exist.
    Considering target file 'yolo_layer.o'.
     File 'yolo_layer.o' does not exist.
      Considering target file 'yolo_layer.cu'.
       Finished prerequisites of target file 'yolo_layer.cu'.
      No need to remake target 'yolo_layer.cu'.
      Considering target file 'yolo_layer.h'.
       Finished prerequisites of target file 'yolo_layer.h'.
      No need to remake target 'yolo_layer.h'.
     Finished prerequisites of target file 'yolo_layer.o'.
    Must remake target 'yolo_layer.o'.
nvcc -ccbin g++ -I/C:/Program\ Files/NVIDIA\ GPU\ Computing\ Toolkit/CUDA/v11.8/include -I/C:/TensorRT-8.5.1.7/include -I/C:/MinGW/include -I"plugin" -m64 -gencode arch=compute_75,code=sm_75  -Xcompiler -fPIC -c -o yolo_layer.o yolo_layer.cu
Main thread handle = 00000164
nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
Makefile:40: recipe for target 'yolo_layer.o' failed
make: *** [yolo_layer.o] Error 1

我還是毫無頭緒

re.Zero iT邦研究生 5 級 ‧ 2022-12-11 14:17:23 檢舉

我也是毫無頭緒;這裡看下來 nvcc ... 之前都沒事的樣子,就 nvcc 處理時出事?(除非 yolo_layer.* 莫名消失?)
你要不要在 makefile 內採用 NVCC=nvcc -v (或是把 -v 用於最後一行亦可) 看看 nvcc 是哪邊出事?

css iT邦新手 5 級 ‧ 2022-12-11 21:17:31 檢舉

恩 我再試試!! 感謝/images/emoticon/emoticon07.gif

css iT邦新手 5 級 ‧ 2022-12-16 14:23:46 檢舉

目前還是無法解決,整體目標是將自己訓練的YOLOV4 Model轉成TENSORRT能執行的格式,所以嘗試別的方式來攻克。還是感謝了!

re.Zero iT邦研究生 5 級 ‧ 2022-12-16 15:57:37 檢舉

了解,謝謝通知結果!不過這不用選入最佳解答啦。
(我是不在意獎勵機制,反倒在意你的測試結果)
不然有人看列表時會誤會~

css iT邦新手 5 級 ‧ 2023-02-04 22:32:25 檢舉

最近終於把整個小專案達到一個階段,以下是說明及後來解決方案:

1.當初是想把YOLOV4(DARKNET) 透過TENSORRT優化成一個ENGINE加快速度,之後封裝成一個DLL供C#呼叫。

2.採用網路上大神們的方案會這樣的訊息,原來僅僅代表原始碼有"語法錯誤"NCC編譯不過,自己學藝不精,畢竟那些程式碼有些時間,TENSORRT API對接的參數有些改變。

3.但自己花了一段時間學習,才發現由於這些程式碼中一部分給CUDA的NCC編譯,一部分是給C++編譯器編譯,在IDE中有時它不會顯示NCC編譯不過的錯誤部分。

3.之所以發現,是因為把這些程式碼放置進visual studio時類似的錯誤訊息再次困擾這我,之後我改成一小塊一小塊的COMPILE才發現原因。

4.例如:以前這個method是這樣
void MishPlugin::serialize(void* buffer) const
後來改成要多加noexcept(head檔修正):
void MishPlugin::serialize(void* buffer) const noexcept

因為這部分是交給NCC去編譯的,所以在visual Studio中C++編譯器是不會報錯等到交給 NCC編譯才會發現堆接參數不對死翹翹

5.所以出這樣的訊息大多不是我開始以為環境設定的問題,而是程式碼中有語法問題

nvcc fatal   : A single input file is required for a non-link phase when an outputfile is specified
Makefile:40: recipe for target 'yolo_layer.o' failed
make: *** [yolo_layer.o] Error 1

以上是我針對這個問題的解決過程。感謝
/images/emoticon/emoticon13.gif

re.Zero iT邦研究生 5 級 ‧ 2023-02-05 02:15:46 檢舉

@css:
辛苦你了~很高興看到你完成這案例!
建議你把這解決方法更新到你的發問內(可用 markdown 水平線分開),方便後人閱覽。
感謝分享經驗!

css iT邦新手 5 級 ‧ 2023-02-05 18:14:11 檢舉

感謝您的建議!! /images/emoticon/emoticon41.gif

我要發表回答

立即登入回答