Add and update samples for cuda 11.0 support

This commit is contained in:
Mahesh Doijade
2020-05-18 22:22:06 +05:30
parent 6be514679b
commit 4f6e02970b
410 changed files with 21920 additions and 3864 deletions

View File

@@ -72,9 +72,9 @@ endif
# architecture
HOST_ARCH := $(shell uname -m)
TARGET_ARCH ?= $(HOST_ARCH)
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 ppc64le armv7l))
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le armv7l))
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 ppc64le))
ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 sbsa ppc64le))
TARGET_SIZE := 64
else ifneq (,$(filter $(TARGET_ARCH),armv7l))
TARGET_SIZE := 32
@@ -85,8 +85,17 @@ ifneq (,$(filter $(TARGET_ARCH),x86_64 aarch64 ppc64le armv7l))
else
$(error ERROR - unsupported value $(TARGET_ARCH) for TARGET_ARCH!)
endif
# sbsa and aarch64 systems look similar. Need to differentiate them at host level for now.
ifeq ($(HOST_ARCH),aarch64)
ifeq ($(CUDA_PATH)/targets/sbsa-linux,$(shell ls -1d $(CUDA_PATH)/targets/sbsa-linux))
HOST_ARCH := sbsa
TARGET_ARCH := sbsa
endif
endif
ifneq ($(TARGET_ARCH),$(HOST_ARCH))
ifeq (,$(filter $(HOST_ARCH)-$(TARGET_ARCH),aarch64-armv7l x86_64-armv7l x86_64-aarch64 x86_64-ppc64le))
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
endif
@@ -141,6 +150,8 @@ else ifneq ($(TARGET_ARCH),$(HOST_ARCH))
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
@@ -185,19 +196,27 @@ ifneq ($(TARGET_ARCH),$(HOST_ARCH))
CCFLAGS += --sysroot=$(TARGET_FS)
endif
LDFLAGS += --sysroot=$(TARGET_FS)
LDFLAGS += -rpath-link=$(TARGET_FS)/lib -L $(TARGET_FS)/lib
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 += -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
CCFLAGS += -isystem=$(TARGET_FS)/usr/include/aarch64-linux-gnu
CCFLAGS += -isystem=$(TARGET_FS)/usr/include -I$(TARGET_FS)/usr/include
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)
CCFLAGS += -DWIN_INTERFACE_CUSTOM -I/usr/include/aarch64-qnx-gnu
LDFLAGS += -lsocket
LDFLAGS += -rpath=/usr/lib/aarch64-qnx-gnu -L/usr/lib/aarch64-qnx-gnu
ifneq ($(TARGET_FS),)
LDFLAGS += -rpath=$(TARGET_FS)/usr/lib -L $(TARGET_FS)/usr/lib
LDFLAGS += -rpath=$(TARGET_FS)/usr/libnvidia -L $(TARGET_FS)/usr/libnvidia
endif
ifdef TARGET_OVERRIDE # cuda toolkit targets override
NVCCFLAGS += -target-dir $(TARGET_OVERRIDE)
endif
endif
endif
ifeq ($(TARGET_OS),qnx)
CCFLAGS += -DWIN_INTERFACE_CUSTOM
LDFLAGS += -lsocket
endif
# Install directory of different arch
@@ -206,6 +225,8 @@ ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-linux)
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-gnueabihf/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-linux)
CUDA_INSTALL_TARGET_DIR = targets/aarch64-linux/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),sbsa-linux)
CUDA_INSTALL_TARGET_DIR = targets/sbsa-linux/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),armv7l-android)
CUDA_INSTALL_TARGET_DIR = targets/armv7-linux-androideabi/
else ifeq ($(TARGET_ARCH)-$(TARGET_OS),aarch64-android)
@@ -246,12 +267,6 @@ ifeq ($(TARGET_ARCH),armv7l)
SAMPLE_ENABLED := 0
endif
# This sample is not supported on QNX
ifeq ($(TARGET_OS),qnx)
$(info >>> WARNING - nvJPEG_encoder is not supported on QNX - waiving sample <<<)
SAMPLE_ENABLED := 0
endif
ALL_LDFLAGS :=
ALL_LDFLAGS += $(ALL_CCFLAGS)
ALL_LDFLAGS += $(addprefix -Xlinker ,$(LDFLAGS))

