Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 76 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,53 @@ if(NOT _cosmo_nn_backend_count EQUAL 1)
message(FATAL_ERROR "Exactly one NN backend must be enabled: Sophon, CPU, or RKNN")
endif()

# The selected inference backend is a build-wide compile contract. Business,
# API, and utility OBJECT libraries include the same backend-aware headers as
# the inference layer, so every project target must observe one consistent set
# of feature macros. Chip identity remains separate build data below.
if(COSMO_NN_USE_SOPHON_BACKEND)
add_compile_definitions(COSMO_NN_USE_SOPHON_BACKEND)
elseif(COSMO_NN_USE_CPU_BACKEND)
add_compile_definitions(
COSMO_NN_USE_CPU_BACKEND
COSMO_NN_USE_HOST_BACKEND
COSMO_NN_USE_ONNX_BACKEND)
elseif(COSMO_NN_USE_RKNN_BACKEND)
add_compile_definitions(
COSMO_NN_USE_RKNN_BACKEND
COSMO_NN_USE_HOST_BACKEND
COSMO_NN_USE_RAW_MODEL_BACKEND)
endif()

# A target package is always chip-specific even when several chips share one
# inference/media implementation. Keep the chip identity as build data instead
# of spreading per-chip preprocessor branches through the RKNN backend.
set(COSMO_TARGET_CHIP "" CACHE STRING "Target accelerator chip recorded in release packages")
if(COSMO_TARGET_CHIP)
string(TOLOWER "${COSMO_TARGET_CHIP}" COSMO_TARGET_CHIP_NORMALIZED)
if(NOT COSMO_TARGET_CHIP_NORMALIZED MATCHES "^(bm1688|cv186x|rk3576|rv1126b|unspecified)$")
message(FATAL_ERROR "Unsupported COSMO_TARGET_CHIP: ${COSMO_TARGET_CHIP}")
endif()
endif()

if(COSMO_NN_USE_RKNN_BACKEND)
if(NOT COSMO_TARGET_CHIP_NORMALIZED MATCHES "^(rk3576|rv1126b)$")
message(FATAL_ERROR
"RKNN builds require COSMO_TARGET_CHIP=rk3576 or rv1126b")
endif()
string(TOUPPER "${COSMO_TARGET_CHIP_NORMALIZED}" COSMO_TARGET_CHIP_LABEL)
set(COSMO_PLATFORM_PROFILE
"${CMAKE_SOURCE_DIR}/config/rknn/platforms/${COSMO_TARGET_CHIP_NORMALIZED}.json")
if(NOT EXISTS "${COSMO_PLATFORM_PROFILE}")
message(FATAL_ERROR "RKNN platform profile not found: ${COSMO_PLATFORM_PROFILE}")
endif()
add_compile_definitions(
COSMO_RKNN_TARGET_CHIP="${COSMO_TARGET_CHIP_NORMALIZED}"
COSMO_RKNN_TARGET_CHIP_LABEL="${COSMO_TARGET_CHIP_LABEL}")
message(STATUS
"RKNN platform profile: ${COSMO_TARGET_CHIP_NORMALIZED} (${COSMO_PLATFORM_PROFILE})")
endif()

