Skip to content

Commit 7c598d3

Browse files
feat: adding code for release v0.8.0 of CV-CUDA
1 parent 11d40a4 commit 7c598d3

File tree

74 files changed

+4306
-978
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+4306
-978
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 91 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ endif()
2323

2424
project(cvcuda
2525
LANGUAGES C CXX
26-
VERSION 0.7.0
26+
VERSION 0.8.0
2727
DESCRIPTION "CUDA-accelerated Computer Vision algorithms"
2828
)
2929

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# Contributing to CV-CUDA
1818

19-
**As of release v0.7.0-beta, CV-CUDA is not accepting outside contribution.**
19+
**Currently, CV-CUDA is not accepting outside contributions.**
2020

2121
Contributions to CV-CUDA fall into the following categories:
2222

@@ -28,8 +28,8 @@ Contributions to CV-CUDA fall into the following categories:
2828
1. To propose a new feature, please file a new feature request
2929
[issue](https://github.com/CVCUDA/CV-CUDA/issues/new/choose). Describe the
3030
intended feature and discuss the design and implementation with the team and
31-
community. NOTE: Currently, as of release v0.7.0-beta, CV-CUDA is not accepting
32-
outside contribution.
31+
community. NOTE: Currently, CV-CUDA is not accepting
32+
outside contributions.
3333
1. To ask a general question, please sumbit a question
3434
[issue](https://github.com/CVCUDA/CV-CUDA/issues/new/choose). If you need
3535
more context on a particular issue, please ask in a comment.

DEVELOPER_GUIDE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ CV-CUDA includes:
8080
| Reformat | Converts a planar image into non-planar and vice versa |
8181
| Remap | Maps pixels in an image with one projection to another projection in a new image. |
8282
| Resize | Changes the size and scale of an image |
83+
| ResizeCropConvertReformat | Performs fused Resize-Crop-Convert-Reformat sequence with optional channel reordering |
8384
| Rotate | Rotates a 2D array in multiples of 90 degrees |
8485
| SIFT | Identifies and describes features in images that are invariant to scale rotation and affine distortion. |
8586
| Thresholding | Chooses a global threshold value that is the same for all pixels across the image. |

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
[![License](https://img.shields.io/badge/License-Apache_2.0-yellogreen.svg)](https://opensource.org/licenses/Apache-2.0)
2020

21-
![Version](https://img.shields.io/badge/Version-v0.7.0--beta-blue)
21+
![Version](https://img.shields.io/badge/Version-v0.8.0--beta-blue)
2222

2323
![Platform](https://img.shields.io/badge/Platform-linux--64_%7C_win--64_wsl2%7C_aarch64-gray)
2424

@@ -76,10 +76,10 @@ Choose the installation method that meets your environment needs.
7676

7777
Download the appropriate .whl file for your computer architecture, Python and CUDA version from the release assets of current CV-CUDA release. Release information of all CV-CUDA releases can be found [here][CV-CUDA GitHub Releases]. Once downloaded, execute the `pip install` command to install the Python wheel. For example:
7878
```shell
79-
pip install cvcuda_<cu_ver>-0.7.0b0-cp<py_ver>-cp<py_ver>-linux_<arch>.whl
79+
pip install cvcuda_<cu_ver>-<x.x.x>-cp<py_ver>-cp<py_ver>-linux_<arch>.whl
8080
```
8181

82-
where `<cu_ver>` is the desired CUDA version, `<py_ver>` is the desired Python version and `<arch>` is the desired architecture.
82+
where `<cu_ver>` is the desired CUDA version, `<x.x.x>` is the CV-CUDA release version, `<py_ver>` is the desired Python version and `<arch>` is the desired architecture.
8383

8484
Please note that the Python wheels are standalone, they include both the C++/CUDA libraries and the Python bindings.
8585

@@ -185,8 +185,8 @@ Install the dependencies required to build the documentation:
185185

186186
On Ubuntu, install the following packages using `apt` and `pip`:
187187
```shell
188-
apt install -y doxygen graphviz python3 python3-pip
189-
python3 -m pip install sphinx==4.5.0 breathe exhale recommonmark graphviz sphinx-rtd-theme
188+
apt install -y doxygen graphviz python3 python3-pip sphinx
189+
python3 -m pip install breathe exhale recommonmark graphviz sphinx-rtd-theme
190190
```
191191

192192
Build the documentation:
@@ -249,7 +249,7 @@ pip install cvcuda_cu12-<x.x.x>-cp310-cp310-linux_x86_64.whl
249249

250250
CV-CUDA is an open source project. As part of the Open Source Community, we are
251251
committed to the cycle of learning, improving, and updating that makes this
252-
community thrive. However, as of release v0.7.0-beta, CV-CUDA is not yet ready
252+
community thrive. However, CV-CUDA is not yet ready
253253
for external contributions.
254254

255255
To understand the process for contributing the CV-CUDA, see our
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/*
2+
* SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "BenchUtils.hpp"
19+
20+
#include <cvcuda/OpResizeCropConvertReformat.hpp>
21+
#include <nvcv/cuda/TypeTraits.hpp>
22+
23+
#include <nvbench/nvbench.cuh>
24+
25+
template<typename T>
26+
inline void ResizeCropConvertReformat(nvbench::state &state, nvbench::type_list<T>)
27+
try
28+
{
29+
long3 srcShape = benchutils::GetShape<3>(state.get_string("shape"));
30+
long varShape = state.get_int64("varShape");
31+
32+
NVCVInterpolationType interpType = benchutils::GetInterpolationType(state.get_string("interpolation"));
33+
34+
int2 cropPos{1, 1};
35+
36+
NVCVSize2D resize;
37+
38+
if (state.get_string("resizeType") == "EXPAND")
39+
{
40+
resize = NVCVSize2D{(int)(srcShape.y * 2), (int)(srcShape.z * 2)};
41+
}
42+
else if (state.get_string("resizeType") == "CONTRACT")
43+
{
44+
resize = NVCVSize2D{(int)(srcShape.y / 2), (int)(srcShape.z / 2)};
45+
}
46+
else
47+
{
48+
throw std::invalid_argument("Invalid resizeType = " + state.get_string("resizeType"));
49+
}
50+
51+
NVCVChannelManip manip;
52+
53+
if (state.get_string("manip") == "NO_OP")
54+
{
55+
manip = NVCV_CHANNEL_NO_OP;
56+
}
57+
else if (state.get_string("manip") == "REVERSE")
58+
{
59+
manip = NVCV_CHANNEL_REVERSE;
60+
}
61+
else
62+
{
63+
throw std::invalid_argument("Invalid channel manipulation = " + state.get_string("manip"));
64+
}
65+
66+
using BT = nvcv::cuda::BaseType<T>;
67+
long nc = nvcv::cuda::NumElements<T>;
68+
69+
long3 dstShape{srcShape.x, resize.h - cropPos.y, resize.w - cropPos.x};
70+
71+
if (dstShape.y <= 0 || dstShape.z <= 0)
72+
{
73+
throw std::invalid_argument("Invalid shape and resizeType");
74+
}
75+
76+
state.add_global_memory_reads(srcShape.x * srcShape.y * srcShape.z * sizeof(T));
77+
state.add_global_memory_writes(dstShape.x * dstShape.y * dstShape.z * sizeof(T));
78+
79+
cvcuda::ResizeCropConvertReformat op;
80+
81+
// clang-format off
82+
83+
if (varShape < 0) // negative var shape means use Tensor
84+
{
85+
nvcv::Tensor src({{srcShape.x, srcShape.y, srcShape.z, nc}, "NHWC"}, benchutils::GetDataType<BT>());
86+
nvcv::Tensor dst({{dstShape.x, dstShape.y, dstShape.z, nc}, "NHWC"}, benchutils::GetDataType<BT>());
87+
88+
benchutils::FillTensor<T>(src, benchutils::RandomValues<T>());
89+
90+
state.exec(nvbench::exec_tag::sync, [&op, &src, &dst, &resize, &interpType, &cropPos, &manip](nvbench::launch &launch)
91+
{
92+
op(launch.get_stream(), src, dst, resize, interpType, cropPos, manip);
93+
});
94+
}
95+
else // zero and positive var shape means use ImageBatchVarShape
96+
{
97+
nvcv::ImageBatchVarShape src(srcShape.x);
98+
nvcv::Tensor dst({{dstShape.x, dstShape.y, dstShape.z, nc}, "NHWC"}, benchutils::GetDataType<BT>());
99+
100+
benchutils::FillImageBatch<T>(src, long2{srcShape.z, srcShape.y}, long2{varShape, varShape},
101+
benchutils::RandomValues<T>());
102+
103+
state.exec(nvbench::exec_tag::sync, [&op, &src, &dst, &resize, &interpType, &cropPos, &manip](nvbench::launch &launch)
104+
{
105+
op(launch.get_stream(), src, dst, resize, interpType, cropPos, manip);
106+
});
107+
}
108+
}
109+
catch (const std::exception &err)
110+
{
111+
state.skip(err.what());
112+
}
113+
114+
// clang-format on
115+
116+
using ResizeCropConvertReformatTypes = nvbench::type_list<uchar3>;
117+
118+
NVBENCH_BENCH_TYPES(ResizeCropConvertReformat, NVBENCH_TYPE_AXES(ResizeCropConvertReformatTypes))
119+
.set_type_axes_names({"InOutDataType"})
120+
.add_string_axis("shape", {"1x1080x1920"})
121+
.add_int64_axis("varShape", {-1, 0})
122+
.add_string_axis("resizeType", {"EXPAND"})
123+
.add_string_axis("manip", {"NO_OP"})
124+
.add_string_axis("interpolation", {"LINEAR"});

bench/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ set(bench_sources
5151
BenchConvertTo.cpp
5252
BenchCopyMakeBorder.cpp
5353
BenchCropFlipNormalizeReformat.cpp
54+
BenchResizeCropConvertReformat.cpp
5455
BenchCustomCrop.cpp
5556
BenchErase.cpp
5657
BenchGammaContrast.cpp

bench/python/all_ops/op_as_image.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import nvcv
17+
18+
# NOTE: One must import PyCuda driver first, before CVCUDA or VPF otherwise
19+
# things may throw unexpected errors.
20+
import pycuda.driver as cuda # noqa: F401
21+
from bench_utils import AbstractOpBase
22+
23+
24+
class OpAsImageFromNVCVImage(AbstractOpBase):
25+
def setup(self, input):
26+
# dummy run that does not use cache
27+
img = nvcv.Image((128, 128), nvcv.Format.RGBA8)
28+
29+
self.imglist = []
30+
for _ in range(10):
31+
img = nvcv.Image((128, 128), nvcv.Format.RGBA8)
32+
self.imglist.append(img.cuda())
33+
self.cycle = 0
34+
35+
def run(self, input):
36+
nvcv.as_image(self.imglist[self.cycle % len(self.imglist)])
37+
self.cycle += 1
38+
return

bench/python/all_ops/op_as_images.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
import nvcv
17+
18+
# NOTE: One must import PyCuda driver first, before CVCUDA or VPF otherwise
19+
# things may throw unexpected errors.
20+
import pycuda.driver as cuda # noqa: F401
21+
from bench_utils import AbstractOpBase
22+
23+
24+
class OpAsImagesFromNVCVImage(AbstractOpBase):
25+
def setup(self, input):
26+
# dummy run that does not use cache
27+
nvcv.ImageBatchVarShape(100)
28+
img = nvcv.Image((128, 128), nvcv.Format.RGBA8)
29+
30+
self.imglists = []
31+
for _ in range(10):
32+
imglist = []
33+
for _ in range(100):
34+
img = nvcv.Image((128, 128), nvcv.Format.RGBA8)
35+
imglist.append(img.cuda())
36+
self.imglists.append(imglist)
37+
self.cycle = 0
38+
39+
def run(self, input):
40+
nvcv.as_images(self.imglists[self.cycle % len(self.imglists)])
41+
self.cycle += 1
42+
return

0 commit comments

Comments
 (0)