2021-10-21 19:04:49 +08:00
################################################################################
2022-01-13 14:05:24 +08:00
# Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
2021-10-21 19:04:49 +08:00
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
################################################################################
#
# Makefile project only supported on Mac OS X and Linux Platforms)
#
################################################################################
# Location of the CUDA Toolkit
CUDA_PATH ?= /usr/local/cuda
##############################
# start deprecated interface #
##############################
i f e q ( $( x 86_ 64) , 1 )
$( info WARNING - x86_64 variable has been deprecated)
$( info WARNING - please use TARGET_ARCH = x86_64 instead)
TARGET_ARCH ?= x86_64
e n d i f
i f e q ( $( ARMv 7) , 1 )
$( info WARNING - ARMv7 variable has been deprecated)
$( info WARNING - please use TARGET_ARCH = armv7l instead)
TARGET_ARCH ?= armv7l
e n d i f
i f e q ( $( aarch 64) , 1 )
$( info WARNING - aarch64 variable has been deprecated)
$( info WARNING - please use TARGET_ARCH = aarch64 instead)
TARGET_ARCH ?= aarch64
e n d i f
i f e q ( $( ppc 64le ) , 1 )
$( info WARNING - ppc64le variable has been deprecated)
$( info WARNING - please use TARGET_ARCH = ppc64le instead)
TARGET_ARCH ?= ppc64le
e n d i f
i f n e q ( $( GCC ) , )
$( info WARNING - GCC variable has been deprecated)
$( info WARNING - please use HOST_COMPILER = $( GCC) instead)
HOST_COMPILER ?= $( GCC)
e n d i f
i f n e q ( $( abi ) , )
$( error ERROR - abi variable has been removed)
e n d i f
############################
# end deprecated interface #
############################
# architecture
HOST_ARCH := $( shell uname -m)
TARGET_ARCH ?= $( HOST_ARCH)
i f n e q ( , $( filter $ ( TARGET_ARCH ) ,x 86_ 64 aarch 64 sbsa ppc 64le armv 7l ) )
ifneq ( $( TARGET_ARCH) ,$( HOST_ARCH) )
ifneq ( ,$( filter $( TARGET_ARCH) ,x86_64 aarch64 sbsa ppc64le) )
TARGET_SIZE := 64
else ifneq ( ,$( filter $( TARGET_ARCH) ,armv7l) )
TARGET_SIZE := 32
endif
else
TARGET_SIZE := $( shell getconf LONG_BIT)
endif
e l s e
$( error ERROR - unsupported value $( TARGET_ARCH) for TARGET_ARCH!)
e n d i f
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
i f e q ( $( HOST_ARCH ) , a a r c h 6 4 )
ifeq ( $( CUDA_PATH) /targets/sbsa-linux,$( shell ls -1d $( CUDA_PATH) /targets/sbsa-linux 2>/dev/null) )
HOST_ARCH := sbsa
TARGET_ARCH := sbsa
endif
e n d i f
i f n e q ( $( TARGET_ARCH ) , $( HOST_ARCH ) )
ifeq ( ,$( filter $( HOST_ARCH) -$( TARGET_ARCH) ,aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-sbsa x86_64-ppc64le) )
$( error ERROR - cross compiling from $( HOST_ARCH) to $( TARGET_ARCH) is not supported!)
endif
e n d i f
# When on native aarch64 system with userspace of 32-bit, change TARGET_ARCH to armv7l
i f e q ( $( HOST_ARCH ) - $( TARGET_ARCH ) - $( TARGET_SIZE ) , a a r c h 6 4 - a a r c h 6 4 - 3 2 )
TARGET_ARCH = armv7l
e n d i f
# operating system
HOST_OS := $( shell uname -s 2>/dev/null | tr "[:upper:]" "[:lower:]" )
TARGET_OS ?= $( HOST_OS)
i f e q ( , $( filter $ ( TARGET_OS ) ,linux darwin qnx android ) )
$( error ERROR - unsupported value $( TARGET_OS) for TARGET_OS!)
e n d i f
# host compiler
2023-06-30 03:33:40 +08:00
i f d e f H O S T _ C O M P I L E R
CUSTOM_HOST_COMPILER = 1
e n d i f
2021-10-21 19:04:49 +08:00
i f e q ( $( TARGET_OS ) , d a r w i n )
ifeq ( $( shell expr ` xcodebuild -version | grep -i xcode | awk '{print $$2}' | cut -d'.' -f1` \> = 5) ,1)
HOST_COMPILER ?= clang++
endif
e l s e i f n e q ( $( TARGET_ARCH ) , $( HOST_ARCH ) )
ifeq ( $( HOST_ARCH) -$( TARGET_ARCH) ,x86_64-armv7l)
ifeq ( $( TARGET_OS) ,linux)
HOST_COMPILER ?= arm-linux-gnueabihf-g++
else ifeq ( $( TARGET_OS) ,qnx)
ifeq ( $( QNX_HOST) ,)
$( error ERROR - QNX_HOST must be passed to the QNX host toolchain)
endif
ifeq ( $( QNX_TARGET) ,)
$( error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
endif
export QNX_HOST
export QNX_TARGET
HOST_COMPILER ?= $( QNX_HOST) /usr/bin/arm-unknown-nto-qnx6.6.0eabi-g++
else ifeq ( $( TARGET_OS) ,android)
HOST_COMPILER ?= arm-linux-androideabi-g++
endif
else ifeq ( $( TARGET_ARCH) ,aarch64)
ifeq ( $( TARGET_OS) , linux)
HOST_COMPILER ?= aarch64-linux-gnu-g++
else ifeq ( $( TARGET_OS) ,qnx)
ifeq ( $( QNX_HOST) ,)
$( error ERROR - QNX_HOST must be passed to the QNX host toolchain)
endif
ifeq ( $( QNX_TARGET) ,)
$( error ERROR - QNX_TARGET must be passed to the QNX target toolchain)
endif
export QNX_HOST
export QNX_TARGET
HOST_COMPILER ?= $( QNX_HOST) /usr/bin/q++
else ifeq ( $( TARGET_OS) , android)
HOST_COMPILER ?= aarch64-linux-android-clang++
endif
else ifeq ( $( TARGET_ARCH) ,sbsa)
HOST_COMPILER ?= aarch64-linux-gnu-g++
else ifeq ( $( TARGET_ARCH) ,ppc64le)
HOST_COMPILER ?= powerpc64le-linux-gnu-g++
endif
e n d i f
HOST_COMPILER ?= g++
NVCC := $( CUDA_PATH) /bin/nvcc -ccbin $( HOST_COMPILER)
# internal flags
NVCCFLAGS := -m${ TARGET_SIZE }
CCFLAGS :=
LDFLAGS :=
# build flags
2024-07-26 00:30:13 +08:00
# Link flag for customized HOST_COMPILER with gcc realpath
GCC_PATH := $( shell which gcc)
i f e q ( $( CUSTOM_HOST_COMPILER ) , 1 )
ifneq ( $( filter /%,$( HOST_COMPILER) ) ,)
ifneq ( $( findstring gcc,$( HOST_COMPILER) ) ,)
ifneq ( $( GCC_PATH) ,$( HOST_COMPILER) )
LDFLAGS += -lstdc++
endif
endif
endif
e n d i f
2021-10-21 19:04:49 +08:00
i f e q ( $( TARGET_OS ) , d a r w i n )
LDFLAGS += -rpath $( CUDA_PATH) /lib
CCFLAGS += -arch $( HOST_ARCH)
e l s e i f e q ( $( HOST_ARCH ) - $( TARGET_ARCH ) - $( TARGET_OS ) , x 8 6 _ 6 4 - a r m v 7 l - l i n u x )
LDFLAGS += --dynamic-linker= /lib/ld-linux-armhf.so.3
CCFLAGS += -mfloat-abi= hard
e l s e i f e q ( $( TARGET_OS ) , a n d r o i d )
LDFLAGS += -pie
CCFLAGS += -fpie -fpic -fexceptions
e n d i f
i f n e q ( $( TARGET_ARCH ) , $( HOST_ARCH ) )
ifeq ( $( TARGET_ARCH) -$( TARGET_OS) ,armv7l-linux)
ifneq ( $( TARGET_FS) ,)
GCCVERSIONLTEQ46 := $( shell expr ` $( HOST_COMPILER) -dumpversion` \< = 4.6)
ifeq ( $( GCCVERSIONLTEQ46) ,1)
CCFLAGS += --sysroot= $( TARGET_FS)
endif
LDFLAGS += --sysroot= $( TARGET_FS)
LDFLAGS += -rpath-link= $( TARGET_FS) /lib
LDFLAGS += -rpath-link= $( TARGET_FS) /usr/lib
LDFLAGS += -rpath-link= $( TARGET_FS) /usr/lib/arm-linux-gnueabihf
endif
endif
ifeq ( $( TARGET_ARCH) -$( TARGET_OS) ,aarch64-linux)
ifneq ( $( TARGET_FS) ,)
GCCVERSIONLTEQ46 := $( shell expr ` $( HOST_COMPILER) -dumpversion` \< = 4.6)
ifeq ( $( GCCVERSIONLTEQ46) ,1)
CCFLAGS += --sysroot= $( TARGET_FS)
endif
LDFLAGS += --sysroot= $( TARGET_FS)
LDFLAGS += -rpath-link= $( TARGET_FS) /lib -L$( TARGET_FS) /lib
LDFLAGS += -rpath-link= $( TARGET_FS) /lib/aarch64-linux-gnu -L$( TARGET_FS) /lib/aarch64-linux-gnu
LDFLAGS += -rpath-link= $( TARGET_FS) /usr/lib -L$( TARGET_FS) /usr/lib
LDFLAGS += -rpath-link= $( TARGET_FS) /usr/lib/aarch64-linux-gnu -L$( TARGET_FS) /usr/lib/aarch64-linux-gnu
LDFLAGS += --unresolved-symbols= ignore-in-shared-libs
CCFLAGS += -isystem= $( TARGET_FS) /usr/include -I$( TARGET_FS) /usr/include -I$( TARGET_FS) /usr/include/libdrm
CCFLAGS += -isystem= $( TARGET_FS) /usr/include/aarch64-linux-gnu -I$( TARGET_FS) /usr/include/aarch64-linux-gnu
endif
endif
ifeq ( $( TARGET_ARCH) -$( TARGET_OS) ,aarch64-qnx)
2022-01-13 14:05:24 +08:00
NVCCFLAGS += -D_QNX_SOURCE
NVCCFLAGS += --qpp-config 8.3.0,gcc_ntoaarch64le
2021-10-21 19:04:49 +08:00
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
LDFLAGS += -lsocket
LDFLAGS += -L/usr/lib/aarch64-qnx-gnu
CCFLAGS += "-Wl\,-rpath-link\,/usr/lib/aarch64-qnx-gnu"
ifdef TARGET_OVERRIDE
LDFLAGS += -lslog2
endif
ifneq ( $( TARGET_FS) ,)
LDFLAGS += -L$( TARGET_FS) /usr/lib
CCFLAGS += " -Wl\,-rpath-link\, $( TARGET_FS) /usr/lib "
LDFLAGS += -L$( TARGET_FS) /usr/libnvidia
CCFLAGS += " -Wl\,-rpath-link\, $( TARGET_FS) /usr/libnvidia "
CCFLAGS += -I$( TARGET_FS) /../include
endif
endif
e n d i f
i f d e f T A R G E T _ O V E R R I D E # cuda toolkit targets override
NVCCFLAGS += -target-dir $( TARGET_OVERRIDE)
e n d i f
# Install directory of different arch
CUDA_INSTALL_TARGET_DIR :=
i f e q ( $( TARGET_ARCH ) - $( TARGET_OS ) , a r m v 7 l - l i n u x )
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
e l s e i f e q ( $( TARGET_ARCH ) - $( TARGET_OS ) , a a r c h 6 4 - l i n u x )
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
e l s e i f e q ( $( TARGET_ARCH ) - $( TARGET_OS ) , s b s a - l i n u x )
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
e l s e i f e q ( $( TARGET_ARCH ) - $( TARGET_OS ) , a r m v 7 l - a n d r o i d )
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
e l s e i f e q ( $( TARGET_ARCH ) - $( TARGET_OS ) , a a r c h 6 4 - a n d r o i d )
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux-androideabi/
e l s e i f e q ( $( TARGET_ARCH ) - $( TARGET_OS ) , a r m v 7 l - q n x )
CUDA_INSTALL_TARGET_DIR = targets/ARMv7-linux-QNX/
e l s e i f e q ( $( TARGET_ARCH ) - $( TARGET_OS ) , a a r c h 6 4 - q n x )
CUDA_INSTALL_TARGET_DIR = targets/aarch64-qnx/
e l s e i f e q ( $( TARGET_ARCH ) , p p c 6 4 l e )
CUDA_INSTALL_TARGET_DIR = targets/ppc64le-linux/
e n d i f
# Debug build flags
i f e q ( $( dbg ) , 1 )
NVCCFLAGS += -g -G
BUILD_TYPE := debug
e l s e
BUILD_TYPE := release
e n d i f
ALL_CCFLAGS :=
ALL_CCFLAGS += $( NVCCFLAGS)
ALL_CCFLAGS += $( EXTRA_NVCCFLAGS)
ALL_CCFLAGS += $( addprefix -Xcompiler ,$( CCFLAGS) )
ALL_CCFLAGS += $( addprefix -Xcompiler ,$( EXTRA_CCFLAGS) )
SAMPLE_ENABLED := 1
# This sample is not supported on Linux x86_64
i f e q ( $( TARGET_OS ) , l i n u x )
ifeq ( $( TARGET_ARCH) ,x86_64)
$( info >>> WARNING - cuDLAStandaloneMode is not supported on Linux x86_64 - waiving sample <<< )
SAMPLE_ENABLED := 0
endif
e n d i f
# This sample is not supported on Mac OSX
i f e q ( $( TARGET_OS ) , d a r w i n )
$( info >>> WARNING - cuDLAStandaloneMode is not supported on Mac OSX - waiving sample <<< )
SAMPLE_ENABLED := 0
e n d i f
# This sample is not supported on ARMv7
i f e q ( $( TARGET_ARCH ) , a r m v 7 l )
$( info >>> WARNING - cuDLAStandaloneMode is not supported on ARMv7 - waiving sample <<< )
SAMPLE_ENABLED := 0
e n d i f
2022-01-13 14:05:24 +08:00
# This sample is not supported on sbsa
i f e q ( $( TARGET_ARCH ) , s b s a )
$( info >>> WARNING - cuDLAStandaloneMode is not supported on sbsa - waiving sample <<< )
SAMPLE_ENABLED := 0
e n d i f
2021-10-21 19:04:49 +08:00
ALL_LDFLAGS :=
ALL_LDFLAGS += $( ALL_CCFLAGS)
ALL_LDFLAGS += $( addprefix -Xlinker ,$( LDFLAGS) )
ALL_LDFLAGS += $( addprefix -Xlinker ,$( EXTRA_LDFLAGS) )
# Common includes and paths for CUDA
2022-01-13 14:05:24 +08:00
INCLUDES := -I../../../Common
2021-10-21 19:04:49 +08:00
LIBRARIES :=
################################################################################
# Makefile include to help find NVSCI Libraries
i n c l u d e . / f i n d n v s c i . m k
#Detect if installed version of GCC supports required C++11
i f e q ( $( TARGET_OS ) , l i n u x )
empty :=
space := $( empty) $( empty)
GCCVERSIONSTRING := $( shell expr ` $( HOST_COMPILER) -dumpversion` )
#Create version number without "."
GCCVERSION := $( shell expr ` echo $( GCCVERSIONSTRING) ` | cut -f1 -d.)
GCCVERSION += $( shell expr ` echo $( GCCVERSIONSTRING) ` | cut -f2 -d.)
GCCVERSION += $( shell expr ` echo $( GCCVERSIONSTRING) ` | cut -f3 -d.)
# Make sure the version number has at least 3 decimals
GCCVERSION += 00
# Remove spaces from the version number
GCCVERSION := $( subst $( space) ,$( empty) ,$( GCCVERSION) )
#$(warning $(GCCVERSION))
2022-01-13 14:05:24 +08:00
IS_MIN_VERSION := $( shell expr ` echo $( GCCVERSION) ` \> = 47000)
2023-06-30 03:33:40 +08:00
ifneq ( $( CUSTOM_HOST_COMPILER) , 1)
2021-10-21 19:04:49 +08:00
ifeq ( $( IS_MIN_VERSION) , 1)
2022-01-13 14:05:24 +08:00
$( info >>> GCC Version is greater or equal to 4.7.0 <<< )
2021-10-21 19:04:49 +08:00
else
2022-01-13 14:05:24 +08:00
$( info >>> Waiving build. Minimum GCC version required is 4.7.0<<< )
2021-10-21 19:04:49 +08:00
SAMPLE_ENABLED := 0
endif
2023-06-30 03:33:40 +08:00
else
$( warning >>> Custom HOST_COMPILER set; skipping GCC version check. This may lead to unintended behavior. Please note the minimum equivalent GCC version is 4.7.0 <<< )
endif
2021-10-21 19:04:49 +08:00
e n d i f
# Gencode arguments
2022-01-13 14:05:24 +08:00
i f e q ( $( TARGET_ARCH ) , $( filter $ ( TARGET_ARCH ) ,armv 7l aarch 64 sbsa ) )
2022-10-15 08:43:37 +08:00
SMS ?= 53 61 70 72 75 80 86 87 90
2021-10-21 19:04:49 +08:00
e l s e
2023-02-28 06:33:19 +08:00
SMS ?= 50 52 60 61 70 75 80 86 89 90
2021-10-21 19:04:49 +08:00
e n d i f
i f e q ( $( SMS ) , )
$( info >>> WARNING - no SM architectures have been specified - waiving sample <<<)
SAMPLE_ENABLED := 0
e n d i f
i f e q ( $( GENCODE_FLAGS ) , )
# Generate SASS code for each SM architecture listed in $(SMS)
$( foreach sm ,$ ( SMS ) ,$ ( eval GENCODE_FLAGS += -gencode arch =compute_ $ ( sm ) ,code =sm_ $ ( sm ) ) )
# Generate PTX code from the highest SM architecture in $(SMS) to guarantee forward-compatibility
HIGHEST_SM := $( lastword $( sort $( SMS) ) )
i f n e q ( $( HIGHEST_SM ) , )
GENCODE_FLAGS += -gencode arch = compute_$( HIGHEST_SM) ,code= compute_$( HIGHEST_SM)
e n d i f
e n d i f
ALL_CCFLAGS += --std= c++11 --threads 0
2024-07-26 00:30:13 +08:00
LIBRARIES += -L$( TARGET_FS) /usr/lib/aarch64-linux-gnu/nvidia -lcudla -lnvscibuf -lnvscisync
2021-10-21 19:04:49 +08:00
i f e q ( $( SAMPLE_ENABLED ) , 0 )
EXEC ?= @echo "[@]"
e n d i f
################################################################################
# Target rules
all : build
build : cuDLAStandaloneMode
check.deps :
i f e q ( $( SAMPLE_ENABLED ) , 0 )
@echo "Sample will be waived due to the above missing dependencies"
e l s e
@echo "Sample is ready - all dependencies have been met"
e n d i f
main.o : main .cpp
$( EXEC) $( NVCC) $( INCLUDES) $( ALL_CCFLAGS) $( GENCODE_FLAGS) -o $@ -c $<
cuDLAStandaloneMode : main .o
$( EXEC) $( NVCC) $( ALL_LDFLAGS) $( GENCODE_FLAGS) -o $@ $+ $( LIBRARIES)
2022-01-13 14:05:24 +08:00
$( EXEC) mkdir -p ../../../bin/$( TARGET_ARCH) /$( TARGET_OS) /$( BUILD_TYPE)
$( EXEC) cp $@ ../../../bin/$( TARGET_ARCH) /$( TARGET_OS) /$( BUILD_TYPE)
2021-10-21 19:04:49 +08:00
run : build
$( EXEC) ./cuDLAStandaloneMode
2022-01-13 14:05:24 +08:00
testrun : build
2021-10-21 19:04:49 +08:00
clean :
rm -f cuDLAStandaloneMode main.o
2022-01-13 14:05:24 +08:00
rm -rf ../../../bin/$( TARGET_ARCH) /$( TARGET_OS) /$( BUILD_TYPE) /cuDLAStandaloneMode
2021-10-21 19:04:49 +08:00
clobber : clean