# Media acceleration is selected independently from inference. Defaults keep
# existing builds unchanged while allowing a software media pipeline to be
# paired with another inference backend.
Expand All @@ -136,7 +183,7 @@ option(COSMO_MEDIA_USE_SOPHON_BACKEND "Enable Sophon hardware media backend"
${_cosmo_media_sophon_default})
option(COSMO_MEDIA_USE_CPU_BACKEND "Enable FFmpeg software media backend"
${_cosmo_media_cpu_default})
option(COSMO_MEDIA_USE_ROCKCHIP_BACKEND "Enable Rockchip MPP/RGA Copy-first media backend"
option(COSMO_MEDIA_USE_ROCKCHIP_BACKEND "Enable Rockchip MPP/RGA hardware media backend"
${_cosmo_media_rockchip_default})

set(_cosmo_media_backend_count 0)
Expand Down Expand Up @@ -778,6 +825,24 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/netplan/
##########################################################
# Packaging
##########################################################
if(COSMO_NN_USE_RKNN_BACKEND AND COSMO_PACKAGE_MODELS STREQUAL "include")
if(NOT DEFINED RESOURCE_OVERLAY_DIR OR NOT RESOURCE_OVERLAY_DIR)
message(FATAL_ERROR
"RKNN packages that include models require RESOURCE_OVERLAY_DIR")
endif()
find_package(Python3 REQUIRED COMPONENTS Interpreter)
add_custom_target(verify_rknn_packaging_resources ALL
COMMAND "${Python3_EXECUTABLE}"
"${CMAKE_SOURCE_DIR}/tools/rknn/stage_platform_resources.py"
--platform-profile "${COSMO_PLATFORM_PROFILE}"
--output-dir "${RESOURCE_OVERLAY_DIR}"
--verify
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
COMMENT "Verifying target-specific RKNN resource identity and freshness"
VERBATIM
)
endif()

set(PACKAGE_PREFIX "cosmo")
set(PACKAGE_VERSION "V${VER_MAJOR}.${VER_MINOR}.${VER_PATCH}")
set(PACKAGE_NAME "${PACKAGE_PREFIX}-${PACKAGE_VERSION}")
Expand All @@ -786,12 +851,7 @@ set(PACKAGE_NAME "${PACKAGE_PREFIX}-${PACKAGE_VERSION}")
# convenient for automation, but it can be separated from the package during a
# manual copy. This marker keeps such mistakes observable and prevents packages
# for different chips from being byte-identical.
set(COSMO_TARGET_CHIP "" CACHE STRING "Target accelerator chip recorded in release packages")
if(COSMO_TARGET_CHIP)
string(TOLOWER "${COSMO_TARGET_CHIP}" COSMO_TARGET_CHIP_NORMALIZED)
if(NOT COSMO_TARGET_CHIP_NORMALIZED MATCHES "^(bm1688|cv186x|rk3576|unspecified)$")
message(FATAL_ERROR "Unsupported COSMO_TARGET_CHIP: ${COSMO_TARGET_CHIP}")
endif()
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/target-chip.txt"
"${COSMO_TARGET_CHIP_NORMALIZED}\n")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/target-chip.txt"
Expand All @@ -800,6 +860,13 @@ if(COSMO_TARGET_CHIP)
message(STATUS "Package target chip: ${COSMO_TARGET_CHIP_NORMALIZED}")
endif()

if(COSMO_NN_USE_RKNN_BACKEND)
install(FILES "${COSMO_PLATFORM_PROFILE}"
DESTINATION share/cosmo
RENAME platform-profile.json
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ)
endif()

# Generate and install version.txt
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/version.txt" "${PACKAGE_VERSION}\n")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/version.txt"
Expand Down Expand Up @@ -868,6 +935,9 @@ set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/packages")
include(CPack)

