()
| 280 | |
| 281 | |
| 282 | def make_image_extension(): |
| 283 | print("Building image extension") |
| 284 | |
| 285 | include_dirs = TORCHVISION_INCLUDE.copy() |
| 286 | library_dirs = TORCHVISION_LIBRARY.copy() |
| 287 | |
| 288 | libraries = [] |
| 289 | define_macros, extra_compile_args = get_macros_and_flags() |
| 290 | |
| 291 | image_dir = CSRS_DIR / "io/image" |
| 292 | sources = list(image_dir.glob("*.cpp")) + list(image_dir.glob("cpu/*.cpp")) + list(image_dir.glob("cpu/giflib/*.c")) |
| 293 | |
| 294 | if IS_ROCM: |
| 295 | sources += list(image_dir.glob("hip/*.cpp")) |
| 296 | # we need to exclude this in favor of the hipified source |
| 297 | sources.remove(image_dir / "image.cpp") |
| 298 | else: |
| 299 | sources += list(image_dir.glob("cuda/*.cpp")) |
| 300 | |
| 301 | Extension = CppExtension |
| 302 | |
| 303 | if USE_PNG: |
| 304 | png_found, png_include_dir, png_library_dir, png_library = find_libpng() |
| 305 | if png_found: |
| 306 | print("Building torchvision with PNG support") |
| 307 | print(f"{png_include_dir = }") |
| 308 | print(f"{png_library_dir = }") |
| 309 | include_dirs.append(png_include_dir) |
| 310 | library_dirs.append(png_library_dir) |
| 311 | libraries.append(png_library) |
| 312 | define_macros += [("PNG_FOUND", 1)] |
| 313 | else: |
| 314 | warnings.warn("Building torchvision without PNG support") |
| 315 | |
| 316 | if USE_JPEG: |
| 317 | jpeg_found, jpeg_include_dir, jpeg_library_dir = find_library(header="jpeglib.h") |
| 318 | if jpeg_found: |
| 319 | print("Building torchvision with JPEG support") |
| 320 | print(f"{jpeg_include_dir = }") |
| 321 | print(f"{jpeg_library_dir = }") |
| 322 | if jpeg_include_dir is not None and jpeg_library_dir is not None: |
| 323 | # if those are None it means they come from standard paths that are already in the search paths, which we don't need to re-add. |
| 324 | include_dirs.append(jpeg_include_dir) |
| 325 | library_dirs.append(jpeg_library_dir) |
| 326 | libraries.append("jpeg") |
| 327 | define_macros += [("JPEG_FOUND", 1)] |
| 328 | else: |
| 329 | warnings.warn("Building torchvision without JPEG support") |
| 330 | |
| 331 | if USE_WEBP: |
| 332 | webp_found, webp_include_dir, webp_library_dir = find_library(header="webp/decode.h") |
| 333 | if webp_found: |
| 334 | print("Building torchvision with WEBP support") |
| 335 | print(f"{webp_include_dir = }") |
| 336 | print(f"{webp_library_dir = }") |
| 337 | if webp_include_dir is not None and webp_library_dir is not None: |
| 338 | # if those are None it means they come from standard paths that are already in the search paths, which we don't need to re-add. |
| 339 | include_dirs.append(webp_include_dir) |
no test coverage detected
searching dependent graphs…