View File

@@ -31,16 +31,6 @@
<scope>1:CUDA Basic Topics</scope>
<scope>4:JPEG Encoding</scope>
</scopes>
<sm-arch>sm30</sm-arch>
<sm-arch>sm35</sm-arch>
<sm-arch>sm37</sm-arch>
<sm-arch>sm50</sm-arch>
<sm-arch>sm52</sm-arch>
<sm-arch>sm60</sm-arch>
<sm-arch>sm61</sm-arch>
<sm-arch>sm70</sm-arch>
<sm-arch>sm72</sm-arch>
<sm-arch>sm75</sm-arch>
<supported_envs>
<env>
<arch>x86_64</arch>

View File

@@ -10,8 +10,6 @@ Image Encoding, NVJPEG Library
## Supported SM Architectures
[SM 3.0 ](https://developer.nvidia.com/cuda-gpus) [SM 3.5 ](https://developer.nvidia.com/cuda-gpus) [SM 3.7 ](https://developer.nvidia.com/cuda-gpus) [SM 5.0 ](https://developer.nvidia.com/cuda-gpus) [SM 5.2 ](https://developer.nvidia.com/cuda-gpus) [SM 6.0 ](https://developer.nvidia.com/cuda-gpus) [SM 6.1 ](https://developer.nvidia.com/cuda-gpus) [SM 7.0 ](https://developer.nvidia.com/cuda-gpus) [SM 7.2 ](https://developer.nvidia.com/cuda-gpus) [SM 7.5 ](https://developer.nvidia.com/cuda-gpus)
## Supported OSes
Linux, Windows
@@ -27,7 +25,7 @@ x86_64, ppc64le, aarch64
## Prerequisites
Download and install the [CUDA Toolkit 10.2](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Download and install the [CUDA Toolkit 11.0](https://developer.nvidia.com/cuda-downloads) for your corresponding platform.
Make sure the dependencies mentioned in [Dependencies]() section above are installed.
## Build and Run

View File

@@ -35,8 +35,6 @@
int dev_malloc(void **p, size_t s) { return (int)cudaMalloc(p, s); }
int dev_free(void *p) { return (int)cudaFree(p); }
StopWatchInterface *timer = NULL;
bool is_interleaved(nvjpegOutputFormat_t format)
{
if (format == NVJPEG_OUTPUT_RGBI || format == NVJPEG_OUTPUT_BGRI)
@@ -51,6 +49,7 @@ struct encode_params_t {
std::string format;
std::string subsampling;
int quality;
int huf;
int dev;
};
@@ -62,6 +61,11 @@ nvjpegEncoderState_t encoder_state;
int decodeEncodeOneImage(std::string sImagePath, std::string sOutputPath, double &time, nvjpegOutputFormat_t output_format, nvjpegInputFormat_t input_format)
{
time = 0.;
cudaEvent_t startEvent = NULL, stopEvent = NULL;
float loopTime = 0;
checkCudaErrors(cudaEventCreate(&startEvent, cudaEventBlockingSync));
checkCudaErrors(cudaEventCreate(&stopEvent, cudaEventBlockingSync));
// Get the file name, without extension.
// This will be used to rename the output file.
size_t position = sImagePath.rfind("/");
@@ -87,7 +91,7 @@ int decodeEncodeOneImage(std::string sImagePath, std::string sOutputPath, double
// Image buffers.
unsigned char * pBuffer = NULL;
double decode_time = 0.;
double encoder_time = 0.;
std::vector<char> vBuffer(nSize);
@@ -169,9 +173,7 @@ int decodeEncodeOneImage(std::string sImagePath, std::string sOutputPath, double
int nReturnCode = 0;
cudaDeviceSynchronize();
// Create the CUTIL timer
sdkCreateTimer(&timer);
sdkStartTimer(&timer);
nReturnCode = nvjpegDecode(nvjpeg_handle, jpeg_state, dpImage, nSize, output_format, &imgdesc, NULL);
// alternatively decode by stages
@@ -179,14 +181,14 @@ int decodeEncodeOneImage(std::string sImagePath, std::string sOutputPath, double
nReturnCode = nvjpegDecodeMixed(nvjpeg_handle, NULL);
nReturnCode = nvjpegDecodeGPU(nvjpeg_handle, NULL);*/
cudaDeviceSynchronize();
sdkStopTimer(&timer);
decode_time =sdkGetTimerValue(&timer);
if(nReturnCode != 0)
{
std::cerr << "Error in nvjpegDecode." << std::endl;
return 1;
}
checkCudaErrors(cudaEventRecord(startEvent, NULL));
/////////////////////// encode ////////////////////
if (NVJPEG_OUTPUT_YUV == output_format)
{
@@ -226,6 +228,12 @@ int decodeEncodeOneImage(std::string sImagePath, std::string sOutputPath, double
obuffer.data(),
&length,
NULL));
checkCudaErrors(cudaEventRecord(stopEvent, NULL));
checkCudaErrors(cudaEventSynchronize(stopEvent));
checkCudaErrors(cudaEventElapsedTime(&loopTime, startEvent, stopEvent));
encoder_time = static_cast<double>(loopTime);
std::string output_filename = sOutputPath + "/" + sFileName + ".jpg";
char directory[120];
char mkdir_cmd[256];
@@ -250,7 +258,7 @@ int decodeEncodeOneImage(std::string sImagePath, std::string sOutputPath, double
}
}
time = decode_time;
time = encoder_time;
return 0;
}
@@ -352,14 +360,14 @@ int processArgs(encode_params_t param)
return error_code;
}
double total_time = 0., decode_time = 0.;
double total_time = 0., encoder_time = 0.;
int total_images = 0;
for (unsigned int i = 0; i < inputFiles.size(); i++)
{
std::string &sFileName = inputFiles[i];
std::cout << "Processing file: " << sFileName << std::endl;
int image_error_code = decodeEncodeOneImage(sFileName, sOutputPath, decode_time, oformat, iformat);
int image_error_code = decodeEncodeOneImage(sFileName, sOutputPath, encoder_time, oformat, iformat);
if (image_error_code)
{
std::cerr << "Error processing file: " << sFileName << std::endl;
@@ -368,11 +376,11 @@ int processArgs(encode_params_t param)
else
{
total_images++;
total_time += decode_time;
total_time += encoder_time;
}
}
std::cout << "Total images processed: " << total_images << std::endl;
std::cout << "Total time spent on decoding: " << total_time << std::endl;
std::cout << "Total time spent on encoding: " << total_time << std::endl;
std::cout << "Avg time/image: " << total_time/total_images << std::endl;
return 0;
@@ -411,7 +419,7 @@ int main(int argc, const char *argv[])
(pidx = findParamIndex(argv, argc, "--help")) != -1) {
std::cout << "Usage: " << argv[0]
<< " -i images_dir [-o output_dir] [-device=device_id]"
"[-q quality][-s 420/444] [-fmt output_format]\n";
"[-q quality][-s 420/444] [-fmt output_format] [-huf 0]\n";
std::cout << "Parameters: " << std::endl;
std::cout << "\timages_dir\t:\tPath to single image or directory of images" << std::endl;
std::cout << "\toutput_dir\t:\tWrite encoded images as jpeg to this directory" << std::endl;
@@ -421,6 +429,7 @@ int main(int argc, const char *argv[])
std::cout << "\toutput_format\t:\tnvJPEG output format for encoding. One "
"of [rgb, rgbi, bgr, bgri, yuv, y, unchanged]"
<< std::endl;
std::cout << "\tHuffman Optimization\t:\tUse Huffman optimization [default 0]" << std::endl;
return EXIT_SUCCESS;
}
@@ -465,6 +474,11 @@ int main(int argc, const char *argv[])
params.format = "yuv";
}
params.huf = 0;
if ((pidx = findParamIndex(argv, argc, "-huf")) != -1) {
params.huf = std::atoi(argv[pidx + 1]);
}
cudaDeviceProp props;
checkCudaErrors(cudaGetDeviceProperties(&props, params.dev));
@@ -481,7 +495,7 @@ int main(int argc, const char *argv[])
// sample input parameters
checkCudaErrors(nvjpegEncoderParamsSetQuality(encode_params, params.quality, NULL));
checkCudaErrors(nvjpegEncoderParamsSetOptimizedHuffman(encode_params, 1, NULL));
checkCudaErrors(nvjpegEncoderParamsSetOptimizedHuffman(encode_params, params.huf, NULL));
pidx = processArgs(params);