Skip to content

Commit 442a539

Browse files
spolifroni-amdalexxu-amdsamjwuAryanSalmanpour
authored
Docs - Adding documentation (#95)
* Update documentation requirements * Upd doc reqs * Update RTD yaml * cherry pick to add documentation (#94) * Prepare documentation (#57) * Updated the readme file to point to the official documentation * first commit of new documentation structure * split up and reconfigured Using rocJpeg * Updated the readme file to point to the official documentation * first commit of new documentation structure * split up and reconfigured Using rocJpeg * fixed missing space * All changes asked for in the PR except the Destroy Handles part. * separated creating and destroying handles; added a destroying handles section; added links to hipmalloc() and hipfree() * removed the installation and build sections so that it doesn't conflict/go out of sync with the official doc * putting readme back the way it was, minus documentation section * changed some wording around hipFree() * Fix a typo in README/Docs (#66) * Edited the readme and reorganized the toc (#69) * Edited the readme so that it doesn't duplicate information in the official online docs * rearranged the toc to match the new structure * moved Docker section --------- Co-authored-by: Aryan Salmanpour <[email protected]> * Update README.md --------- Co-authored-by: alexxu-amd <[email protected]> Co-authored-by: Sam Wu <[email protected]> Co-authored-by: Aryan Salmanpour <[email protected]>
1 parent d2e5131 commit 442a539

15 files changed

+611
-861
lines changed

.readthedocs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ python:
1515
build:
1616
os: ubuntu-22.04
1717
tools:
18-
python: "3.8"
18+
python: "3.10"

README.md

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
rocJPEG is a high performance JPEG decode SDK for AMD GPUs. Using the rocJPEG API, you can access the JPEG decoding features available on your GPU.
66

7+
>[!Note]
8+
>The published documentation is available at [rocJPEG](https://rocm.docs.amd.com/projects/rocJPEG/en/latest/) in an organized, easy-to-read format, with search and a table of contents. The documentation source files reside in the `docs` folder of this repository. As with all ROCm projects, the documentation is open source. For more information on contributing to the documentation, see [Contribute to ROCm documentation](https://rocm.docs.amd.com/en/latest/contribute/contributing.html)
9+
710
## Supported JPEG chroma subsampling
811

912
* YUV 4:4:4
@@ -15,7 +18,7 @@ rocJPEG is a high performance JPEG decode SDK for AMD GPUs. Using the rocJPEG AP
1518
## Prerequisites
1619

1720
* Linux distribution
18-
* Ubuntu - `20.04` / `22.04` / `24.04`
21+
* Ubuntu - `22.04` / `24.04`
1922
* RHEL - `8` / `9`
2023
* SLES - `15-SP5`
2124

@@ -29,26 +32,29 @@ rocJPEG is a high performance JPEG decode SDK for AMD GPUs. Using the rocJPEG AP
2932
> [!IMPORTANT]
3033
> `sudo amdgpu-install --usecase=rocm`
3134
32-
* Video Acceleration API (VA-API) Version `2.16.0+` - `Libva` is an implementation for VA-API
33-
```shell
34-
sudo apt install libva-amdgpu-dev
35-
```
36-
> [!NOTE]
37-
> RPM Packages for `RHEL`/`SLES` - `libva-amdgpu-devel`
35+
* Video Acceleration API - `libva-amdgpu-dev` is an AMD implementation for VA-API
36+
```shell
37+
sudo apt install libva-amdgpu-dev
38+
```
39+
> [!NOTE]
40+
> * RPM Packages for `RHEL`/`SLES` - `libva-amdgpu-devel`
41+
> * `libva-amdgpu` is strongly recommended over system `libva` as it is used for building mesa-amdgpu-va-driver
3842
3943
* AMD VA Drivers
40-
```shell
41-
sudo apt install libva2-amdgpu libva-amdgpu-drm2 libva-amdgpu-wayland2 libva-amdgpu-x11-2 mesa-amdgpu-va-drivers
42-
```
43-
> [!NOTE]
44-
> RPM Packages for `RHEL`/`SLES` - `libva-amdgpu mesa-amdgpu-va-drivers`
44+
```shell
45+
sudo apt install libva2-amdgpu libva-amdgpu-drm2 libva-amdgpu-wayland2 libva-amdgpu-x11-2 mesa-amdgpu-va-drivers
46+
```
47+
> [!NOTE]
48+
> RPM Packages for `RHEL`/`SLES` - `libva-amdgpu mesa-amdgpu-va-drivers`
4549
46-
* CMake `3.5` or later
50+
* CMake `3.10` or later
4751

4852
```shell
4953
sudo apt install cmake
5054
```
51-
55+
56+
* AMD Clang++ Version 18.0.0 or later - installed with ROCm
57+
5258
* pkg-config
5359

5460
```shell
@@ -67,7 +73,6 @@ rocJPEG is a high performance JPEG decode SDK for AMD GPUs. Using the rocJPEG AP
6773
>[!NOTE]
6874
>
6975
> * All package installs are shown with the `apt` package manager. Use the appropriate package manager for your operating system.
70-
> * To install rocJPEG with minimum requirements, follow the [quick-start](./docs/install/quick-start.rst) instructions
7176
7277
### Prerequisites setup script for Linux
7378
@@ -90,7 +95,8 @@ The installation process uses the following steps:
9095

9196
* Install ROCm `6.3.0` or later with [amdgpu-install](https://rocm.docs.amd.com/projects/install-on-linux/en/latest/how-to/amdgpu-install.html) with `--usecase=rocm`
9297

93-
* Use either [Package install](#package-install) or [Source install](#source-install) as described below.
98+
>[!IMPORTANT]
99+
> Use **either** [package install](#package-install) **or** [source install](#source-install) as described below.
94100
95101
### Package install
96102

@@ -188,16 +194,3 @@ individual folders to build and run the samples.
188194
You can find rocJPEG Docker containers in our
189195
[GitHub repository](https://github.com/ROCm/rocJPEG/tree/develop/docker).
190196

191-
## Documentation
192-
193-
Run the following code to build our documentation locally.
194-
195-
```shell
196-
cd docs
197-
pip3 install -r sphinx/requirements.txt
198-
python3 -m sphinx -T -E -b html -d _build/doctrees -D language=en . _build/html
199-
```
200-
201-
For more information on documentation builds, refer to the
202-
[Building documentation](https://rocm.docs.amd.com/en/latest/contribute/building.html)
203-
page.
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
.. meta::
2+
:description: decoding a jpeg stream with rocJPEG
3+
:keywords: rocJPEG, ROCm, API, documentation, decoding, jpeg
4+
5+
6+
********************************************************************
7+
Decoding a JPEG stream with rocJPEG
8+
********************************************************************
9+
10+
rocJPEG provides two functions, ``rocJpegDecode()`` and ``rocJpegDecodeBatched()``, for decoding JPEG image.
11+
12+
.. code:: cpp
13+
14+
RocJpegStatus rocJpegDecode(
15+
RocJpegHandle handle,
16+
RocJpegStreamHandle jpeg_stream_handle,
17+
const RocJpegDecodeParams *decode_params,
18+
RocJpegImage *destination);
19+
20+
RocJpegStatus rocJpegDecodeBatched(
21+
RocJpegHandle handle,
22+
RocJpegStreamHandle *jpeg_stream_handles,
23+
int batch_size,
24+
const RocJpegDecodeParams *decode_params,
25+
RocJpegImage *destinations);
26+
27+
``rocJpegDecode()`` is used for decoding single images and ``rocJpegDecodeBatched()`` is used for decoding batches of JPEG images. ``rocJpegDecode()`` and ``rocJpegDecodeBatched()`` copy decoded images to a ``RocJpegImage`` struct.
28+
29+
.. code:: cpp
30+
31+
typedef struct {
32+
uint8_t* channel[ROCJPEG_MAX_COMPONENT];
33+
uint32_t pitch[ROCJPEG_MAX_COMPONENT];
34+
} RocJpegImage;
35+
36+
``rocJpegDecodeBatched()`` behaves the same way as ``rocJpegDecode()`` except that ``rocJpegDecodeBatched()`` takes an array of stream handles and an array of decode parameters as input, decodes the batch of JPEG images, and stores the decoded images in an output array of destination images.
37+
38+
``rocJpegDecodeBatched()`` is suited for use on ASICs with multiple JPEG cores and is more efficient than multiple calls to ``rocJpegDecode()``. Choosing a batch size that is a multiple of available JPEG cores is recommended.
39+
40+
Memory has to be allocate to each channel of ``RocJpegImage``, including every channel of every ``RocJpegImage`` in the destination image array passed to ``rocJpegDecodeBatched()``. Use |hipmalloc|_ to allocate memory.
41+
42+
.. |hipmalloc| replace:: ``hipMalloc()``
43+
.. _hipmalloc: https://rocm.docs.amd.com/projects/HIP/en/latest/how-to/virtual_memory.html
44+
45+
For example:
46+
47+
.. code:: cpp
48+
49+
// Allocate device memory for the decoded output image
50+
RocJpegImage output_image = {};
51+
RocJpegDecodeParams decode_params = {};
52+
decode_params.output_format = ROCJPEG_OUTPUT_NATIVE;
53+
54+
// For this sample assuming the input image has a YUV420 chroma subsampling.
55+
// For YUV420 subsampling, the native decoded output image would be NV12 (i.e., the rocJPegDecode API copies Y to first channel and UV (interleaved) to second channel of RocJpegImage)
56+
output_image.pitch[1] = output_image.pitch[0] = widths[0];
57+
hipError_t hip_status;
58+
hip_status = hipMalloc(&output_image.channel[0], output_image.pitch[0] * heights[0]);
59+
if (hip_status != hipSuccess) {
60+
std::cerr << "Failed to allocate device memory for the first channel" << std::endl;
61+
rocJpegStreamDestroy(rocjpeg_stream_handle);
62+
rocJpegDestroy(handle);
63+
return EXIT_FAILURE;
64+
}
65+
66+
hip_status = hipMalloc(&output_image.channel[1], output_image.pitch[1] * (heights[0] >> 1));
67+
if (hip_status != hipSuccess) {
68+
std::cerr << "Failed to allocate device memory for the second channel" << std::endl;
69+
hipFree((void *)output_image.channel[0]);
70+
rocJpegStreamDestroy(rocjpeg_stream_handle);
71+
rocJpegDestroy(handle);
72+
return EXIT_FAILURE;
73+
}
74+
75+
// Decode the JPEG stream
76+
status = rocJpegDecode(handle, rocjpeg_stream_handle, &decode_params, &output_image);
77+
if (status != ROCJPEG_STATUS_SUCCESS) {
78+
std::cerr << "Failed to decode JPEG stream with error code: " << rocJpegGetErrorName(status) << std::endl;
79+
hipFree((void *)output_image.channel[0]);
80+
hipFree((void *)output_image.channel[1]);
81+
rocJpegStreamDestroy(rocjpeg_stream_handle);
82+
rocJpegDestroy(handle);
83+
return EXIT_FAILURE;
84+
}
85+
86+
87+
The behaviors of ``rocJpegDecode()`` and ``rocJpegDecodeBatched()`` depend on ``RocJpegOutputFormat`` and ``RocJpegDecodeParms``.
88+
89+
``RocJpegOutputFormat`` specifies the output format to be used to decode the JPEG image. It can be set to any one of these output formats:
90+
91+
.. csv-table::
92+
:header: "Output format", "Meaning"
93+
94+
"ROCJPEG_OUTPUT_NATIVE", "Return native unchanged decoded YUV image from the VCN JPEG deocder."
95+
"ROCJPEG_OUTPUT_YUV_PLANAR", "Return in the YUV planar format."
96+
"ROCJPEG_OUTPUT_Y", "Return the Y component only."
97+
"ROCJPEG_OUTPUT_RGB", "Convert to interleaved RGB."
98+
"ROCJPEG_OUTPUT_RGB_PLANAR", "Convert to planar RGB."
99+
100+
``RocJpegOutputFormat`` is a member of the ``RocJpegDecodeParams`` struct. ``RocJpegDecodeParams`` defines the output format, crop rectangle, and target dimensions to use when decoding the image.
101+
102+
.. code:: cpp
103+
104+
typedef struct {
105+
RocJpegOutputFormat output_format; /**< Output data format. See RocJpegOutputFormat for description. */
106+
struct {
107+
int16_t left; /**< Left coordinate of the crop rectangle. */
108+
int16_t top; /**< Top coordinate of the crop rectangle. */
109+
int16_t right; /**< Right coordinate of the crop rectangle. */
110+
int16_t bottom; /**< Bottom coordinate of the crop rectangle. */
111+
} crop_rectangle; /**< Defines the region of interest (ROI) to be copied into the RocJpegImage output buffers. */
112+
struct {
113+
uint32_t width; /**< Target width of the picture to be resized. */
114+
uint32_t height; /**< Target height of the picture to be resized. */
115+
} target_dimension; /**< (future use) Defines the target width and height of the picture to be resized. Both should be even.
116+
If specified, allocate the RocJpegImage buffers based on these dimensions. */
117+
} RocJpegDecodeParams;
118+
119+
120+
For example, consider a situation where ``RocJpegOutputFormat`` is set to ``ROCJPEG_OUTPUT_NATIVE``. Based on the chroma subsampling of the input image, ``rocJpegDecode()`` does one of the following:
121+
122+
* For ``ROCJPEG_CSS_444`` and ``ROCJPEG_CSS_440``: writes Y, U, and V to the first, second, and third channels of ``RocJpegImage``.
123+
* For ``ROCJPEG_CSS_422``: writes YUYV (packed) to the first channel of ``RocJpegImage``.
124+
* For ``ROCJPEG_CSS_420``: writes Y to the first channel and UV (interleaved) to the second channel of ``RocJpegImage``.
125+
* For ``ROCJPEG_CSS_400``: writes Y to the first channel of ``RocJpegImage``.
126+
127+
If ``RocJpegOutputFormat`` is set to ``ROCJPEG_OUTPUT_Y`` or ``ROCJPEG_OUTPUT_RGB``, then ``rocJpegDecode()`` copies the output to the first channel of ``RocJpegImage``.
128+
129+
If ``RocJpegOutputFormat`` is set to ``ROCJPEG_OUTPUT_YUV_PLANAR`` or ``ROCJPEG_OUTPUT_RGB_PLANAR``, the data is written to the corresponding channels of the ``RocJpegImage`` destination structure.
130+
131+
The destination images must be large enough to store the output.
132+
133+
Use |rocjpegimageinfo|_ to extract information and calculate the required memory sizes for the destination image following these guidelines:.
134+
135+
.. |rocjpegimageinfo| replace:: ``rocJpegGetImageInfo()``
136+
.. _rocjpegimageinfo: ./rocjpeg-retrieve-image-info.html
137+
138+
.. csv-table::
139+
:header: "Output format", "Chroma subsampling", "Minimum size of destination.pitch[c]", "Minimum size of destination.channel[c]"
140+
141+
"ROCJPEG_OUTPUT_NATIVE", "ROCJPEG_CSS_444", "destination.pitch[c] = widths[c] for c = 0, 1, 2", "destination.channel[c] = destination.pitch[c] * heights[0] for c = 0, 1, 2"
142+
"ROCJPEG_OUTPUT_NATIVE", "ROCJPEG_CSS_440", "destination.pitch[c] = widths[c] for c = 0, 1, 2", "destination.channel[0] = destination.pitch[0] * heights[0], destination.channel[c] = destination.pitch[c] * heights[0] / 2 for c = 1, 2"
143+
"ROCJPEG_OUTPUT_NATIVE", "ROCJPEG_CSS_422", "destination.pitch[0] = widths[0] * 2", "destination.channel[0] = destination.pitch[0] * heights[0]"
144+
"ROCJPEG_OUTPUT_NATIVE", "ROCJPEG_CSS_420", "destination.pitch[1] = destination.pitch[0] = widths[0]", "destination.channel[0] = destination.pitch[0] * heights[0], destination.channel[1] = destination.pitch[1] * (heights[0] >> 1)"
145+
"ROCJPEG_OUTPUT_NATIVE", "ROCJPEG_CSS_400", "destination.pitch[0] = widths[0]", "destination.channel[0] = destination.pitch[0] * heights[0]"
146+
"ROCJPEG_OUTPUT_YUV_PLANAR", "ROCJPEG_CSS_444, ROCJPEG_CSS_440, ROCJPEG_CSS_422, ROCJPEG_CSS_420", "destination.pitch[c] = widths[c] for c = 0, 1, 2", "destination.channel[c] = destination.pitch[c] * heights[c] for c = 0, 1, 2"
147+
"ROCJPEG_OUTPUT_YUV_PLANAR", "ROCJPEG_CSS_400", "destination.pitch[0] = widths[0]", "destination.channel[0] = destination.pitch[0] * heights[0]"
148+
"ROCJPEG_OUTPUT_Y", "Any of the supported chroma subsampling", "destination.pitch[0] = widths[0]", "destination.channel[0] = destination.pitch[0] * heights[0]"
149+
"ROCJPEG_OUTPUT_RGB", "Any of the supported chroma subsampling", "destination.pitch[0] = widths[0] * 3", "destination.channel[0] = destination.pitch[0] * heights[0]"
150+
"ROCJPEG_OUTPUT_RGB_PLANAR", "Any of the supported chroma subsampling", "destination.pitch[c] = widths[c] for c = 0, 1, 2", "destination.channel[c] = destination.pitch[c] * heights[c] for c = 0, 1, 2"
151+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.. meta::
2+
:description: retrieving image information with rocJPEG
3+
:keywords: rocJPEG, ROCm, API, documentation, image information, jpeg
4+
5+
6+
********************************************************************
7+
Retrieving image information with rocJPEG
8+
********************************************************************
9+
10+
Retrieving image information is done using ``rocJpegGetImageInfo()``.
11+
12+
.. code:: cpp
13+
14+
RocJpegStatus rocJpegGetImageInfo(
15+
RocJpegHandle handle,
16+
RocJpegStreamHandle jpeg_stream_handle,
17+
uint8_t *num_components,
18+
RocJpegChromaSubsampling *subsampling,
19+
uint32_t *widths,
20+
uint32_t *heights);
21+
22+
``rocJpegGetImageInfo()`` takes the ``RocJpegHandle`` and a ``RocJpegStreamHandle`` as inputs, and returns the subsampling, number of components, and widths and heights of the components. These are passed to the ``subsampling``, ``num_components``, and ``widths`` and ``heights`` output parameters.
23+
24+
The ``subsampling`` output parameter is a ``RocJpegChromaSubsampling`` enum.
25+
26+
.. code:: cpp
27+
28+
typedef enum {
29+
ROCJPEG_CSS_444 = 0,
30+
ROCJPEG_CSS_440 = 1,
31+
ROCJPEG_CSS_422 = 2,
32+
ROCJPEG_CSS_420 = 3,
33+
ROCJPEG_CSS_411 = 4,
34+
ROCJPEG_CSS_400 = 5,
35+
ROCJPEG_CSS_UNKNOWN = -1
36+
} RocJpegChromaSubsampling;
37+
38+
Its value is set to the chroma subsampling retrieved from the image.
39+
40+
For example:
41+
42+
.. code:: cpp
43+
44+
// Get the image info
45+
uint8_t num_components;
46+
RocJpegChromaSubsampling subsampling;
47+
uint32_t widths[ROCJPEG_MAX_COMPONENT] = {};
48+
uint32_t heights[ROCJPEG_MAX_COMPONENT] = {};
49+
50+
status = rocJpegGetImageInfo(handle, rocjpeg_stream_handle, &num_components, &subsampling, widths, heights);
51+
if (status != ROCJPEG_STATUS_SUCCESS) {
52+
std::cerr << "Failed to get image info with error code: " << rocJpegGetErrorName(status) << std::endl;
53+
rocJpegStreamDestroy(rocjpeg_stream_handle);
54+
rocJpegDestroy(handle);
55+
return EXIT_FAILURE;
56+
}
57+
58+
59+
``rocJpegGetImageInfo()`` is thread safe.
60+
61+
.. note::
62+
63+
The VCN hardware-accelerated JPEG decoder in AMD GPUs only supports decoding JPEG images with ``ROCJPEG_CSS_444``, ``ROCJPEG_CSS_440``, ``ROCJPEG_CSS_422``, ``ROCJPEG_CSS_420``, and ``ROCJPEG_CSS_400`` chroma subsampling.

0 commit comments

Comments
 (0)