set(COSMO_PACKAGE_TARGETS ${EXECUTABLE_NAME} web_frontend)
if(TARGET verify_rknn_packaging_resources)
list(APPEND COSMO_PACKAGE_TARGETS verify_rknn_packaging_resources)
endif()
add_custom_target(package_all
# CPack names are content-addressed only after generation. Clear artifacts
# from an earlier profile before creating and exporting this build's output.
Expand Down
8 changes: 8 additions & 0 deletions cmake/rockchip_media.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,11 @@ install(DIRECTORY "${COSMO_ROCKCHIP_MEDIA_ROOT}/lib/"
FILES_MATCHING
PATTERN "librockchip_mpp.so*"
PATTERN "librga.so*")

set(ROCKCHIP_MEDIA_MANIFEST
"${COSMO_ROCKCHIP_MEDIA_ROOT}/.cosmo-rockchip-media.json")
if(EXISTS "${ROCKCHIP_MEDIA_MANIFEST}")
install(FILES "${ROCKCHIP_MEDIA_MANIFEST}"
DESTINATION share/cosmo/platform
RENAME rockchip-media-manifest.json)
endif()
5 changes: 4 additions & 1 deletion config/rknn/models/helmet.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"model_type": "classify",
"source_repository_path": "data/resource/aiboxresource_x86/models/prod_X86_7982161_helmet_V1.0.0/model.onnx",
"source_sha256": "a0ea37d99416371c6ef073d5ac87b486b77bb822b1f8aa29f2f30a8a06c97cdd",
"packaging": {
"algorithm_code": "7982161"
},
"conversion": {
"target_platform": "rk3576",
"maximum_onnx_opset": 19,
"optimization_level": 3,
"preprocessing_owner": "host"
Expand All @@ -30,6 +32,7 @@
],
"calibration": {
"source": "person crops detected in data/test-video/Safety Helmet.mp4",
"person_detector_model": "yolov8",
"minimum_samples": 32,
"labeled": false
},
Expand Down
4 changes: 3 additions & 1 deletion config/rknn/models/yolov8.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
"model_type": "yolov8_det",
"source_repository_path": "data/resource/aiboxresource_x86/models/prod_X86_9275710_YOLOV8_V1.0.0/model.onnx",
"source_sha256": "5f8e91cb4507596b66cd5e3b7193bb16f7bd4779ed3b78e3613fcc51b83db8e1",
"packaging": {
"algorithm_code": "9275710"
},
"conversion": {
"target_platform": "rk3576",
"input_sha256": "17a2cd603576afd1b5dd86a485933b857534355d25f517f6e1f2acd2a2fe4563",
"maximum_onnx_opset": 19,
"maximum_onnx_ir_version": 9,
Expand Down
34 changes: 34 additions & 0 deletions config/rknn/platforms/rk3576.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"schema_version": 1,
"chip": "rk3576",
"display_name": "RK3576",
"backend": "rknn",
"toolchain_lock": "../toolchain-lock.json",
"conversion": {
"target_platform": "rk3576"
},
"runtime": {
"architecture": "aarch64",
"default_core_mode": "auto"
},
"media": {
"default_backend": "rockchip",
"cpu_fallback": true,
"runtime_lock": "../../rockchip-media/runtime-lock.json",
"runtime_profile": "rk3576-build-env-v1",
"require_sealed_sysroot": false
},
"packaging": {
"directory_token": "RK3576",
"resource_template_directory": "data/resource/aiboxresource_rknn",
"resource_overlay_directory": "data/resource/aiboxresource_rknn",
"legacy_models_directory": "data/resource/aiboxresource_rknn/models"
},
"device": {
"compatible_tokens": ["rk3576"]
},
"qualification": {
"status": "candidate-validated",
"requires_target_bound_evidence": true
}
}
35 changes: 35 additions & 0 deletions config/rknn/platforms/rv1126b.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"schema_version": 1,
"chip": "rv1126b",
"display_name": "RV1126B",
"backend": "rknn",
"toolchain_lock": "../toolchain-lock.json",
"conversion": {
"target_platform": "rv1126b"
},
"runtime": {
"architecture": "aarch64",
"default_core_mode": "auto"
},
"media": {
"default_backend": "rockchip",
"cpu_fallback": true,
"runtime_lock": "../../rockchip-media/runtime-lock.json",
"runtime_profile": "mpp-1.1.0-rga-1.10.6",
"require_sealed_sysroot": true
},
"packaging": {
"directory_token": "RV1126B",
"resource_template_directory": "data/resource/aiboxresource_rknn",
"resource_overlay_directory": "output/platform-artifacts/rv1126b/resource-overlay",
"resource_manifest_required": true,
"legacy_models_directory": "output/platform-artifacts/rv1126b/resource-overlay/models"
},
"device": {
"compatible_tokens": ["rv1126b"]
},
"qualification": {
"status": "candidate-validated",
"requires_target_bound_evidence": true
}
}
47 changes: 30 additions & 17 deletions config/rknn/toolchain-lock.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
{
"schema_version": 1,
"target_platform": "rk3576",
"cosmo_edge_base_sha": "2eaf5fd7b096f98a9dca1ef298e03440484e15bc",
"tensorrt_reference_sha": "57c578616ba826f01921bb4e43d7a695549b6b9e",
"rknn_toolkit2": {
"version": "2.3.2",
"tag_sha": "42aa1d426c0a9e0869b6374edba009f7208a1926",
"python": "3.10",
"wheel_sha256": "6cb783ddf293ac509f39bf9127acf6a5492bbb67e4b4b4ac33a7c6d2cefb4f3c"
"schema_version": 2,
"family": "rknn-toolkit2",
"version": "2.3.2",
"python": "3.10",
"source": {
"repository": "https://github.com/airockchip/rknn-toolkit2",
"tag_sha": "42aa1d426c0a9e0869b6374edba009f7208a1926"
},
"wheel": {
"distribution": "rknn-toolkit2",
"sha256": "6cb783ddf293ac509f39bf9127acf6a5492bbb67e4b4b4ac33a7c6d2cefb4f3c"
},
"rknn_model_zoo": {
"model_zoo": {
"version": "2.3.2",
"tag_sha": "bad6c7334531becaf90a561988519b7bec34d0ab"
},
"offline_bundle": {
"known_offline_bundle": {
"file": "rk3576-offline-bundle-v2.3.2-20260804.tar.gz",
"sha256": "12960656f854ab8bfe0e2ee2292745245d82d1cd88b7acd0a8cb6c06c080c726",
"entry_count": 42
Expand All @@ -24,12 +26,6 @@
"rknn_api_header_sha256": "c48e11a6f41b451a5fd1e4ad774ea60252d3d94f78bee9b21ea3d21b21deba9a",
"rknn_server_sha256": "eea12fe4270fad8aff015056319705b2eb871563ebd001eff8d8788bdd1c0cfa"
},
"device_baseline": {
"kernel": "6.1.118",
"rknpu_driver": "0.9.8",
"system_runtime": "2.1.0",
"system_runtime_sha256": "0f1c5db6c649c8705759308aa56ecffc3295c7eb465f9ec9170882f44004aa8d"
},
"models": {
"helmet": {
"onnx_sha256": "a0ea37d99416371c6ef073d5ac87b486b77bb822b1f8aa29f2f30a8a06c97cdd",
Expand All @@ -44,5 +40,22 @@
"input": [1, 3, 640, 640],
"output": [1, 84, 8400]
}
},
"qualification": {
"rk3576": {
"status": "candidate-validated",
"cosmo_edge_base_sha": "2eaf5fd7b096f98a9dca1ef298e03440484e15bc",
"tensorrt_reference_sha": "57c578616ba826f01921bb4e43d7a695549b6b9e",
"device_baseline": {
"kernel": "6.1.118",
"rknpu_driver": "0.9.8",
"system_runtime": "2.1.0",
"system_runtime_sha256": "0f1c5db6c649c8705759308aa56ecffc3295c7eb465f9ec9170882f44004aa8d"
}
},
"rv1126b": {
"status": "candidate-validated",
"requires_target_bound_evidence": true
}
}
}
78 changes: 78 additions & 0 deletions config/rockchip-media/runtime-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"schema_version": 1,
"family": "rockchip-mpp-rga",
"runtimes": {
"rk3576-build-env-v1": {
"architecture": "aarch64",
"provenance": "legacy-build-image",
"sources": {
"builder": {
"repository": "ghcr.io/cosmo-wander-ai/cosmo_edge-build-env_rk3576",
"revision": "sha256:135d25d0baf14e7918726f7efb040a0627926aedd5825f52fab6c1cd208da348"
}
},
"artifacts": {
"include/rockchip/rk_mpi.h": {},
"include/rga/im2d.h": {},
"lib/librockchip_mpp.so": {
"elf": {
"machine": "AArch64",
"soname": "librockchip_mpp.so.1"
}
},
"lib/librga.so": {
"elf": {
"machine": "AArch64",
"soname": "librga.so.2"
}
}
}
},
"mpp-1.1.0-rga-1.10.6": {
"architecture": "aarch64",
"provenance": "source-and-official-prebuilt",
"sources": {
"mpp": {
"repository": "https://github.com/rockchip-linux/mpp",
"revision": "c08762ebfadeb4e986d2fed993bc7a54862d3ebe",
"tag": "1.1.0"
},
"rga": {
"repository": "https://github.com/airockchip/librga",
"revision": "2b32edcb97b601b25683e2941d888c8515da6d55",
"api_version": "1.10.6_[3]",
"artifact": "libs/Linux/gcc-aarch64/librga.so"
}
},
"artifacts": {
"include/rockchip/rk_mpi.h": {
"sha256": "96dbae7d90e91baaac38821fc06c74a327cac888007841fe5937798259193646"
},
"include/rga/im2d.h": {
"sha256": "5ee06891775451c56e6264f5d53db0a4e948e1830287f3a5db4f75c30ac0ff11"
},
"include/rga/im2d_version.h": {
"sha256": "66021285feb75dc1b492345adc074722813b8945dd998357002cf5396872980c"
},
"lib/librockchip_mpp.so.0": {
"sha256": "c27de803917989f85c1435261ddcf4db16182bd72a6830090e98031e89700e0e",
"elf": {
"machine": "AArch64",
"soname": "librockchip_mpp.so.1"
}
},
"lib/librga.so": {
"sha256": "e150bda757fb5e8a649c429ec7cabaf851aa2a3be554ed494d5519e8790d943b",
"elf": {
"machine": "AArch64",
"soname": "librga.so"
}
}
},
"links": {
"lib/librockchip_mpp.so": "librockchip_mpp.so.1",
"lib/librockchip_mpp.so.1": "librockchip_mpp.so.0"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"algorithm_code":"7982161","chip_type":"RK3576","labels":[{"id":"0","name":"helmet","threshold":[0.5,0.5]},{"id":"1","name":"nohelmet","threshold":[0.5,0.5]}],"model_type":"classify","models":[{"description":"","file_md5":"","file_name":"","inputs":[{"data_type":0,"name":"images","shape":[1,3,224,224]}],"max_batch":1,"name":"helmet","outputs":[{"data_type":0,"name":"output0","shape":[1,2]}],"params":{"crop":true,"crop_h_bottom":0,"crop_h_top":0,"crop_w_left":0,"crop_w_right":0,"gravity":0,"input_size":[224,224],"is_bgr":false,"normalize_mean":[0,0,0],"normalize_scale":0.00392157,"padding_color":[114,114,114],"square":false,"square_mode":0}}],"reduce":"","version":"V1.0.0"}
{"algorithm_code":"7982161","chip_type":"RK3576","labels":[{"id":"0","name":"helmet","threshold":[0.5,0.5]},{"id":"1","name":"nohelmet","threshold":[0.5,0.5]}],"model_type":"classify","models":[{"description":"","file_md5":"","file_name":"","inputs":[{"data_type":0,"name":"images","shape":[1,3,224,224]}],"max_batch":1,"name":"helmet","outputs":[{"data_type":0,"name":"output0","shape":[1,2]}],"params":{"crop":true,"crop_h_bottom":0,"crop_h_top":0,"crop_w_left":0,"crop_w_right":0,"gravity":0,"input_size":[224,224],"is_bgr":false,"normalize_mean":[0,0,0],"normalize_scale":0.00392157,"padding_color":[114,114,114],"rknn_input_contract":"cosmo.rknn.input.rgb_u8_nhwc_0_255_to_0_1.v1","square":false,"square_mode":0}}],"reduce":"","version":"V1.0.0"}
Loading
Loading