Repository: NVIDIA-ISAAC-ROS/isaac_ros_nitros Branch: main Commit: 4fbeb113fdf9 Files: 770 Total size: 5.1 MB Directory structure: gitextract_a_s3rfnt/ ├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── SECURITY.md ├── isaac_ros_gxf/ │ ├── CMakeLists.txt │ ├── cmake/ │ │ ├── isaac_ros_gxf-extras.cmake │ │ └── modules/ │ │ └── FindGXF.cmake │ ├── gxf/ │ │ ├── AMENT_IGNORE │ │ └── core/ │ │ └── include/ │ │ ├── common/ │ │ │ ├── assert.hpp │ │ │ ├── backtrace.hpp │ │ │ ├── byte.hpp │ │ │ ├── endian.hpp │ │ │ ├── expected.hpp │ │ │ ├── fixed_map.hpp │ │ │ ├── fixed_string.hpp │ │ │ ├── fixed_vector.hpp │ │ │ ├── iterator.hpp │ │ │ ├── logger.hpp │ │ │ ├── memory_utils.hpp │ │ │ ├── nvtx_helper.hpp │ │ │ ├── singleton.hpp │ │ │ ├── span.hpp │ │ │ ├── strong_type.hpp │ │ │ ├── type_name.hpp │ │ │ ├── type_name_gnuc.hpp │ │ │ ├── type_utils.hpp │ │ │ ├── unique_index_map.hpp │ │ │ └── yaml_parser.hpp │ │ ├── dlpack/ │ │ │ └── dlpack.h │ │ ├── gxf/ │ │ │ ├── app/ │ │ │ │ ├── application.hpp │ │ │ │ ├── arg.hpp │ │ │ │ ├── arg_parse.hpp │ │ │ │ ├── config_parser.hpp │ │ │ │ ├── driver.hpp │ │ │ │ ├── entity_group.hpp │ │ │ │ ├── extension_manager.hpp │ │ │ │ ├── graph_entity.hpp │ │ │ │ ├── graph_utils.hpp │ │ │ │ ├── proxy_component.hpp │ │ │ │ ├── segment.hpp │ │ │ │ └── worker.hpp │ │ │ ├── behavior_tree/ │ │ │ │ ├── constant_behavior.hpp │ │ │ │ ├── entity_count_failure_repeat_controller.hpp │ │ │ │ ├── parallel_behavior.hpp │ │ │ │ ├── repeat_behavior.hpp │ │ │ │ ├── selector_behavior.hpp │ │ │ │ ├── sequence_behavior.hpp │ │ │ │ ├── switch_behavior.hpp │ │ │ │ └── timer_behavior.hpp │ │ │ ├── core/ │ │ │ │ ├── common_expected_macro.hpp │ │ │ │ ├── component.hpp │ │ │ │ ├── entity.hpp │ │ │ │ ├── expected.hpp │ │ │ │ ├── expected_macro.hpp │ │ │ │ ├── filepath.hpp │ │ │ │ ├── gxf.h │ │ │ │ ├── gxf_ext.h │ │ │ │ ├── handle.hpp │ │ │ │ ├── parameter.hpp │ │ │ │ ├── parameter_parser.hpp │ │ │ │ ├── parameter_parser_std.hpp │ │ │ │ ├── parameter_registrar.hpp │ │ │ │ ├── parameter_storage.hpp │ │ │ │ ├── parameter_wrapper.hpp │ │ │ │ ├── registrar.hpp │ │ │ │ ├── resource.hpp │ │ │ │ ├── resource_manager.hpp │ │ │ │ ├── resource_registrar.hpp │ │ │ │ └── type_registry.hpp │ │ │ ├── cuda/ │ │ │ │ ├── cuda_allocator.hpp │ │ │ │ ├── cuda_buffer.hpp │ │ │ │ ├── cuda_common.hpp │ │ │ │ ├── cuda_event.hpp │ │ │ │ ├── cuda_scheduling_terms.hpp │ │ │ │ ├── cuda_stream.hpp │ │ │ │ ├── cuda_stream_id.hpp │ │ │ │ ├── cuda_stream_pool.hpp │ │ │ │ ├── cuda_stream_sync.hpp │ │ │ │ ├── stream_ordered_allocator.hpp │ │ │ │ └── tests/ │ │ │ │ ├── convolution.h │ │ │ │ ├── green_context_with_smid.h │ │ │ │ └── test_cuda_helper.hpp │ │ │ ├── logger/ │ │ │ │ ├── gxf_logger.hpp │ │ │ │ └── logger.hpp │ │ │ ├── multimedia/ │ │ │ │ ├── audio.hpp │ │ │ │ ├── camera.hpp │ │ │ │ └── video.hpp │ │ │ ├── network/ │ │ │ │ ├── tcp_client.hpp │ │ │ │ ├── tcp_client_socket.hpp │ │ │ │ ├── tcp_codelet.hpp │ │ │ │ ├── tcp_server.hpp │ │ │ │ └── tcp_server_socket.hpp │ │ │ ├── npp/ │ │ │ │ ├── nppi_mul_c.hpp │ │ │ │ └── nppi_set.hpp │ │ │ ├── rmm/ │ │ │ │ └── rmm_allocator.hpp │ │ │ ├── serialization/ │ │ │ │ ├── component_serializer.hpp │ │ │ │ ├── endpoint.hpp │ │ │ │ ├── entity_recorder.hpp │ │ │ │ ├── entity_replayer.hpp │ │ │ │ ├── entity_serializer.hpp │ │ │ │ ├── file.hpp │ │ │ │ ├── file_stream.hpp │ │ │ │ ├── serialization_buffer.hpp │ │ │ │ ├── std_component_serializer.hpp │ │ │ │ ├── std_entity_id_serializer.hpp │ │ │ │ ├── std_entity_serializer.hpp │ │ │ │ ├── tests/ │ │ │ │ │ └── serialization_tester.hpp │ │ │ │ └── tid_hash.hpp │ │ │ ├── std/ │ │ │ │ ├── allocator.hpp │ │ │ │ ├── async_buffer_receiver.hpp │ │ │ │ ├── async_buffer_transmitter.hpp │ │ │ │ ├── block_memory_pool.hpp │ │ │ │ ├── clock.hpp │ │ │ │ ├── codelet.hpp │ │ │ │ ├── complex.hpp │ │ │ │ ├── component_allocator.hpp │ │ │ │ ├── component_factory.hpp │ │ │ │ ├── controller.hpp │ │ │ │ ├── cpu_thread.hpp │ │ │ │ ├── cuda_green_context.hpp │ │ │ │ ├── cuda_green_context_pool.hpp │ │ │ │ ├── default_extension.hpp │ │ │ │ ├── dlpack_utils.hpp │ │ │ │ ├── double_buffer_receiver.hpp │ │ │ │ ├── double_buffer_transmitter.hpp │ │ │ │ ├── eos.hpp │ │ │ │ ├── event_based_scheduler.hpp │ │ │ │ ├── extension.hpp │ │ │ │ ├── extension_factory_helper.hpp │ │ │ │ ├── gems/ │ │ │ │ │ ├── event_list/ │ │ │ │ │ │ ├── event_list.hpp │ │ │ │ │ │ └── unique_event_list.hpp │ │ │ │ │ ├── queue_thread/ │ │ │ │ │ │ └── queue_thread.hpp │ │ │ │ │ ├── staging_queue/ │ │ │ │ │ │ ├── staging_queue.hpp │ │ │ │ │ │ └── staging_queue_iterator.hpp │ │ │ │ │ ├── suballocators/ │ │ │ │ │ │ ├── first_fit_allocator.hpp │ │ │ │ │ │ └── first_fit_allocator_base.hpp │ │ │ │ │ ├── timed_job_list/ │ │ │ │ │ │ └── timed_job_list.hpp │ │ │ │ │ ├── utils/ │ │ │ │ │ │ └── time.hpp │ │ │ │ │ └── video_buffer/ │ │ │ │ │ └── allocator.hpp │ │ │ │ ├── graph_driver.hpp │ │ │ │ ├── graph_driver_worker_common.hpp │ │ │ │ ├── graph_worker.hpp │ │ │ │ ├── greedy_scheduler.hpp │ │ │ │ ├── ipc_client.hpp │ │ │ │ ├── ipc_server.hpp │ │ │ │ ├── memory_buffer.hpp │ │ │ │ ├── metric.hpp │ │ │ │ ├── monitor.hpp │ │ │ │ ├── multi_thread_scheduler.hpp │ │ │ │ ├── network_context.hpp │ │ │ │ ├── new_component_allocator.hpp │ │ │ │ ├── queue.hpp │ │ │ │ ├── receiver.hpp │ │ │ │ ├── resources.hpp │ │ │ │ ├── scheduler.hpp │ │ │ │ ├── scheduling_condition.hpp │ │ │ │ ├── scheduling_term.hpp │ │ │ │ ├── scheduling_term_combiner.hpp │ │ │ │ ├── scheduling_terms.hpp │ │ │ │ ├── system.hpp │ │ │ │ ├── tensor.hpp │ │ │ │ ├── timestamp.hpp │ │ │ │ ├── topic.hpp │ │ │ │ ├── transmitter.hpp │ │ │ │ ├── unbounded_allocator.hpp │ │ │ │ ├── vault.hpp │ │ │ │ └── yaml_file_loader.hpp │ │ │ ├── stream/ │ │ │ │ ├── stream_nvsci.hpp │ │ │ │ ├── stream_nvscisync.hpp │ │ │ │ ├── stream_sync_id.hpp │ │ │ │ └── tests/ │ │ │ │ └── test_gxf_stream_sync_cuda_helper.hpp │ │ │ └── ucx/ │ │ │ ├── ucx_common.hpp │ │ │ ├── ucx_component_serializer.hpp │ │ │ ├── ucx_context.hpp │ │ │ ├── ucx_entity_serializer.hpp │ │ │ ├── ucx_receiver.hpp │ │ │ ├── ucx_serialization_buffer.hpp │ │ │ └── ucx_transmitter.hpp │ │ └── third_party/ │ │ └── LICENSE.txt │ ├── package.xml │ └── src/ │ └── isaac_ros_gxf.cpp ├── isaac_ros_gxf_extensions/ │ ├── gxf_isaac_argus/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_atlas/ │ │ ├── CMakeLists.txt │ │ ├── gxf/ │ │ │ └── extensions/ │ │ │ └── atlas/ │ │ │ ├── composite_schema_server.hpp │ │ │ └── pose_tree_frame.hpp │ │ └── package.xml │ ├── gxf_isaac_camera_utils/ │ │ ├── CMakeLists.txt │ │ ├── gxf/ │ │ │ └── extensions/ │ │ │ └── camera_utils/ │ │ │ ├── camera_info_synchronizer.cpp │ │ │ ├── camera_info_synchronizer.hpp │ │ │ ├── camera_utils.cpp │ │ │ ├── stereo_camera_synchronizer.cpp │ │ │ └── stereo_camera_synchronizer.hpp │ │ └── package.xml │ ├── gxf_isaac_cuda/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_flatscan_localization/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_gems/ │ │ ├── CMakeLists.txt │ │ ├── gxf/ │ │ │ ├── gems/ │ │ │ │ ├── algorithm/ │ │ │ │ │ └── string_utils.hpp │ │ │ │ ├── common/ │ │ │ │ │ ├── composite_schema_uid.hpp │ │ │ │ │ └── pose_frame_uid.hpp │ │ │ │ ├── composite/ │ │ │ │ │ ├── composite_from_tensor.hpp │ │ │ │ │ ├── composite_view.hpp │ │ │ │ │ ├── measure.hpp │ │ │ │ │ ├── quantity.hpp │ │ │ │ │ ├── schema.hpp │ │ │ │ │ └── schema_tensor_archive.hpp │ │ │ │ ├── coms/ │ │ │ │ │ └── socket.hpp │ │ │ │ ├── control_types/ │ │ │ │ │ └── differential_drive.hpp │ │ │ │ ├── core/ │ │ │ │ │ ├── allocator/ │ │ │ │ │ │ ├── allocator_base.hpp │ │ │ │ │ │ └── allocators.hpp │ │ │ │ │ ├── assert.hpp │ │ │ │ │ ├── buffers/ │ │ │ │ │ │ ├── algorithm.hpp │ │ │ │ │ │ ├── buffer.hpp │ │ │ │ │ │ └── traits.hpp │ │ │ │ │ ├── byte.hpp │ │ │ │ │ ├── constants.hpp │ │ │ │ │ ├── epsilon.hpp │ │ │ │ │ ├── image/ │ │ │ │ │ │ └── image.hpp │ │ │ │ │ ├── logger.hpp │ │ │ │ │ ├── math/ │ │ │ │ │ │ ├── macros.hpp │ │ │ │ │ │ ├── pose2.hpp │ │ │ │ │ │ ├── pose3.hpp │ │ │ │ │ │ ├── so2.hpp │ │ │ │ │ │ ├── so3.hpp │ │ │ │ │ │ ├── types.hpp │ │ │ │ │ │ └── utils.hpp │ │ │ │ │ ├── optional.hpp │ │ │ │ │ └── tensor/ │ │ │ │ │ ├── sample_cloud.hpp │ │ │ │ │ └── tensor.hpp │ │ │ │ ├── cuda_utils/ │ │ │ │ │ ├── launch_utils.hpp │ │ │ │ │ ├── stride_pointer.hpp │ │ │ │ │ ├── stride_pointer_3d.hpp │ │ │ │ │ └── vector_math.hpp │ │ │ │ ├── flatscan/ │ │ │ │ │ ├── flatscan_info.hpp │ │ │ │ │ └── flatscan_types.hpp │ │ │ │ ├── geometry/ │ │ │ │ │ ├── line.hpp │ │ │ │ │ ├── line_segment.hpp │ │ │ │ │ ├── line_utils.hpp │ │ │ │ │ ├── n_cuboid.hpp │ │ │ │ │ ├── n_sphere.hpp │ │ │ │ │ ├── pinhole.hpp │ │ │ │ │ ├── plane.hpp │ │ │ │ │ ├── polygon.hpp │ │ │ │ │ ├── polyline.hpp │ │ │ │ │ └── types.hpp │ │ │ │ ├── gxf_helpers/ │ │ │ │ │ ├── expected_macro_abstract.hpp │ │ │ │ │ ├── expected_macro_common.hpp │ │ │ │ │ ├── expected_macro_cuda.hpp │ │ │ │ │ ├── expected_macro_gxf.hpp │ │ │ │ │ ├── expected_macro_isaac.hpp │ │ │ │ │ └── image_view.hpp │ │ │ │ ├── image/ │ │ │ │ │ ├── color.hpp │ │ │ │ │ ├── io.hpp │ │ │ │ │ └── utils.hpp │ │ │ │ ├── pose_tree/ │ │ │ │ │ ├── pose_tree.hpp │ │ │ │ │ └── pose_tree_edge_history.hpp │ │ │ │ ├── serialization/ │ │ │ │ │ ├── base64.hpp │ │ │ │ │ ├── json.hpp │ │ │ │ │ └── json_formatter.hpp │ │ │ │ ├── sight/ │ │ │ │ │ ├── sop.hpp │ │ │ │ │ ├── sop_asset.hpp │ │ │ │ │ ├── sop_image.hpp │ │ │ │ │ ├── sop_mesh.hpp │ │ │ │ │ ├── sop_point_cloud.hpp │ │ │ │ │ ├── sop_style.hpp │ │ │ │ │ ├── sop_text.hpp │ │ │ │ │ └── sop_transform.hpp │ │ │ │ ├── uuid/ │ │ │ │ │ └── uuid.hpp │ │ │ │ └── video_buffer/ │ │ │ │ └── allocator.hpp │ │ │ └── third_party/ │ │ │ └── nlohmann/ │ │ │ └── json.hpp │ │ └── package.xml │ ├── gxf_isaac_gxf_helpers/ │ │ ├── CMakeLists.txt │ │ ├── gxf/ │ │ │ └── extensions/ │ │ │ └── gxf_helpers/ │ │ │ ├── parameter_parser_isaac.hpp │ │ │ ├── parameter_wrapper_isaac.hpp │ │ │ └── string_provider.hpp │ │ └── package.xml │ ├── gxf_isaac_hesai/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_localization/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_message_compositor/ │ │ ├── CMakeLists.txt │ │ ├── gxf/ │ │ │ └── message_compositor/ │ │ │ └── message_relay.hpp │ │ └── package.xml │ ├── gxf_isaac_messages/ │ │ ├── CMakeLists.txt │ │ ├── gxf/ │ │ │ └── extensions/ │ │ │ └── messages/ │ │ │ ├── accelerometer_message.hpp │ │ │ ├── battery_state_message.hpp │ │ │ ├── camera_message.hpp │ │ │ ├── composite_message.hpp │ │ │ ├── correlated_timestamp_message.hpp │ │ │ ├── encoder_tick_message.hpp │ │ │ ├── flatscan_message.hpp │ │ │ ├── gyroscope_message.hpp │ │ │ ├── helpers.hpp │ │ │ ├── imu_message.hpp │ │ │ ├── json_message.hpp │ │ │ └── pose3d_cov_message.hpp │ │ └── package.xml │ ├── gxf_isaac_messages_throttler/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_optimizer/ │ │ ├── CMakeLists.txt │ │ ├── gxf/ │ │ │ └── extensions/ │ │ │ └── gxf_optimizer/ │ │ │ ├── common/ │ │ │ │ └── type.hpp │ │ │ ├── core/ │ │ │ │ └── optimizer.hpp │ │ │ └── exporter/ │ │ │ └── graph_types.hpp │ │ └── package.xml │ ├── gxf_isaac_point_cloud/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_range_scan_processing/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_ros_cuda/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_ros_messages/ │ │ ├── CMakeLists.txt │ │ ├── gxf/ │ │ │ └── messages/ │ │ │ ├── flat_scan_message.hpp │ │ │ └── point_cloud_message.hpp │ │ └── package.xml │ ├── gxf_isaac_segway/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_sight/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ ├── gxf_isaac_timestamp_correlator/ │ │ ├── CMakeLists.txt │ │ └── package.xml │ └── gxf_isaac_utils/ │ ├── CMakeLists.txt │ ├── gxf/ │ │ └── extensions/ │ │ └── utils/ │ │ ├── disparity_to_depth.cpp │ │ ├── disparity_to_depth.cu.cpp │ │ ├── disparity_to_depth.cu.hpp │ │ ├── disparity_to_depth.hpp │ │ ├── image_loader.cpp │ │ ├── image_loader.hpp │ │ ├── udp_receiver.cpp │ │ ├── udp_receiver.hpp │ │ └── utils.cpp │ └── package.xml ├── isaac_ros_managed_nitros/ │ ├── CMakeLists.txt │ ├── include/ │ │ └── isaac_ros_managed_nitros/ │ │ ├── managed_nitros_message_filters_subscriber.hpp │ │ ├── managed_nitros_publisher.hpp │ │ └── managed_nitros_subscriber.hpp │ └── package.xml ├── isaac_ros_managed_nitros_examples/ │ ├── custom_nitros_dnn_image_encoder/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── custom_nitros_dnn_image_encoder/ │ │ │ └── image_encoder_node.hpp │ │ ├── launch/ │ │ │ └── custom_image_isaac_ros_dope_tensor_rt.launch.py │ │ ├── package.xml │ │ ├── src/ │ │ │ └── image_encoder_node.cpp │ │ └── test/ │ │ ├── custom_nitros_dnn_image_encoder_pol.py │ │ └── test_cases/ │ │ └── profile_image/ │ │ └── image.json │ ├── custom_nitros_image/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── custom_nitros_image/ │ │ │ ├── gpu_image_builder_node.hpp │ │ │ ├── gpu_image_viewer_node.hpp │ │ │ └── nitros_image_switch_node.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── gpu_image_builder_node.cpp │ │ │ ├── gpu_image_viewer_node.cpp │ │ │ └── nitros_image_switch_node.cpp │ │ └── test/ │ │ ├── custom_nitros_image_builder_pol.py │ │ ├── custom_nitros_image_pol.py │ │ ├── custom_nitros_image_viewer_pol.py │ │ ├── test_cases/ │ │ │ └── profile_image/ │ │ │ └── image.json │ │ └── test_nitros_image_switch_pol.py │ ├── custom_nitros_message_filter/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── custom_nitros_message_filter/ │ │ │ └── synchronizer_node.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── synchronizer_node.cpp │ │ └── test/ │ │ ├── custom_nitros_message_filter_pol.py │ │ └── test_cases/ │ │ └── profile_image/ │ │ ├── camera_info.json │ │ └── image.json │ ├── custom_nitros_message_filter_interfaces/ │ │ ├── CMakeLists.txt │ │ ├── msg/ │ │ │ └── SyncStatus.msg │ │ └── package.xml │ └── custom_nitros_string/ │ ├── CMakeLists.txt │ ├── include/ │ │ └── custom_nitros_string/ │ │ ├── string_decoder_node.hpp │ │ └── string_encoder_node.hpp │ ├── package.xml │ ├── src/ │ │ ├── string_decoder_node.cpp │ │ └── string_encoder_node.cpp │ └── test/ │ ├── custom_nitros_string_decoder_pol.py │ ├── custom_nitros_string_encoder_pol.py │ └── custom_nitros_string_pol.py ├── isaac_ros_nitros/ │ ├── CMakeLists.txt │ ├── config/ │ │ └── type_adapter_nitros_context_graph.yaml │ ├── include/ │ │ └── isaac_ros_nitros/ │ │ ├── nitros_context.hpp │ │ ├── nitros_node.hpp │ │ ├── nitros_publisher.hpp │ │ ├── nitros_publisher_subscriber_base.hpp │ │ ├── nitros_publisher_subscriber_group.hpp │ │ ├── nitros_subscriber.hpp │ │ └── types/ │ │ ├── nitros_empty.hpp │ │ ├── nitros_format_agent.hpp │ │ ├── nitros_type_base.hpp │ │ ├── nitros_type_manager.hpp │ │ ├── nitros_type_message_filter_traits.hpp │ │ ├── nitros_type_view_factory.hpp │ │ ├── type_adapter_nitros_context.hpp │ │ └── type_utility.hpp │ ├── lib/ │ │ ├── AMENT_IGNORE │ │ ├── cuapriltags/ │ │ │ ├── cuapriltags/ │ │ │ │ └── cuAprilTags.h │ │ │ ├── lib_aarch64_jetpack51/ │ │ │ │ └── libcuapriltags.a │ │ │ ├── lib_aarch64_jetpack61/ │ │ │ │ └── libcuapriltags.a │ │ │ └── lib_x86_64_cuda_12_6/ │ │ │ └── libcuapriltags.a │ │ ├── cumotion/ │ │ │ ├── .gitattributes │ │ │ ├── aarch64_jetpack70/ │ │ │ │ ├── LICENSE │ │ │ │ ├── NOTICE │ │ │ │ ├── include/ │ │ │ │ │ └── cumotion/ │ │ │ │ │ ├── collision_free_ik_solver.h │ │ │ │ │ ├── collision_sphere_generator.h │ │ │ │ │ ├── composite_path_spec.h │ │ │ │ │ ├── cspace_path.h │ │ │ │ │ ├── cspace_path_spec.h │ │ │ │ │ ├── cumotion.h │ │ │ │ │ ├── cumotion_export.h │ │ │ │ │ ├── ik_solver.h │ │ │ │ │ ├── kinematics.h │ │ │ │ │ ├── linear_cspace_path.h │ │ │ │ │ ├── motion_planner.h │ │ │ │ │ ├── obstacle.h │ │ │ │ │ ├── path_conversion.h │ │ │ │ │ ├── path_spec_yaml.h │ │ │ │ │ ├── pose3.h │ │ │ │ │ ├── rmpflow.h │ │ │ │ │ ├── robot_description.h │ │ │ │ │ ├── robot_segmenter.h │ │ │ │ │ ├── robot_world_inspector.h │ │ │ │ │ ├── rotation3.h │ │ │ │ │ ├── task_space_path.h │ │ │ │ │ ├── task_space_path_spec.h │ │ │ │ │ ├── text_style.h │ │ │ │ │ ├── trajectory.h │ │ │ │ │ ├── trajectory_generator.h │ │ │ │ │ ├── trajectory_optimizer.h │ │ │ │ │ ├── version.h │ │ │ │ │ ├── vision.h │ │ │ │ │ ├── world.h │ │ │ │ │ └── world_inspector.h │ │ │ │ ├── lib/ │ │ │ │ │ ├── cmake/ │ │ │ │ │ │ └── cumotion/ │ │ │ │ │ │ ├── cumotionConfig.cmake │ │ │ │ │ │ ├── cumotionConfigVersion.cmake │ │ │ │ │ │ ├── cumotionTargets-release.cmake │ │ │ │ │ │ └── cumotionTargets.cmake │ │ │ │ │ └── libcumotion.so.1.1.0 │ │ │ │ └── python_wheels/ │ │ │ │ ├── cumotion-1.1.0-cp312-cp312-linux_aarch64.whl │ │ │ │ └── cumotion_vis-1.1.0-py3-none-any.whl │ │ │ └── x86_64_cuda_13_0/ │ │ │ ├── LICENSE │ │ │ ├── NOTICE │ │ │ ├── include/ │ │ │ │ └── cumotion/ │ │ │ │ ├── collision_free_ik_solver.h │ │ │ │ ├── collision_sphere_generator.h │ │ │ │ ├── composite_path_spec.h │ │ │ │ ├── cspace_path.h │ │ │ │ ├── cspace_path_spec.h │ │ │ │ ├── cumotion.h │ │ │ │ ├── cumotion_export.h │ │ │ │ ├── ik_solver.h │ │ │ │ ├── kinematics.h │ │ │ │ ├── linear_cspace_path.h │ │ │ │ ├── motion_planner.h │ │ │ │ ├── obstacle.h │ │ │ │ ├── path_conversion.h │ │ │ │ ├── path_spec_yaml.h │ │ │ │ ├── pose3.h │ │ │ │ ├── rmpflow.h │ │ │ │ ├── robot_description.h │ │ │ │ ├── robot_segmenter.h │ │ │ │ ├── robot_world_inspector.h │ │ │ │ ├── rotation3.h │ │ │ │ ├── task_space_path.h │ │ │ │ ├── task_space_path_spec.h │ │ │ │ ├── text_style.h │ │ │ │ ├── trajectory.h │ │ │ │ ├── trajectory_generator.h │ │ │ │ ├── trajectory_optimizer.h │ │ │ │ ├── version.h │ │ │ │ ├── vision.h │ │ │ │ ├── world.h │ │ │ │ └── world_inspector.h │ │ │ ├── lib/ │ │ │ │ ├── cmake/ │ │ │ │ │ └── cumotion/ │ │ │ │ │ ├── cumotionConfig.cmake │ │ │ │ │ ├── cumotionConfigVersion.cmake │ │ │ │ │ ├── cumotionTargets-release.cmake │ │ │ │ │ └── cumotionTargets.cmake │ │ │ │ └── libcumotion.so.1.1.0 │ │ │ └── python_wheels/ │ │ │ ├── cumotion-1.1.0-cp312-cp312-linux_x86_64.whl │ │ │ └── cumotion_vis-1.1.0-py3-none-any.whl │ │ └── cuvslam/ │ │ ├── .gitattributes │ │ ├── include/ │ │ │ └── cuvslam/ │ │ │ ├── cuvslam.h │ │ │ ├── cuvslam2.h │ │ │ ├── ground_constraint.h │ │ │ └── ground_constraint2.h │ │ ├── lib_aarch64_jetpack61/ │ │ │ └── cuvslam_api_launcher │ │ ├── lib_aarch64_jetpack70/ │ │ │ └── cuvslam_api_launcher │ │ ├── lib_x86_64_cuda_12_6/ │ │ │ └── cuvslam_api_launcher │ │ └── lib_x86_64_cuda_13_0/ │ │ └── cuvslam_api_launcher │ ├── package.xml │ ├── scripts/ │ │ └── diagnostic_viewer.py │ ├── src/ │ │ ├── nitros_context.cpp │ │ ├── nitros_node.cpp │ │ ├── nitros_publisher.cpp │ │ ├── nitros_publisher_subscriber_group.cpp │ │ ├── nitros_subscriber.cpp │ │ └── types/ │ │ ├── nitros_empty.cpp │ │ ├── nitros_type_base.cpp │ │ └── type_adapter_nitros_context.cpp │ └── test/ │ ├── config/ │ │ └── test_forward_node.yaml │ ├── isaac_ros_nitros_diagnostics_test_pol.py │ ├── isaac_ros_nitros_multi_node_test_pol.py │ ├── isaac_ros_nitros_test_pol.py │ ├── src/ │ │ └── nitros_empty_forward_node.cpp │ └── test_cases/ │ └── nitros_image/ │ └── profile/ │ ├── april_tag_detection_array.json │ ├── camera_info.json │ ├── image.json │ └── ketchup.pcd ├── isaac_ros_nitros_bridge/ │ ├── .gitattributes │ ├── .gitignore │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── config/ │ │ ├── nitros_bridge_convert_forward.yaml │ │ ├── nitros_bridge_forward.yaml │ │ └── nitros_bridge_image_converter.yaml │ ├── isaac_ros_nitros_bridge_ros2/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_bridge_ros2/ │ │ │ ├── image_converter_node.hpp │ │ │ ├── ipc_buffer_manager.hpp │ │ │ └── tensor_list_converter_node.hpp │ │ ├── launch/ │ │ │ ├── isaac_ros_nitros_bridge_image_converter.launch.py │ │ │ ├── isaac_ros_nitros_bridge_quickstart.launch.py │ │ │ └── isaac_ros_nitros_bridge_tensor_list_converter.launch.py │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── image_converter_node.cpp │ │ │ └── tensor_list_converter_node.cpp │ │ └── test/ │ │ ├── isaac_ros_nitros_bridge_image_pol.py │ │ ├── isaac_ros_nitros_bridge_tensor_list_pol.py │ │ └── test_cases/ │ │ └── nitros_image/ │ │ └── profile/ │ │ └── image.json │ ├── resources/ │ │ ├── quickstart.bag/ │ │ │ ├── metadata.yaml │ │ │ ├── quickstart.bag_0.db3 │ │ │ └── quickstart.bag_0.db3.zstd │ │ └── unet_sample_data_ros1.bag │ └── scripts/ │ └── workspace-entrypoint.sh ├── isaac_ros_nitros_topic_tools/ │ ├── CMakeLists.txt │ ├── include/ │ │ └── isaac_ros_nitros_topic_tools/ │ │ ├── isaac_ros_nitros_camera_drop_node.hpp │ │ └── isaac_ros_nitros_topic_tools_common.hpp │ ├── launch/ │ │ └── isaac_ros_nitros_camera_drop.launch.py │ ├── package.xml │ ├── src/ │ │ └── isaac_ros_nitros_camera_drop_node.cpp │ └── test/ │ ├── isaac_ros_nitros_topic_tools_camera_drop_node_mode_0_test.py │ ├── isaac_ros_nitros_topic_tools_camera_drop_node_mode_1_test.py │ └── isaac_ros_nitros_topic_tools_camera_drop_node_mode_2_test.py ├── isaac_ros_nitros_type/ │ ├── isaac_ros_nitros_battery_state_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_battery_state_type/ │ │ │ └── nitros_battery_state.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_battery_state.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_battery_state_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_battery_state_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_battery_state/ │ │ └── profile/ │ │ └── battery_state.json │ ├── isaac_ros_nitros_camera_info_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_camera_info_type/ │ │ │ ├── nitros_camera_info.hpp │ │ │ └── nitros_camera_info_view.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── nitros_camera_info.cpp │ │ │ └── nitros_camera_info_view.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_camera_info_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_camera_info_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_camera_info/ │ │ └── profile/ │ │ └── camera_info.json │ ├── isaac_ros_nitros_compressed_image_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_compressed_image_type/ │ │ │ └── nitros_compressed_image.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_compressed_image.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_compressed_image_type_test_pol.py │ │ └── src/ │ │ └── nitros_compressed_image_forward_node.cpp │ ├── isaac_ros_nitros_compressed_video_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_compressed_video_type/ │ │ │ └── nitros_compressed_video.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_compressed_video.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_compressed_video_type_test_pol.py │ │ └── src/ │ │ └── nitros_compressed_video_forward_node.cpp │ ├── isaac_ros_nitros_correlated_timestamp_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_correlated_timestamp_type/ │ │ │ └── nitros_correlated_timestamp.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_correlated_timestamp.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_correlated_timestamp_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_correlated_timestamp_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_correlated_timestamp/ │ │ └── profile/ │ │ └── correlated_timestamp.json │ ├── isaac_ros_nitros_detection2_d_array_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ ├── detectnet/ │ │ │ │ ├── detection2_d.hpp │ │ │ │ └── detection2_d_array_message.hpp │ │ │ └── isaac_ros_nitros_detection2_d_array_type/ │ │ │ └── nitros_detection2_d_array.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── detection2_d_array_message.cpp │ │ │ └── nitros_detection2_d_array.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_detection2_d_array_type_test_pol.py │ │ ├── src/ │ │ │ ├── detection2_d_test_ext.cpp │ │ │ └── nitros_detection2_d_array_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_detection2_d_array/ │ │ └── profile/ │ │ └── nitros_detection2_d_array.json │ ├── isaac_ros_nitros_detection3_d_array_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ ├── detection3_d_array_message/ │ │ │ │ └── detection3_d_array_message.hpp │ │ │ └── isaac_ros_nitros_detection3_d_array_type/ │ │ │ └── nitros_detection3_d_array.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── detection3_d_array_message.cpp │ │ │ └── nitros_detection3_d_array.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_detection3_d_array_type_test_pol.py │ │ ├── src/ │ │ │ ├── detection3_d_test_ext.cpp │ │ │ └── nitros_detection3_d_array_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_detection3_d_array/ │ │ └── profile/ │ │ └── nitros_detection3_d_array.json │ ├── isaac_ros_nitros_disparity_image_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_disparity_image_type/ │ │ │ ├── nitros_disparity_image.hpp │ │ │ └── nitros_disparity_image_builder.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── nitros_disparity_image.cpp │ │ │ └── nitros_disparity_image_builder.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_disparity_image_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_disparity_image_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_disparity_image/ │ │ └── profile/ │ │ └── image.json │ ├── isaac_ros_nitros_encoder_ticks_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_encoder_ticks_type/ │ │ │ └── nitros_encoder_ticks.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_encoder_ticks.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_encoder_ticks_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_encoder_ticks_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_encoder_ticks/ │ │ └── profile/ │ │ └── encoder_ticks.json │ ├── isaac_ros_nitros_flat_scan_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_flat_scan_type/ │ │ │ └── nitros_flat_scan.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_flat_scan.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_flat_scan_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_flat_scan_forward_node.cpp │ │ └── test_cases/ │ │ └── profile/ │ │ └── flat_scan.json │ ├── isaac_ros_nitros_image_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_image_type/ │ │ │ ├── nitros_image.hpp │ │ │ ├── nitros_image_builder.hpp │ │ │ ├── nitros_image_details.hpp │ │ │ └── nitros_image_view.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── nitros_image.cpp │ │ │ ├── nitros_image_builder.cpp │ │ │ └── nitros_image_view.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_image_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_image_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_image/ │ │ └── profile/ │ │ └── image.json │ ├── isaac_ros_nitros_imu_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_imu_type/ │ │ │ └── nitros_imu.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_imu.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_imu_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_imu_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_imu/ │ │ └── profile/ │ │ └── imu.json │ ├── isaac_ros_nitros_occupancy_grid_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_occupancy_grid_type/ │ │ │ └── nitros_occupancy_grid.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_occupancy_grid.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_occupancy_grid_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_occupancy_grid_forward_node.cpp │ │ └── test_cases/ │ │ └── profile/ │ │ └── occupancy_grid.json │ ├── isaac_ros_nitros_odometry_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_odometry_type/ │ │ │ └── nitros_odometry.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_odometry.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_odometry_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_odometry_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_odometry/ │ │ └── profile/ │ │ └── odometry.json │ ├── isaac_ros_nitros_point_cloud_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_point_cloud_type/ │ │ │ ├── nitros_point_cloud.hpp │ │ │ ├── nitros_point_cloud_builder.hpp │ │ │ └── nitros_point_cloud_view.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── nitros_point_cloud.cpp │ │ │ ├── nitros_point_cloud_builder.cpp │ │ │ └── nitros_point_cloud_view.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_managed_nitros_point_cloud_type_test_pol.py │ │ ├── isaac_ros_nitros_point_cloud_type_test_pol.py │ │ ├── managed_nitros_point_cloud_forward_node.cpp │ │ ├── src/ │ │ │ └── nitros_point_cloud_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_point_cloud/ │ │ └── profile/ │ │ └── ketchup.pcd │ ├── isaac_ros_nitros_pose_array_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_pose_array_type/ │ │ │ └── nitros_pose_array.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_pose_array.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_pose_array_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_pose_array_forward_node.cpp │ │ └── test_cases/ │ │ └── profile/ │ │ └── pose_array.json │ ├── isaac_ros_nitros_pose_cov_stamped_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_pose_cov_stamped_type/ │ │ │ └── nitros_pose_cov_stamped.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_pose_cov_stamped.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_pose_cov_stamped_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_pose_cov_stamped_forward_node.cpp │ │ └── test_cases/ │ │ └── nitros_pose_cov_stamped/ │ │ └── profile/ │ │ └── pose_cov_stamped.json │ ├── isaac_ros_nitros_std_msg_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_std_msg_type/ │ │ │ └── nitros_int64.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ └── nitros_int64.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_int64_type_test_pol.py │ │ ├── src/ │ │ │ └── nitros_int64_forward_node.cpp │ │ └── test_cases/ │ │ └── profile/ │ │ └── pose_array.json │ ├── isaac_ros_nitros_tensor_list_type/ │ │ ├── CMakeLists.txt │ │ ├── include/ │ │ │ └── isaac_ros_nitros_tensor_list_type/ │ │ │ ├── nitros_data_type.hpp │ │ │ ├── nitros_tensor.hpp │ │ │ ├── nitros_tensor_builder.hpp │ │ │ ├── nitros_tensor_list.hpp │ │ │ ├── nitros_tensor_list_builder.hpp │ │ │ ├── nitros_tensor_list_view.hpp │ │ │ └── nitros_tensor_shape.hpp │ │ ├── package.xml │ │ ├── src/ │ │ │ ├── nitros_data_type.cpp │ │ │ ├── nitros_tensor_builder.cpp │ │ │ ├── nitros_tensor_list.cpp │ │ │ ├── nitros_tensor_list_builder.cpp │ │ │ └── nitros_tensor_list_view.cpp │ │ └── test/ │ │ ├── config/ │ │ │ └── test_forward_node.yaml │ │ ├── isaac_ros_nitros_tensor_list_type_test_pol.py │ │ └── src/ │ │ └── nitros_tensor_list_forward_node.cpp │ └── isaac_ros_nitros_twist_type/ │ ├── .vscode/ │ │ └── settings.json │ ├── CMakeLists.txt │ ├── include/ │ │ └── isaac_ros_nitros_twist_type/ │ │ └── nitros_twist.hpp │ ├── package.xml │ ├── src/ │ │ └── nitros_twist.cpp │ └── test/ │ ├── config/ │ │ └── test_forward_node.yaml │ ├── isaac_ros_nitros_twist_type_test_pol.py │ ├── src/ │ │ └── nitros_twist_forward_node.cpp │ └── test_cases/ │ └── nitros_twist/ │ └── profile/ │ └── twist.json └── isaac_ros_pynitros/ ├── isaac_ros_pynitros/ │ ├── __init__.py │ ├── examples/ │ │ ├── __init__.py │ │ ├── pynitros_dnn_image_encoder_node.py │ │ ├── pynitros_image_forward_node.py │ │ ├── pynitros_message_filter_sync_node.py │ │ ├── pynitros_point_cloud_forward_node.py │ │ └── pynitros_tensor_list_forward_node.py │ ├── isaac_ros_pynitros_message_filter.py │ ├── isaac_ros_pynitros_publisher.py │ ├── isaac_ros_pynitros_subscriber.py │ ├── pynitros_type_builders/ │ │ ├── __init__.py │ │ ├── pynitros_image_builder.py │ │ ├── pynitros_point_cloud_builder.py │ │ ├── pynitros_tensor_list_builder.py │ │ └── pynitros_type_builder_base.py │ ├── pynitros_type_views/ │ │ ├── __init__.py │ │ ├── pynitros_image_view.py │ │ ├── pynitros_point_cloud_view.py │ │ ├── pynitros_tensor_list_view.py │ │ └── pynitros_type_view_base.py │ └── utils/ │ ├── __init__.py │ ├── cpu_shared_mem.py │ └── tensor_data_type.py ├── launch/ │ ├── isaac_ros_pynitros_dnn_image_encoder.launch.py │ ├── isaac_ros_pynitros_quickstart.launch.py │ └── isaac_ros_pynitros_to_nitros.launch.py ├── package.xml ├── resource/ │ └── isaac_ros_pynitros ├── setup.cfg ├── setup.py └── test/ ├── isaac_ros_pynitros_dnn_image_encoder.py ├── isaac_ros_pynitros_image_test.py ├── isaac_ros_pynitros_point_cloud_test.py ├── isaac_ros_pynitros_sync_test.py ├── isaac_ros_pynitros_tensor_list_test.py ├── test_cases/ │ ├── nitros_image/ │ │ └── profile/ │ │ └── image.json │ └── nitros_point_cloud/ │ └── test_data/ │ └── ketchup.pcd ├── test_copyright.py ├── test_flake8.py └── test_pep257.py ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ # Ignore Python files in linguist *.py linguist-detectable=false # Images *.gif filter=lfs diff=lfs merge=lfs -text *.jpg filter=lfs diff=lfs merge=lfs -text *.png filter=lfs diff=lfs merge=lfs -text *.psd filter=lfs diff=lfs merge=lfs -text # Archives *.gz filter=lfs diff=lfs merge=lfs -text *.tar filter=lfs diff=lfs merge=lfs -text *.zip filter=lfs diff=lfs merge=lfs -text # Documents *.pdf filter=lfs diff=lfs merge=lfs -text # Numpy data *.npy filter=lfs diff=lfs merge=lfs -text # Debian package *.deb filter=lfs diff=lfs merge=lfs -text # Shared libraries *.so.* filter=lfs diff=lfs merge=lfs -text *.so filter=lfs diff=lfs merge=lfs -text *.a filter=lfs diff=lfs merge=lfs -text # trtexec trtexec_x86_64 filter=lfs diff=lfs merge=lfs -text ================================================ FILE: .gitignore ================================================ # Ignore all pycache files **/__pycache__/** # Ignore ROS build files **/build/** **/install/** **/cc_internals/** **/log/** ================================================ FILE: LICENSE ================================================ NVIDIA ISAAC ROS SOFTWARE LICENSE This license is a legal agreement between you and NVIDIA Corporation ("NVIDIA") and governs the use of the NVIDIA Isaac ROS software and materials provided hereunder (“SOFTWARE”). This license can be accepted only by an adult of legal age of majority in the country in which the SOFTWARE is used. If you are entering into this license on behalf of a company or other legal entity, you represent that you have the legal authority to bind the entity to this license, in which case “you” will mean the entity you represent. If you don’t have the required age or authority to accept this license, or if you don’t accept all the terms and conditions of this license, do not download, install or use the SOFTWARE. You agree to use the SOFTWARE only for purposes that are permitted by (a) this license, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions. 1. LICENSE. Subject to the terms of this license, NVIDIA hereby grants you a non-exclusive, non-transferable license, without the right to sublicense (except as expressly provided in this license) to: a. Install and use the SOFTWARE, b. Modify and create derivative works of sample or reference source code delivered in the SOFTWARE, and c. Distribute any part of the SOFTWARE (i) as incorporated into a software application that has material additional functionality beyond the included portions of the SOFTWARE, or (ii) unmodified in binary format, in each case subject to the distribution requirements indicated in this license. 2. DISTRIBUTION REQUIREMENTS. These are the distribution requirements for you to exercise the distribution grant above: a. The following notice shall be included in modifications and derivative works of source code distributed: “This software contains source code provided by NVIDIA Corporation.” b. You agree to distribute the SOFTWARE subject to the terms at least as protective as the terms of this license, including (without limitation) terms relating to the license grant, license restrictions and protection of NVIDIA’s intellectual property rights. Additionally, you agree that you will protect the privacy, security and legal rights of your application users. c. You agree to notify NVIDIA in writing of any known or suspected distribution or use of the SOFTWARE not in compliance with the requirements of this license, and to enforce the terms of your agreements with respect to the distributed portions of the SOFTWARE. 3. AUTHORIZED USERS. You may allow employees and contractors of your entity or of your subsidiary(ies) to access and use the SOFTWARE from your secure network to perform work on your behalf. If you are an academic institution you may allow users enrolled or employed by the academic institution to access and use the SOFTWARE from your secure network. You are responsible for the compliance with the terms of this license by your authorized users. 4. LIMITATIONS. Your license to use the SOFTWARE is restricted as follows: a. The SOFTWARE is licensed for you to develop applications only for their use in systems with NVIDIA GPUs. b. You may not reverse engineer, decompile or disassemble, or remove copyright or other proprietary notices from any portion of the SOFTWARE or copies of the SOFTWARE. c. Except as expressly stated above in this license, you may not sell, rent, sublicense, transfer, distribute, modify, or create derivative works of any portion of the SOFTWARE. d. Unless you have an agreement with NVIDIA for this purpose, you may not indicate that an application created with the SOFTWARE is sponsored or endorsed by NVIDIA. e. You may not bypass, disable, or circumvent any technical limitation, encryption, security, digital rights management or authentication mechanism in the SOFTWARE. f. You may not use the SOFTWARE in any manner that would cause it to become subject to an open source software license. As examples, licenses that require as a condition of use, modification, and/or distribution that the SOFTWARE be: (i) disclosed or distributed in source code form; (ii) licensed for the purpose of making derivative works; or (iii) redistributable at no charge. g. You acknowledge that the SOFTWARE as delivered is not tested or certified by NVIDIA for use in connection with the design, construction, maintenance, and/or operation of any system where the use or failure of such system could result in a situation that threatens the safety of human life or results in catastrophic damages (each, a "Critical Application"). Examples of Critical Applications include use in avionics, navigation, autonomous vehicle applications, ai solutions for automotive products, military, medical, life support or other life critical applications. NVIDIA shall not be liable to you or any third party, in whole or in part, for any claims or damages arising from such uses. You are solely responsible for ensuring that any product or service developed with the SOFTWARE as a whole includes sufficient features to comply with all applicable legal and regulatory standards and requirements. h. You agree to defend, indemnify and hold harmless NVIDIA and its affiliates, and their respective employees, contractors, agents, officers and directors, from and against any and all claims, damages, obligations, losses, liabilities, costs or debt, fines, restitutions and expenses (including but not limited to attorney’s fees and costs incident to establishing the right of indemnification) arising out of or related to your use of goods and/or services that include or utilize the SOFTWARE, or for use of the SOFTWARE outside of the scope of this license or not in compliance with its terms. 5. UPDATES. NVIDIA may, at its option, make available patches, workarounds or other updates to this SOFTWARE. Unless the updates are provided with their separate governing terms, they are deemed part of the SOFTWARE licensed to you as provided in this license. 6. PRE-RELEASE VERSIONS. SOFTWARE versions identified as alpha, beta, preview, early access or otherwise as pre-release may not be fully functional, may contain errors or design flaws, and may have reduced or different security, privacy, availability, and reliability standards relative to commercial versions of NVIDIA software and materials. You may use a pre-release SOFTWARE version at your own risk, understanding that these versions are not intended for use in production or business-critical systems. 7. COMPONENTS UNDER OTHER LICENSES. The SOFTWARE may include NVIDIA or third-party components with separate legal notices or terms as may be described in proprietary notices accompanying the SOFTWARE, such as components governed by open source software licenses. If and to the extent there is a conflict between the terms in this license and the license terms associated with a component, the license terms associated with the component controls only to the extent necessary to resolve the conflict. 8. OWNERSHIP. 8.1 NVIDIA reserves all rights, title and interest in and to the SOFTWARE not expressly granted to you under this license. NVIDIA and its suppliers hold all rights, title and interest in and to the SOFTWARE, including their respective intellectual property rights. The SOFTWARE is copyrighted and protected by the laws of the United States and other countries, and international treaty provisions. 8.2 Subject to the rights of NVIDIA and its suppliers in the SOFTWARE, you hold all rights, title and interest in and to your applications and your derivative works of the sample or reference source code delivered in the SOFTWARE including their respective intellectual property rights. With respect to source code samples or reference source code licensed to you, NVIDIA and its affiliates are free to continue independently developing source code samples and you covenant not to sue NVIDIA, its affiliates or their licensees with respect to later versions of NVIDIA released source code. 9. FEEDBACK. You may, but are not obligated to, provide to NVIDIA Feedback. “Feedback” means suggestions, fixes, modifications, feature requests or other feedback regarding the SOFTWARE. Feedback, even if designated as confidential by you, shall not create any confidentiality obligation for NVIDIA. NVIDIA and its designees have a perpetual, non-exclusive, worldwide, irrevocable license to use, reproduce, publicly display, modify, create derivative works of, license, sublicense, and otherwise distribute and exploit Feedback as NVIDIA sees fit without payment and without obligation or restriction of any kind on account of intellectual property rights or otherwise. 10. NO WARRANTIES. THE SOFTWARE IS PROVIDED AS-IS. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW NVIDIA AND ITS AFFILIATES EXPRESSLY DISCLAIM ALL WARRANTIES OF ANY KIND OR NATURE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, NON-INFRINGEMENT, OR FITNESS FOR A PARTICULAR PURPOSE. NVIDIA DOES NOT WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS OR THAT THE OPERATION THEREOF WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ALL ERRORS WILL BE CORRECTED. 11. LIMITATIONS OF LIABILITY. TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW NVIDIA AND ITS AFFILIATES SHALL NOT BE LIABLE FOR ANY SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL DAMAGES, OR FOR ANY LOST PROFITS, PROJECT DELAYS, LOSS OF USE, LOSS OF DATA OR LOSS OF GOODWILL, OR THE COSTS OF PROCURING SUBSTITUTE PRODUCTS, ARISING OUT OF OR IN CONNECTION WITH THIS LICENSE OR THE USE OR PERFORMANCE OF THE SOFTWARE, WHETHER SUCH LIABILITY ARISES FROM ANY CLAIM BASED UPON BREACH OF CONTRACT, BREACH OF WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCT LIABILITY OR ANY OTHER CAUSE OF ACTION OR THEORY OF LIABILITY, EVEN IF NVIDIA HAS PREVIOUSLY BEEN ADVISED OF, OR COULD REASONABLY HAVE FORESEEN, THE POSSIBILITY OF SUCH DAMAGES. IN NO EVENT WILL NVIDIA’S AND ITS AFFILIATES TOTAL CUMULATIVE LIABILITY UNDER OR ARISING OUT OF THIS LICENSE EXCEED US$10.00. THE NATURE OF THE LIABILITY OR THE NUMBER OF CLAIMS OR SUITS SHALL NOT ENLARGE OR EXTEND THIS LIMIT. 12. TERMINATION. Your rights under this license will terminate automatically without notice from NVIDIA if you fail to comply with any term and condition of this license or if you commence or participate in any legal proceeding against NVIDIA with respect to the SOFTWARE. NVIDIA may terminate this license with advance written notice to you, if NVIDIA decides to no longer provide the SOFTWARE in a country or, in NVIDIA’s sole discretion, the continued use of it is no longer commercially viable. Upon any termination of this license, you agree to promptly discontinue use of the SOFTWARE and destroy all copies in your possession or control. Your prior distributions in accordance with this license are not affected by the termination of this license. All provisions of this license will survive termination, except for the license granted to you. 13. APPLICABLE LAW. This license will be governed in all respects by the laws of the United States and of the State of Delaware, without regard to the conflicts of laws principles. The United Nations Convention on Contracts for the International Sale of Goods is specifically disclaimed. You agree to all terms of this license in the English language. The state or federal courts residing in Santa Clara County, California shall have exclusive jurisdiction over any dispute or claim arising out of this license. Notwithstanding this, you agree that NVIDIA shall still be allowed to apply for injunctive remedies or urgent legal relief in any jurisdiction. 14. NO ASSIGNMENT. This license and your rights and obligations thereunder may not be assigned by you by any means or operation of law without NVIDIA’s permission. Any attempted assignment not approved by NVIDIA in writing shall be void and of no effect. NVIDIA may assign, delegate or transfer this license and its rights and obligations, and if to a non-affiliate you will be notified. 15. EXPORT. The SOFTWARE is subject to United States export laws and regulations. You agree to comply with all applicable U.S. and international export laws, including the Export Administration Regulations (EAR) administered by the U.S. Department of Commerce and economic sanctions administered by the U.S. Department of Treasury’s Office of Foreign Assets Control (OFAC). These laws include restrictions on destinations, end-users and end-use. By accepting this license, you confirm that you are not currently residing in a country or region currently embargoed by the U.S. and that you are not otherwise prohibited from receiving the SOFTWARE. 16. GOVERNMENT USE. The SOFTWARE is, and shall be treated as being, “Commercial Items” as that term is defined at 48 CFR § 2.101, consisting of “commercial computer software” and “commercial computer software documentation”, respectively, as such terms are used in, respectively, 48 CFR § 12.212 and 48 CFR §§ 227.7202 & 252.227-7014(a)(1). Use, duplication or disclosure by the U.S. Government or a U.S. Government subcontractor is subject to the restrictions in this license pursuant to 48 CFR § 12.212 or 48 CFR § 227.7202. In no event shall the US Government user acquire rights in the SOFTWARE beyond those specified in 48 C.F.R. 52.227-19(b)(1)-(2). 17. NOTICES. Please direct your legal notices or other correspondence to NVIDIA Corporation, 2788 San Tomas Expressway, Santa Clara, California 95051, United States of America, Attention: Legal Department. 18. ENTIRE AGREEMENT. This license is the final, complete and exclusive agreement between the parties relating to the subject matter of this license and supersedes all prior or contemporaneous understandings and agreements relating to this subject matter, whether oral or written. If any court of competent jurisdiction determines that any provision of this license is illegal, invalid or unenforceable, the remaining provisions will remain in full force and effect. Any amendment or waiver under this license shall be in writing and signed by representatives of both parties. (v. November 17, 2021) ================================================ FILE: README.md ================================================ # Isaac ROS NITROS NVIDIA Isaac Transport for ROS package for hardware-acceleration friendly movement of messages.
image
## Overview Isaac ROS NITROS contains NVIDIA’s implementation of type adaptation and negotiation in ROS 2. To learn more about NITROS, see [here](https://nvidia-isaac-ros.github.io/concepts/nitros/index.html). Isaac ROS NITROS is composed of a number of individual packages, each with either a functional or structural purpose: `isaac_ros_gxf`: : This package serves as a container for precompiled GXF extensions used by other Isaac ROS packages. While a number of GXF extensions used by Isaac ROS are provided with source, the extensions contained in `isaac_ros_gxf` are license constrained and are thus shipped as `.so` binaries. `isaac_ros_managed_nitros`: : This package contains the wrapper classes that enable developers to add NITROS-compatible publishers and subscribers to third-party CUDA-based ROS nodes. For more information about CUDA with NITROS, see [here](https://nvidia-isaac-ros.github.io/concepts/nitros/cuda_with_nitros.html). `isaac_ros_nitros`: : This package contains the base `NitrosNode` class and associated core utilities that serve as the foundation for all NITROS-based ROS nodes. `isaac_ros_nitros_bridge`: : This folder contains the implementation of the NITROS Bridge for inter-process communication. `isaac_ros_nitros_interfaces`: : This package contains the definitions of the custom ROS 2 interfaces that facilitate type negotiation between NITROS nodes. `isaac_ros_nitros_topic_tools`: : This folder contains a NITROS based implementation of some of the nodes in the [topic_tools package](https://github.com/ros-tooling/topic_tools). `isaac_ros_nitros_type`: : This folder contains a number of packages, each defining a specific NITROS type and the associated type adaptation logic to convert to and from a standard ROS type. `isaac_ros_pynitros`: : This folder contains the implementation of Python NITROS. --- ## Documentation Please visit the [Isaac ROS Documentation](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/index.html) to learn how to use this repository. --- ## Packages * [`isaac_ros_gxf`](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_gxf/index.html) * [`isaac_ros_managed_nitros`](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_managed_nitros/index.html) * [`isaac_ros_nitros`](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros/index.html) * [Quickstart](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros/index.html#quickstart) * [Isaac ROS NITROS Bridge](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/index.html) * [Overview](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/index.html#overview) * [Performance](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/index.html#performance) * [Packages](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/index.html#packages) * [Quickstart](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/index.html#quickstart) * [Try Another Example](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/index.html#try-another-example) * [Troubleshooting](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/index.html#troubleshooting) * [Updates](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/index.html#updates) * [`isaac_ros_nitros_bridge_ros2`](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/isaac_ros_nitros_bridge_ros2/index.html) * [API](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_bridge/isaac_ros_nitros_bridge_ros2/index.html#api) * [`isaac_ros_nitros_topic_tools`](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_topic_tools/index.html) * [NitrosCameraDrop Node](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_topic_tools/index.html#nitroscameradrop-node) * [`isaac_ros_nitros_type`](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_nitros_type/index.html) * [`isaac_ros_pynitros`](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_pynitros/index.html) * [Creating PyNITROS-Accelerated Nodes](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_pynitros/index.html#creating-pynitros-accelerated-nodes) * [Quickstart](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_pynitros/index.html#quickstart) * [Try More Examples](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_pynitros/index.html#try-more-examples) * [API Reference](https://nvidia-isaac-ros.github.io/repositories_and_packages/isaac_ros_nitros/isaac_ros_pynitros/index.html#api-reference) ## Latest Update 2026-04-30: Compatibility and integration updates for the Isaac ROS 4.4.0 release ================================================ FILE: SECURITY.md ================================================ ## Security NVIDIA is dedicated to the security and trust of our software products and services, including all source code repositories managed through our organization. If you need to report a security issue, please use the appropriate contact points outlined below. **Please do not report security vulnerabilities through GitHub.** If a potential security issue is inadvertently reported via a public issue or pull request, NVIDIA maintainers may limit public discussion and redirect the reporter to the appropriate private disclosure channels. ## Reporting Potential Security Vulnerability in an NVIDIA Product To report a potential security vulnerability in any NVIDIA product: - Web: [Security Vulnerability Submission Form](https://www.nvidia.com/object/submit-security-vulnerability.html) - E-Mail: psirt@nvidia.com - We encourage you to use the following PGP key for secure email communication: [NVIDIA public PGP Key for communication](https://www.nvidia.com/en-us/security/pgp-key) - Please include the following information: - Product/Driver name and version/branch that contains the vulnerability - Type of vulnerability (code execution, denial of service, buffer overflow, etc.) - Instructions to reproduce the vulnerability - Proof-of-concept or exploit code - Potential impact of the vulnerability, including how an attacker could exploit the vulnerability While NVIDIA currently does not have a bug bounty program, we do offer acknowledgement when an externally reported security issue is addressed under our coordinated vulnerability disclosure policy. Please visit our [Product Security Incident Response Team (PSIRT)](https://www.nvidia.com/en-us/security/psirt-policies/) policies page for more information. ## NVIDIA Product Security For all security-related concerns, please visit NVIDIA's Product Security portal at https://www.nvidia.com/en-us/security ================================================ FILE: isaac_ros_gxf/CMakeLists.txt ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.22.1) project(isaac_ros_gxf) # Add option for overriding GXF core library directory option(GXF_CORE_LIB_DIR_OVERRIDE "Override path for GXF core library directory" "") execute_process(COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE) message( STATUS "Architecture: ${ARCHITECTURE}" ) find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() add_library(${PROJECT_NAME} STATIC src/isaac_ros_gxf.cpp) # GXF core headers install( DIRECTORY gxf/core/include/ DESTINATION share/${PROJECT_NAME}/gxf/include/ ) # Install extensions directory if( ${ARCHITECTURE} STREQUAL "x86_64" ) install(DIRECTORY gxf/core/lib/gxf_x86_64_cuda_13_0/ DESTINATION share/${PROJECT_NAME}/gxf/lib) install(FILES gxf/core/lib/gxf_x86_64_cuda_13_0/core/libgxf_core.so DESTINATION lib) install(FILES gxf/core/lib/gxf_x86_64_cuda_13_0/logger/libgxf_logger.so DESTINATION lib) install(FILES gxf/core/lib/gxf_x86_64_cuda_13_0/multimedia/libgxf_multimedia.so DESTINATION lib) install(FILES gxf/core/lib/gxf_x86_64_cuda_13_0/cuda/libgxf_cuda.so DESTINATION lib) elseif( ${ARCHITECTURE} STREQUAL "aarch64" ) if(CMAKE_DEVICE STREQUAL "sbsa") set(GXF_CORE_LIB_DIR gxf/core/lib/gxf_aarch64_cuda_13_0/) elseif(CMAKE_DEVICE STREQUAL "arm64") set(GXF_CORE_LIB_DIR gxf/core/lib/gxf_jetpack70/) else() message(FATAL_ERROR "Device is not supported.") endif() install(DIRECTORY ${GXF_CORE_LIB_DIR} DESTINATION share/${PROJECT_NAME}/gxf/lib) install(FILES ${GXF_CORE_LIB_DIR}/core/libgxf_core.so DESTINATION lib) install(FILES ${GXF_CORE_LIB_DIR}/logger/libgxf_logger.so DESTINATION lib) install(FILES ${GXF_CORE_LIB_DIR}/multimedia/libgxf_multimedia.so DESTINATION lib) install(FILES ${GXF_CORE_LIB_DIR}/cuda/libgxf_cuda.so DESTINATION lib) endif() # Register cmake in install. ament_index_register_resource(isaac_ros_gxf_cmake_path CONTENT "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/cmake") list(APPEND ${PROJECT_NAME}_CONFIG_EXTRAS cmake/isaac_ros_gxf-extras.cmake) # Core add_library(Core INTERFACE) set_target_properties(Core PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include" ) set_property(TARGET Core PROPERTY INTERFACE_LINK_LIBRARIES magic_enum::magic_enum "$/lib/libgxf_core.so" ) # Logger add_library(Logger INTERFACE) set_target_properties(Logger PROPERTIES INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/logger/libgxf_logger.so" INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include" ) # Std add_library(Std INTERFACE) set_target_properties(Std PROPERTIES INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/std/libgxf_std.so" INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include" ) # Multimedia add_library(Multimedia INTERFACE) set_target_properties(Multimedia PROPERTIES INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/multimedia/libgxf_multimedia.so" INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include" ) # Serialization add_library(Serialization INTERFACE) set_target_properties(Serialization PROPERTIES INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/serialization/libgxf_serialization.so" INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include" ) # Cuda add_library(Cuda INTERFACE) set_target_properties(Cuda PROPERTIES INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/cuda/libgxf_cuda.so" INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include" ) install(TARGETS Core Logger Std Multimedia Serialization Cuda EXPORT export_${PROJECT_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) if(BUILD_TESTING) find_package(ament_lint_auto REQUIRED) # Ignore copyright notices since we use custom NVIDIA Isaac ROS Software License set(ament_cmake_copyright_FOUND TRUE) ament_lint_auto_find_test_dependencies() endif() # Embed versioning information into installed files ament_index_get_resource(ISAAC_ROS_COMMON_CMAKE_PATH isaac_ros_common_cmake_path isaac_ros_common) include("${ISAAC_ROS_COMMON_CMAKE_PATH}/isaac_ros_common-version-info.cmake") generate_version_info(${PROJECT_NAME}) ament_auto_package(INSTALL_TO_SHARE cmake) ================================================ FILE: isaac_ros_gxf/cmake/isaac_ros_gxf-extras.cmake ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 # Common flags and cmake commands for all Isaac ROS packages based on NITROS message(STATUS "Loading isaac_ros_gxf extras") # Append local cmake module path for CMAKE_MODULE_PATH ament_index_get_resource(ISAAC_ROS_GXF_CMAKE_PATH isaac_ros_gxf_cmake_path isaac_ros_gxf) list(APPEND CMAKE_MODULE_PATH "${ISAAC_ROS_GXF_CMAKE_PATH}/modules") # Versions set(ISAAC_ROS_GXF_VERSION 2.5.0) ================================================ FILE: isaac_ros_gxf/cmake/modules/FindGXF.cmake ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 # Create GXF imported cmake targets # # This module defines GXF_FOUND if all GXF libraries are found or # if the required libraries (COMPONENTS property in find_package) # are found. # # A new imported target is created for each component (library) # under the GXF namespace (GXF::${component_name}) # # Note: this leverages the find-module paradigm [1]. The config-file paradigm [2] # is recommended instead in CMake. # [1] https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#config-file-packages # [2] https://cmake.org/cmake/help/latest/manual/cmake-packages.7.html#find-module-packages # Library names list(APPEND _GXF_EXTENSIONS cuda multimedia serialization std ) list(APPEND GXF_BASE_PATHS "${isaac_ros_gxf_DIR}/../../../share/isaac_ros_gxf/gxf") # Common headers find_path(GXF_common_INCLUDE_DIR NAMES common/ PATHS ${GXF_BASE_PATHS} PATH_SUFFIXES include/ REQUIRED ) mark_as_advanced(GXF_common_INCLUDE_DIR) list(APPEND GXF_INCLUDE_DIR_VARS GXF_common_INCLUDE_DIR) # Libraries and their headers list(APPEND _GXF_LIBRARIES ${_GXF_EXTENSIONS} core) foreach(component IN LISTS _GXF_LIBRARIES) # headers find_path(GXF_${component}_INCLUDE_DIR NAMES "${component}/" PATHS ${GXF_BASE_PATHS} PATH_SUFFIXES include include/gxf NO_DEFAULT_PATH REQUIRED ) mark_as_advanced(GXF_${component}_INCLUDE_DIR) list(APPEND GXF_INCLUDE_DIR_VARS GXF_${component}_INCLUDE_DIR) # library find_library(GXF_${component}_LIBRARY NAMES "gxf_${component}" "${component}" PATHS ${GXF_BASE_PATHS} PATH_SUFFIXES lib/${component} lib/${GXF_PLATFORM_SUFFIX} lib/${GXF_PLATFORM_SUFFIX}/${component} lib/${GXF_PLATFORM_SUFFIX}/isaac lib/${GXF_PLATFORM_SUFFIX}/isaac/${component} REQUIRED ) mark_as_advanced(GXF_${component}_LIBRARY) list(APPEND GXF_LIBRARY_VARS GXF_${component}_LIBRARY) # create imported target if(GXF_${component}_LIBRARY AND GXF_${component}_INCLUDE_DIR) set(gxf_component_location "${GXF_${component}_LIBRARY}") if(NOT TARGET GXF::${component}) # Assume SHARED, though technically UNKNOWN since we don't enforce .so add_library(GXF::${component} SHARED IMPORTED) endif() list(APPEND GXF_${component}_INCLUDE_DIRS ${GXF_${component}_INCLUDE_DIR} ${GXF_${component}_INCLUDE_DIR}/${component} ${GXF_common_INCLUDE_DIR} ) message(STATUS "Found ${component} lib=${gxf_component_location}, include=${GXF_${component}_INCLUDE_DIR}") # Points to the copied location of GXF set_target_properties(GXF::${component} PROPERTIES IMPORTED_LOCATION "${gxf_component_location}" IMPORTED_NO_SONAME ON INTERFACE_INCLUDE_DIRECTORIES "${GXF_${component}_INCLUDE_DIRS}" ) set(GXF_${component}_FOUND TRUE) else() message(FATAL_ERROR "Could not find GXF::${component}: lib={GXF_${component}_LIBRARY} / include=${GXF_${component}_INCLUDE_DIR}") set(GXF_${component}_FOUND FALSE) endif() endforeach() unset(_GXF_EXTENSIONS) unset(_GXF_LIBRARIES) # Find version if(GXF_core_INCLUDE_DIR) # Note: "kGxfCoreVersion \"(.*)\"$" does not work with a simple string # REGEX (doesn't stop and EOL, neither $ nor \n), so we first extract # the line with file(STRINGS), then the version with string(REGEX) file(STRINGS "${GXF_core_INCLUDE_DIR}/core/gxf.h" _GXF_VERSION_LINE REGEX "kGxfCoreVersion" ) string(REGEX MATCH "kGxfCoreVersion \"(.*)\"" _ ${_GXF_VERSION_LINE}) set(GXF_VERSION ${CMAKE_MATCH_1}) unset(_GXF_VERSION_LINE) endif() # Generate GXF_FOUND include(FindPackageHandleStandardArgs) find_package_handle_standard_args(GXF FOUND_VAR GXF_FOUND VERSION_VAR GXF_VERSION HANDLE_COMPONENTS # Looks for GXF_${component}_FOUND ) ================================================ FILE: isaac_ros_gxf/gxf/AMENT_IGNORE ================================================ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/assert.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_ASSERT_HPP_ #define NVIDIA_COMMON_ASSERT_HPP_ #include #include #include #include "common/backtrace.hpp" #include "common/logger.hpp" // Prints a panic message and aborts the program #define GXF_PANIC(...) \ { \ GXF_LOG_PANIC(__VA_ARGS__); \ PrettyPrintBacktrace(); \ std::exit(1); \ } // Checks if an expression evaluates to true. If not prints a panic message and aborts the program. #define GXF_ASSERT(expr, ...) \ if (!(expr)) { \ GXF_LOG_PANIC(__VA_ARGS__); \ PrettyPrintBacktrace(); \ std::exit(1); \ } #define GXF_ASSERT_SUCCESS(expr) \ { \ const auto _result = (expr); \ if (_result != 0) { \ GXF_LOG_PANIC("GXF operation failed: %s", GxfResultStr(_result)); \ PrettyPrintBacktrace(); \ std::exit(1); \ } \ } \ // Asserts that A == true. If not prints a panic message and aborts the program. #define GXF_ASSERT_TRUE(exp_a) \ { \ const auto _va = exp_a; \ GXF_ASSERT(_va == true, "Assert failed: %s == true.", std::to_string(_va).c_str()); \ } // Asserts that A == false. If not prints a panic message and aborts the program. #define GXF_ASSERT_FALSE(exp_a) \ { \ const auto _va = exp_a; \ GXF_ASSERT(_va == false, "Assert failed: %s == false.", std::to_string(_va).c_str()); \ } // Asserts that A == B. If not prints a panic message and aborts the program. #define GXF_ASSERT_EQ(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ GXF_ASSERT(_va == _vb, "Assert failed: %s == %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A == B for two strings. If not prints a panic message and aborts the program. #define GXF_ASSERT_STREQ(exp_a, exp_b) \ { \ const char* _va = (exp_a); \ const char* _vb = (exp_b); \ GXF_ASSERT(std::strcmp(_va, _vb) == 0, "Assert failed: %s == %s.", _va, _vb); \ } // Asserts that A != B. If not prints a panic message and aborts the program. #define GXF_ASSERT_NE(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ GXF_ASSERT(_va != _vb, "Assert failed: %s != %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A > B. If not prints a panic message and aborts the program. #define GXF_ASSERT_GT(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ GXF_ASSERT(_va > _vb, "Assert failed: %s > %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A >= B. If not prints a panic message and aborts the program. #define GXF_ASSERT_GE(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ GXF_ASSERT(_va >= _vb, "Assert failed: %s >= %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A > B. If not prints a panic message and aborts the program. #define GXF_ASSERT_LT(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ GXF_ASSERT(_va < _vb, "Assert failed: %s > %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A <= B. If not prints a panic message and aborts the program. #define GXF_ASSERT_LE(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ GXF_ASSERT(_va <= _vb, "Assert failed: %s <= %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that abs(A - B) <= abs_error. If not prints a panic message and aborts the program. #define GXF_ASSERT_NEAR(exp_a, exp_b, exp_abs_error) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ const auto _verror = exp_abs_error; \ GXF_ASSERT(std::abs(_va - _vb) <= _verror, "Assert failed: abs(%s - %s) <= %s.", \ std::to_string(_va).c_str(), std::to_string(_vb).c_str(), \ std::to_string(_verror).c_str()); \ } #endif // NVIDIA_COMMON_ASSERT_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/backtrace.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_BACKTRACE_HPP_ #define NVIDIA_COMMON_BACKTRACE_HPP_ // Print the stacktrace with demangled function names (if possible) // Function is disabled for QNX since execinfo.h is not available in the QNX toolchain void PrettyPrintBacktrace(); #endif // NVIDIA_COMMON_BACKTRACE_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/byte.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_BYTE_HPP_ #define NVIDIA_COMMON_BYTE_HPP_ # if __cplusplus < 201703L namespace std { using byte = unsigned char; } // namespace std using std::byte; # else namespace nvidia { using byte = unsigned char; } using nvidia::byte; #endif #endif // NVIDIA_COMMON_BYTE_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/endian.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_ENDIAN_HPP_ #define NVIDIA_COMMON_ENDIAN_HPP_ #ifdef _QNX_SOURCE #include #else #include #endif #include "common/type_utils.hpp" namespace nvidia { /// Returns true if the machine stores multi-byte integers in little-endian format /// FIXME: Use std::memcpy if reinterpret_cast has to be removed inline bool IsLittleEndian() { const uint16_t test = 0x0102; return *reinterpret_cast(&test) == 0x02; } /// Convert @a value to little-endian. /// This overload should only be used if @c T is a signed integer type. template >> inline T EncodeLittleEndian(T value) { static_assert(IsSigned_v); using U = MakeUnsigned_t; return static_cast(EncodeLittleEndian(static_cast(value))); } template <> inline uint64_t EncodeLittleEndian(uint64_t value) { return htole64(value); } template <> inline uint32_t EncodeLittleEndian(uint32_t value) { return htole32(value); } template <> inline uint16_t EncodeLittleEndian(uint16_t value) { return htole16(value); } template <> inline uint8_t EncodeLittleEndian (uint8_t value) { return value; } /// Convert @a value from little-endian. /// This overload should only be used if @c T is a signed integer type. template >> inline T DecodeLittleEndian(T value) { static_assert(IsSigned_v); using U = MakeUnsigned_t; return static_cast(DecodeLittleEndian(static_cast(value))); } template <> inline uint64_t DecodeLittleEndian(uint64_t value) { return le64toh(value); } template <> inline uint32_t DecodeLittleEndian(uint32_t value) { return le32toh(value); } template <> inline uint16_t DecodeLittleEndian(uint16_t value) { return le16toh(value); } template <> inline uint8_t DecodeLittleEndian (uint8_t value) { return value; } /// Returns true if the machine stores multi-byte integers in big-endian format /// FIXME: Use std::memcpy if reinterpret_cast has to be removed inline bool IsBigEndian() { const uint16_t test = 0x0102; return *reinterpret_cast(&test) == 0x01; } /// Convert @a value to big-endian. /// This overload should only be used if @c T is a signed integer type. template >> inline T EncodeBigEndian(T value) { static_assert(IsSigned_v); using U = MakeUnsigned_t; return static_cast(EncodeBigEndian(static_cast(value))); } template <> inline uint64_t EncodeBigEndian(uint64_t value) { return htobe64(value); } template <> inline uint32_t EncodeBigEndian(uint32_t value) { return htobe32(value); } template <> inline uint16_t EncodeBigEndian(uint16_t value) { return htobe16(value); } template <> inline uint8_t EncodeBigEndian (uint8_t value) { return value; } /// Convert @a value from big-endian. /// This overload should only be used if @c T is a signed integer type. template >> inline T DecodeBigEndian(T value) { static_assert(IsSigned_v); using U = MakeUnsigned_t; return static_cast(DecodeBigEndian(static_cast(value))); } template <> inline uint64_t DecodeBigEndian(uint64_t value) { return be64toh(value); } template <> inline uint32_t DecodeBigEndian(uint32_t value) { return be32toh(value); } template <> inline uint16_t DecodeBigEndian(uint16_t value) { return be16toh(value); } template <> inline uint8_t DecodeBigEndian (uint8_t value) { return value; } } // namespace nvidia #endif // NVIDIA_COMMON_ENDIAN_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/expected.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_EXPECTED_HPP_ #define NVIDIA_COMMON_EXPECTED_HPP_ #include #include "common/assert.hpp" #include "common/memory_utils.hpp" #include "common/strong_type.hpp" #include "common/type_utils.hpp" namespace nvidia { template using Unexpected = StrongType; template class Expected; ///------------------------------------------------------------------------------------------------- /// Local Helper Functions ///------------------------------------------------------------------------------------------------- namespace detail { template struct IsExpectedHelper : FalseType {}; template struct IsExpectedHelper> : TrueType {}; template using IsExpected = IsExpectedHelper>; template constexpr bool IsExpected_v = IsExpected::value; // Extracts the error type from a pack of Expecteds if they all contain the same Error . template struct ErrorTypeHelper : TypeIdentity {}; template struct ErrorTypeHelper...> : TypeIdentity {}; template using ErrorType = typename ErrorTypeHelper...>::type; template using ErrorTypeOr = Conditional_t>; // Extracts the error type from a pack of Expecteds if they all contain the same Error . template struct ValueTypeHelper {}; template struct ValueTypeHelper> { using type = T; }; template using ValueType = typename ValueTypeHelper>::type; // Extracts the type from a Unexpected if provided. Otherwise, returns the type T. template struct UnexpectedTypeHelper : TypeIdentity {}; template struct UnexpectedTypeHelper> : TypeIdentity {}; template using UnexpectedType = typename UnexpectedTypeHelper>::type; // Finds the result type of invoking a function with the wrapped types of a pack of Expecteds. template using ResultType = decltype(Declval()(Declval().value()...)); template using ErrorResultType = UnexpectedType()(Declval().error()...))>; // Empty struct for representing an object with only one possible value (itself). This can be used // for speciallizing on void types where void would not compile because it is not a valid type. // NOTE: GCC9 has a bug where it cannot evaluate the destructor of an empty struct, so put a dummy // byte in to pass the compiler warnings. All empty structs are always considered non-zero in size // in C++ anyway, and these are functionally equivalent for use with Expected. // https://www.stroustrup.com/bs_faq2.html#sizeof-empty struct Unit { byte dummy; }; // If T is already Expected, keep as Expected, otherwise wrap as Expected template struct FlattenExpectedHelper : TypeIdentity> {}; template struct FlattenExpectedHelper, E> : TypeIdentity> {}; template struct FlattenExpectedHelper&, E> : TypeIdentity, E>> {}; template struct FlattenExpectedHelper&, E> : TypeIdentity, E>> {}; template using FlattenExpected = typename FlattenExpectedHelper::type; // Helper for specializing on variadic parameter packs template struct Pack {}; // Checks if a functor is callable with an Expected value. template struct IsCallableHelper : FalseType {}; template struct IsCallableHelper, void_t>> : TrueType {}; template struct IsCallable : IsCallableHelper> {}; template constexpr bool IsCallable_v = IsCallable::value; // Checks if a functor is callable with an Expected value. template struct IsErrorCallableHelper : FalseType {}; template struct IsErrorCallableHelper, void_t>> : TrueType {}; template struct IsErrorCallable : IsErrorCallableHelper> {}; template constexpr bool IsErrorCallable_v = IsErrorCallable::value; // Maps the values with the given functor. If F returns an Expected, it returns the Expected type // directly, otherwise it constructs a new Expected. template auto FunctorMap(F&& func, Args&&... expected) -> EnableIf_t>, FlattenExpected, ErrorTypeOr>> { return std::forward(func)(std::forward(expected).value()...); } // Maps the values with the given void functor. Returns Expected. template auto FunctorMap(F&& func, Args&&... expected) -> EnableIf_t>, Expected>> { std::forward(func)(std::forward(expected).value()...); return {}; } // Maps the error values with the given function. If F returns an Unexpected, it returns the // Unexpected type directly, otherwise it constructs a new Unexpected. template Expected, ErrorResultType> FunctorMapError(F&& func, E&& expected) { using R = Unexpected>; return R{std::forward(func)(std::forward(expected).error())}; } template Expected> FunctorMapError(F&& func) { using R = Unexpected>; return R{std::forward(func)()}; } // Base class for all operations of Expected, not directly related to setting or creating the value // type T into the underlying byte buffer. template class ExpectedBase { private: static_assert(!IsVoid_v, "ExpectedBase cannot wrap void types"); static_assert(!IsVoid_v, "ExpectedBase cannot wrap void types"); static_assert(!IsReference_v, "ExpectedBase cannot wrap reference types"); static_assert(!IsReference_v, "ExpectedBase cannot wrap reference types"); template using EnableIfMappable_t = EnableIf_t, decltype(FunctorMap(Declval(), Declval()))>; template using EnableIfNonaryMappable_t = EnableIf_t && !IsCallable_v, FlattenExpected, E>>; template using EnableIfMappableError_t = EnableIf_t, decltype(FunctorMapError(Declval(), Declval()))>; template using EnableIfNonaryMappableError_t = EnableIf_t && !IsErrorCallable_v, Expected>>; public: ///----------------------------------------------------------------------------------------------- /// Constructors ///----------------------------------------------------------------------------------------------- constexpr ExpectedBase(const ExpectedBase& other) { constructFrom(other); } constexpr ExpectedBase(ExpectedBase&& other) { constructFrom(std::move(other)); } // Construction from convertible error types template explicit constexpr ExpectedBase(const ExpectedBase& other) { static_assert(IsConvertible_v, "Cannot construct Expected from type with unconvertible error type."); constructFrom(other); } template explicit constexpr ExpectedBase(ExpectedBase&& other) { static_assert(IsConvertible_v, "Cannot construct Expected from type with unconvertible error type."); constructFrom(std::move(other)); } template constexpr ExpectedBase(const Unexpected& error, const char* error_message = "") : is_error_{true}, error_message_{error_message} { static_assert(IsConvertible_v, "Cannot construct Unexpected from type with unconvertible error type."); InplaceConstruct>(buffer_, error.value()); } template constexpr ExpectedBase(Unexpected&& error, const char* error_message = "") : is_error_{true}, error_message_{error_message} { static_assert(IsConvertible_v, "Cannot construct Unexpected from type with unconvertible error type."); InplaceConstruct>(buffer_, std::move(error.value())); } ///----------------------------------------------------------------------------------------------- /// Destructor ///----------------------------------------------------------------------------------------------- ~ExpectedBase() { destruct(); } ///----------------------------------------------------------------------------------------------- /// Assignment ///----------------------------------------------------------------------------------------------- ExpectedBase& operator=(const ExpectedBase& other) { destruct(); constructFrom(other); return *this; } ExpectedBase& operator=(ExpectedBase&& other) { destruct(); constructFrom(std::move(other)); return *this; } template ExpectedBase& operator=(const Unexpected& error) { destruct(); is_error_ = true; InplaceConstruct>(buffer_, error); return *this; } template ExpectedBase& operator=(Unexpected&& error) { destruct(); is_error_ = true; InplaceConstruct>(buffer_, std::move(error)); return *this; } ///----------------------------------------------------------------------------------------------- /// Observers ///----------------------------------------------------------------------------------------------- template , class D = const Derived> constexpr EnableIf_t, RemoveReference_t()->value())>*> operator->() const { return &(derived()->value()); } template , class D = Derived> constexpr EnableIf_t, RemoveReference_t()->value())>*> operator->() { return &(derived()->value()); } template > constexpr EnableIf_t, const V&> operator*() const& { return derived()->value(); } template > constexpr EnableIf_t, V&> operator*() & { return derived()->value(); } template , EnableIf_t, void*> = nullptr> constexpr decltype(auto) operator*() const&& { return std::move(derived())->value(); } template , EnableIf_t, void*> = nullptr> constexpr decltype(auto) operator*() && { return std::move(derived())->value(); } template , EnableIf_t, void*> = nullptr> constexpr V value_or(U&& default_value) const& { return has_value() ? derived()->value() : std::forward(default_value); } template , EnableIf_t, void*> = nullptr> constexpr V value_or(U&& default_value) && { return has_value() ? std::move(derived())->value() : std::forward(default_value); } constexpr bool has_value() const { return !is_error_; } constexpr explicit operator bool() const { return !is_error_; } constexpr const E& error() const& { return unexpected().value(); } constexpr E& error() & { return unexpected().value(); } constexpr E&& error() && { return std::move(unexpected()).value(); } constexpr const char* get_error_message() { GXF_ASSERT(is_error_, "Expected does not have an error. Check before accessing."); return error_message_; } ///----------------------------------------------------------------------------------------------- /// Logging ///----------------------------------------------------------------------------------------------- // Logging helper functions if this contains an error value. template constexpr const Derived& log_error(Args&&... args) const& { if (is_error_) { GXF_LOG_ERROR(std::forward(args)...); } return static_cast(*this); } template constexpr Derived& log_error(Args&&... args) & { if (is_error_) { GXF_LOG_ERROR(std::forward(args)...); } return static_cast(*this); } template constexpr Derived&& log_error(Args&&... args) && { // GCC is not able to do format security validation when the string is coming from a // variadic template, even if the string is originally a char* // ignore this warning until a more recent GCC version fixes this behavior #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-security" if (is_error_) { GXF_LOG_ERROR(std::forward(args)...); } #pragma GCC diagnostic pop return static_cast(std::move(*this)); } template constexpr const Derived& log_warning(Args&&... args) const& { if (is_error_) { GXF_LOG_WARNING(std::forward(args)...); } return static_cast(*this); } template constexpr Derived& log_warning(Args&&... args) & { if (is_error_) { GXF_LOG_WARNING(std::forward(args)...); } return static_cast(*this); } template constexpr Derived&& log_warning(Args&&... args) && { if (is_error_) { GXF_LOG_WARNING(std::forward(args)...); } return static_cast(std::move(*this)); } template constexpr const Derived& log_info(Args&&... args) const& { if (is_error_) { GXF_LOG_INFO(std::forward(args)...); } return static_cast(*this); } template constexpr Derived& log_info(Args&&... args) & { if (is_error_) { GXF_LOG_INFO(std::forward(args)...); } return static_cast(*this); } template constexpr Derived&& log_info(Args&&... args) && { if (is_error_) { GXF_LOG_INFO(std::forward(args)...); } return static_cast(std::move(*this)); } template constexpr const Derived& log_debug(Args&&... args) const& { if (is_error_) { GXF_LOG_DEBUG(std::forward(args)...); } return static_cast(*this); } template constexpr Derived& log_debug(Args&&... args) & { if (is_error_) { GXF_LOG_DEBUG(std::forward(args)...); } return static_cast(*this); } template constexpr Derived&& log_debug(Args&&... args) && { if (is_error_) { GXF_LOG_DEBUG(std::forward(args)...); } return static_cast(std::move(*this)); } ///----------------------------------------------------------------------------------------------- /// Substitute ///----------------------------------------------------------------------------------------------- // When this expected does not contain an error an expected with the given value 'next' is // created and returned, otherwise an unexpected with the error is returned. template constexpr FlattenExpected substitute(U next) const& { return has_value() ? FlattenExpected{std::forward(next)} : unexpected(); } template constexpr FlattenExpected substitute(U next) && { return has_value() ? FlattenExpected{std::forward(next)} : std::move(unexpected()); } ///----------------------------------------------------------------------------------------------- /// Substitute Error ///----------------------------------------------------------------------------------------------- template constexpr Expected, G> substitute_error(G new_error) const& { using R = Expected, G>; return is_error_ ? R{Unexpected{new_error}} : R{*ValuePointer(buffer_)}; } template constexpr Expected, G> substitute_error(G new_error) && { using R = Expected, G>; return is_error_ ? R{Unexpected{new_error}} : R{std::move(*ValuePointer(buffer_))}; } ///----------------------------------------------------------------------------------------------- /// Unary Free Functor Map ///----------------------------------------------------------------------------------------------- // If in error the error is returned, otherwise the value is mapped with the given functor and // the result is returned. template constexpr EnableIfMappable_t map(F&& func) & { return has_value() ? FunctorMap(std::forward(func), *derived()) : unexpected(); } template constexpr EnableIfMappable_t map(F&& func) const& { return has_value() ? FunctorMap(std::forward(func), *derived()) : unexpected(); } template constexpr EnableIfMappable_t map(F&& func) && { return has_value() ? FunctorMap(std::forward(func), std::move(*derived())) : std::move(unexpected()); } ///----------------------------------------------------------------------------------------------- /// Unary Free Functor Map Error ///----------------------------------------------------------------------------------------------- // If has value the value is returned, otherwise the error is mapped with the given functor and // the result is returned. template constexpr EnableIfMappableError_t map_error(F&& func) & { using R = Expected, ErrorResultType>; return is_error_ ? FunctorMapError(std::forward(func), *derived()) : R{*ValuePointer(buffer_)}; } template constexpr EnableIfMappableError_t map_error(F&& func) const& { using R = Expected, ErrorResultType>; return is_error_ ? FunctorMapError(std::forward(func), *derived()) : R{*ValuePointer(buffer_)}; } template constexpr EnableIfMappableError_t map_error(F&& func) && { using R = Expected, ErrorResultType>; return is_error_ ? FunctorMapError(std::forward(func), std::move(*derived())) : R{std::move(*ValuePointer(buffer_))}; } ///----------------------------------------------------------------------------------------------- /// Nonary Free Functor Map ///----------------------------------------------------------------------------------------------- // If in error the error is returned, otherwise the given functor is called with no arguments and // the result is returned. template constexpr EnableIfNonaryMappable_t map(F&& func) const& { return has_value() ? FunctorMap(std::forward(func)) : unexpected(); } template constexpr EnableIfNonaryMappable_t map(F&& func) && { return has_value() ? FunctorMap(std::forward(func)) : std::move(unexpected()); } template constexpr FlattenExpected, E> and_then(F&& func) const& { return has_value() ? FunctorMap(std::forward(func)) : unexpected(); } template constexpr FlattenExpected, E> and_then(F&& func) && { return has_value() ? FunctorMap(std::forward(func)) : std::move(unexpected()); } ///----------------------------------------------------------------------------------------------- /// Nonary Free Functor Map Error ///----------------------------------------------------------------------------------------------- // If has value the value is returned, otherwise the given functor is called with no arguments and // the result is returned. template constexpr EnableIfNonaryMappableError_t map_error(F&& func) const& { static_assert(IsErrorCallable_v); static_assert(!IsErrorCallable_v); using R = Expected, ErrorResultType>; return is_error_ ? FunctorMapError(std::forward(func)) : R{*ValuePointer(buffer_)}; } template constexpr EnableIfNonaryMappableError_t map_error(F&& func) && { using R = Expected, ErrorResultType>; return is_error_ ? FunctorMapError(std::forward(func)) : R{std::move(*ValuePointer(buffer_))}; } template constexpr Expected, ErrorResultType> and_then_error(F&& func) const& { using R = Expected, ErrorResultType>; return is_error_ ? FunctorMapError(std::forward(func)) : R{*ValuePointer(buffer_)}; } template constexpr Expected, ErrorResultType> and_then_error(F&& func) && { using R = Expected, ErrorResultType>; return is_error_ ? FunctorMapError(std::forward(func)) : R{std::move(*ValuePointer(buffer_))}; } ///----------------------------------------------------------------------------------------------- /// Member Variable Map ///----------------------------------------------------------------------------------------------- template constexpr FlattenExpected map(R U::* ptr) & { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); // NOTE: We explicitly declare the return type of the lambda to allow capturing of member by // mutable reference, otherwise a lambda will always return a copy. auto func = [&](ValueType& a) -> decltype(auto) { return a.*ptr; }; return has_value() ? FunctorMap(func, *derived()) : unexpected(); } template constexpr FlattenExpected map(R U::* ptr) const& { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); auto func = [&](const ValueType& a) -> decltype(auto) { return a.*ptr; }; return has_value() ? FunctorMap(func, *derived()) : unexpected(); } template constexpr FlattenExpected, E> map(R U::* ptr) && { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); // NOTE: there is a subtle distinction here. If we want to get access to a member variable // from an rvalue context, we MUST make a copy, since we cannot guarantee the reference will // still be valid after destruction of the temporary. auto func = [&](ValueType&& a) { return a.*ptr; }; return has_value() ? FunctorMap(func, std::move(*derived())) : unexpected(); } template constexpr FlattenExpected, E> map(R U::* ptr) const&& { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); auto func = [&](const ValueType&& a) { return a.*ptr; }; return has_value() ? FunctorMap(func, std::move(*derived())) : unexpected(); } ///----------------------------------------------------------------------------------------------- /// Member Function Map ///----------------------------------------------------------------------------------------------- template constexpr FlattenExpected map(R (U::* ptr)(Args...), Args&&... args) { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); auto func = [&](U& a) { return (a.*ptr)(std::forward(args)...); }; return has_value() ? FunctorMap(func, *derived()) : unexpected(); } template constexpr FlattenExpected map(R (U::* ptr)(Args...) & , Args&&... args) & { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); auto func = [&](U& a) { return (a.*ptr)(std::forward(args)...); }; return has_value() ? FunctorMap(func, *derived()) : unexpected(); } template constexpr FlattenExpected map(R (U::* ptr)(Args...) &&, Args&&... args) && { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); auto func = [&](U&& a) { return (std::move(a).*ptr)(std::forward(args)...); }; return has_value() ? FunctorMap(func, std::move(*derived())) : unexpected(); } template constexpr FlattenExpected map(R (U::* ptr)(Args...) const, Args&&... args) const { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); auto func = [&](const U& a) { return (a.*ptr)(std::forward(args)...); }; return has_value() ? FunctorMap(func, *derived()) : unexpected(); } template constexpr FlattenExpected map(R (U::* ptr)(Args...) const&, Args&&... args) const& { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); auto func = [&](const U& a) { return (a.*ptr)(std::forward(args)...); }; return has_value() ? FunctorMap(func, *derived()) : unexpected(); } template constexpr FlattenExpected map(R (U::* ptr)(Args...) const&&, Args&&... args) const&& { static_assert(IsSame_v>>, "received pointer-to-member that is not of type T."); auto func = [&](const U&& a) { return (std::move(a).*ptr)(std::forward(args)...); }; return has_value() ? FunctorMap(func, std::move(*derived())) : unexpected(); } ///----------------------------------------------------------------------------------------------- /// Assign Value ///----------------------------------------------------------------------------------------------- // Assigns the value of an expected directly to a concrete instance with perfect forwarding. template constexpr Expected assign_to(U& value) const& { static_assert(IsAssignable_v&>, "Argument Type is not assignable with Expected Type (const T&)"); auto assign = [&](const ValueType& derived) { value = derived; }; return has_value() ? FunctorMap(assign, *derived()) : unexpected(); } template constexpr Expected assign_to(U& value) && { static_assert(IsAssignable_v&&>, "Argument Type is not assignable with Expected Type (T&&)"); auto move_assign = [&](ValueType&& derived) { value = std::move(derived); }; return has_value() ? FunctorMap(move_assign, std::move(*derived())) : std::move(unexpected()); } ///----------------------------------------------------------------------------------------------- /// Guard ///----------------------------------------------------------------------------------------------- template constexpr Expected, E> guard(P&& pred, E&& new_error) const& { if (is_error_) { return unexpected(); } return pred(derived()->value()) ? *derived() : Unexpected{new_error}; } template constexpr Expected, E> guard(P&& pred, E&& new_error) && { if (is_error_) { return std::move(unexpected()); } return pred(derived()->value()) ? std::move(*derived()) : Unexpected{new_error}; } ///----------------------------------------------------------------------------------------------- /// Ignore Error ///----------------------------------------------------------------------------------------------- template constexpr Expected, E> ignore_error(U&& next) const& { return has_value() ? *derived() : std::forward(next); } template constexpr Expected, E> ignore_error(U&& next) && { return has_value() ? std::move(*derived()) : std::forward(next); } constexpr Expected ignore_error() const { return {}; } protected: // Allow other Expected classes access to `unexpected` getters. template friend class ExpectedBase; // Protected default constructor so derived types can write custom initializers. ExpectedBase() = default; // Protected Value constructor so Derived types can convert to stored types template , void*> = nullptr> constexpr ExpectedBase(Args&&... args) { constructValueFrom(std::forward(args)...); } // Unexpected accessors to skip extra construction calls when not needed. constexpr const Unexpected& unexpected() const& { GXF_ASSERT(is_error_, "Expected does not have an error. Check before accessing."); return *ValuePointer>(buffer_); } constexpr Unexpected& unexpected() & { GXF_ASSERT(is_error_, "Expected does not have an error. Check before accessing."); return *ValuePointer>(buffer_); } constexpr Unexpected&& unexpected() && { GXF_ASSERT(is_error_, "Expected does not have an error. Check before accessing."); return std::move(*ValuePointer>(buffer_)); } // Returns a pointer to the derived type for accessing value result in supported specializations. constexpr const Derived* derived() const { return static_cast(this); } constexpr Derived* derived() { return static_cast(this); } ///----------------------------------------------------------------------------------------------- /// Construction Helpers ///----------------------------------------------------------------------------------------------- // Construct a new object in allocated buffer. template constexpr void constructFrom(const ExpectedBase& other) { other.has_value() ? constructValueFrom(other) : constructErrorFrom(other); } // Move construct a new object in allocated buffer. template constexpr void constructFrom(ExpectedBase&& other) { other.has_value() ? constructValueFrom(std::move(other)) : constructErrorFrom(std::move(other)); } template constexpr void constructErrorFrom(const ExpectedBase& other) { is_error_ = true; InplaceCopyConstruct(buffer_, *ValuePointer>(other.buffer_)); } template constexpr void constructErrorFrom(ExpectedBase&& other) { is_error_ = true; InplaceMoveConstruct(buffer_, std::move(*ValuePointer>(other.buffer_))); } template constexpr void constructValueFrom(const ExpectedBase& other) { is_error_ = false; InplaceCopyConstruct(buffer_, *ValuePointer(other.buffer_)); } template constexpr void constructValueFrom(ExpectedBase&& other) { is_error_ = false; InplaceConstruct(buffer_, std::move(*ValuePointer(other.buffer_))); } template void constructValueFrom(Args&&... args) { is_error_ = false; InplaceConstruct(buffer_, std::forward(args)...); } // Call the destructor for the current object explicitly constexpr void destruct() { has_value() ? Destruct(buffer_) : Destruct>(buffer_); } bool is_error_ = true; const char* error_message_{}; static constexpr uint32_t kAlign = (alignof(Unexpected) < alignof(T)) ? alignof(T) : alignof(Unexpected); static constexpr uint32_t kSize = (sizeof(Unexpected) < sizeof(T)) ? sizeof(T) : sizeof(Unexpected); alignas(kAlign) byte buffer_[kSize] = {0}; }; } // namespace detail ///------------------------------------------------------------------------------------------------- // Expected Implementation ///------------------------------------------------------------------------------------------------- // Default instance for Expected types. template class Expected : public detail::ExpectedBase> { public: using detail::ExpectedBase::ExpectedBase; // Enable implicit construction of Move-Only types constexpr Expected(T&& value) : detail::ExpectedBase(std::move(value)) {} template && IsConvertible_v>* = nullptr> constexpr Expected(U&& value) : detail::ExpectedBase(std::forward(value)) {} template && !IsConvertible_v>* = nullptr> explicit constexpr Expected(U&& value) : detail::ExpectedBase(std::forward(value)) {} template , void*> = nullptr> explicit constexpr Expected(Args&&... args) : detail::ExpectedBase(std::forward(args)...) {} template && IsConvertible_v>* = nullptr> constexpr Expected(const Expected& other) { other.has_value() ? this->constructValueFrom(other.value()) : this->constructErrorFrom(other); } template && !IsConvertible_v>* = nullptr> explicit constexpr Expected(const Expected& other) { other.has_value() ? this->constructValueFrom(other.value()) : this->constructErrorFrom(other); } template && IsConvertible_v>* = nullptr> constexpr Expected(Expected&& other) { other.has_value() ? this->constructValueFrom(std::move(other.value())) : this->constructErrorFrom(std::move(other)); } template && !IsConvertible_v>* = nullptr> explicit constexpr Expected(Expected&& other) { other.has_value() ? this->constructValueFrom(std::move(other.value())) : this->constructErrorFrom(std::move(other)); } template && IsConvertible_v>* = nullptr> constexpr Expected& operator=(U&& value) { this->destruct(); this->constructValueFrom(std::forward(value)); return *this; } template T& replace(Args&&... args) { static_assert(IsConstructible_v, "T cannot be constructed with the provide argument types."); this->destruct(); this->constructValueFrom(std::forward(args)...); return value(); } constexpr const T& value() const& { GXF_ASSERT(this->has_value(), "Expected does not have a value. Check before accessing."); return *ValuePointer(this->buffer_); } constexpr T& value() & { GXF_ASSERT(this->has_value(), "Expected does not have a value. Check before accessing."); return *ValuePointer(this->buffer_); } constexpr const T&& value() const&& { GXF_ASSERT(this->has_value(), "Expected does not have a value. Check before accessing."); return std::move(*ValuePointer(this->buffer_)); } constexpr T&& value() && { GXF_ASSERT(this->has_value(), "Expected does not have a value. Check before accessing."); return std::move(*ValuePointer(this->buffer_)); } }; ///------------------------------------------------------------------------------------------------- /// Expected of Reference Implementation ///------------------------------------------------------------------------------------------------- // Specialization of Expected for references. template class Expected : public detail::ExpectedBase> { private: template struct IsExpectedConvertible : FalseType {}; template struct IsExpectedConvertible().value())>> : IsConvertible().value()), T&> {}; template static constexpr bool IsExpectedConvertible_v = detail::IsExpected_v && IsExpectedConvertible::value; public: using detail::ExpectedBase::ExpectedBase; template , void*> = nullptr> constexpr Expected(U&& value) : detail::ExpectedBase(&std::forward(value)) {} template , void*> = nullptr> constexpr Expected(U&& other) { other.has_value() ? this->constructValueFrom(&std::forward(other).value()) : this->constructErrorFrom(std::forward(other)); } constexpr T& value() const { GXF_ASSERT(this->has_value(), "Expected does not have a value. Check before accessing."); return **ValuePointer(this->buffer_); } }; ///------------------------------------------------------------------------------------------------- /// Expected of Void Implementation ///------------------------------------------------------------------------------------------------- // Specialization of Expected for void. This is essentially an std::optional. template class Expected : public detail::ExpectedBase> { public: using detail::ExpectedBase::ExpectedBase; constexpr Expected() : detail::ExpectedBase(detail::Unit{}) {} // Constructor that allows assigning an Expected with the same error type to an Expected template explicit constexpr Expected(const Expected& other) { other.has_value() ? this->constructValueFrom() : this->constructErrorFrom(other); } // Constructor that allows assigning an Expected with the same error type to an Expected template explicit constexpr Expected(Expected&& other) { other.has_value() ? this->constructValueFrom() : this->constructErrorFrom(std::move(other)); } // Combines two expected value taking the first error. template Expected& operator&=(const Expected& other) { *this = *this & other; return *this; } // Combines two expected value taking the last success. template Expected& operator|=(const Expected& other) { *this = *this | other; return *this; } }; ///------------------------------------------------------------------------------------------------- /// Utility Functions ///------------------------------------------------------------------------------------------------- // Checks if all Expected values are not in error. If in error, return the first error found. template Expected AllOf(const Expected& expected) { return Expected{expected}; } // Checks if all Expected values are not in error. If in error, return the first error found. template Expected AllOf(const Expected& expected, const Expected&... others) { return expected & AllOf(others...); } // Checks if all the Arguments are of type Expected. If so, unwraps them and calls // the function object F with the unwrapped arguments. Otherwise, return an Unexpected with // the first error value found in the argument list. template auto Apply(F&& func, Args&&... args) -> EnableIf_t< Conjunction_v...>, decltype(detail::FunctorMap(func, args...)) > { const auto all_valid = AllOf(std::forward(args)...); if (!all_valid) { return Unexpected>(all_valid.error()); } return detail::FunctorMap(std::forward(func), std::forward(args)...); } ///------------------------------------------------------------------------------------------------- /// Comparison Operators ///------------------------------------------------------------------------------------------------- template constexpr bool operator==(const Expected& lhs, const Expected& rhs) { return ( lhs && rhs && (lhs.value() == rhs.value())) || (!lhs && !rhs && (lhs.error() == rhs.error())); } template constexpr bool operator==(const Expected& lhs, const U& rhs) { return lhs && (*lhs == rhs); } template constexpr bool operator==(const U& lhs, const Expected& rhs) { return rhs && (lhs == *rhs); } template constexpr bool operator==(const Expected& lhs, const Unexpected& rhs) { return !lhs && (lhs.error() == rhs.value()); } template constexpr bool operator==(const Unexpected& lhs, const Expected& rhs) { return !rhs && (lhs.value() == rhs.error()); } template constexpr bool operator==(const Unexpected& lhs, const Unexpected& rhs) { return lhs.value() == rhs.value(); } // All inequality operators are defined in terms of negated equality template constexpr bool operator!=(const Expected& lhs, const Expected& rhs) { return !(lhs == rhs); } template constexpr bool operator!=(const Expected& lhs, const U& rhs) { return !(lhs == rhs); } template constexpr bool operator!=(const U& lhs, const Expected& rhs) { return !(lhs == rhs); } template constexpr bool operator!=(const Unexpected& lhs, const Unexpected& rhs) { return !(lhs == rhs); } ///------------------------------------------------------------------------------------------------- /// Binary Logical Operators ///------------------------------------------------------------------------------------------------- // Combines two expected value taking the first error. template Expected operator&(const Expected& lhs, const Expected& rhs) { return !lhs ? Expected{lhs} : Expected{rhs}; } // Combines two expected value taking the last success. template Expected operator|(const Expected& lhs, const Expected& rhs) { return rhs ? Expected{rhs} : Expected{lhs}; } ///------------------------------------------------------------------------------------------------- /// Binary Arithmetic Operators ///------------------------------------------------------------------------------------------------- // Arithmetic operator+ for values stored in expected values. Returns either the computed value // or the first unexpected among lhs and rhs. template Expected operator+(const Expected& lhs, const Expected& rhs) { return Apply([](const V& lhs, const V& rhs) { return lhs + rhs; }, lhs, rhs); } template Expected operator+(const Expected& lhs, const V& rhs) { return lhs.map([&](const V& value) { return value + rhs; }); } template Expected operator+(const V& lhs, const Expected& rhs) { return rhs.map([&](const V& value) { return lhs + value; }); } // Arithmetic operator- for values stored in expected values. Returns either the computed value // or the first unexpected among lhs and rhs. template Expected operator-(const Expected& lhs, const Expected& rhs) { return Apply([](const V& lhs, const V& rhs) { return lhs - rhs; }, lhs, rhs); } template Expected operator-(const Expected& lhs, const V& rhs) { return lhs.map([&](const V& value) { return value - rhs; }); } template Expected operator-(const V& lhs, const Expected& rhs) { return rhs.map([&](const V& value) { return lhs - value; }); } // Arithmetic operator* for values stored in expected values. Returns either the computed value // or the first unexpected among lhs and rhs. template Expected operator*(const Expected& lhs, const Expected& rhs) { return Apply([](const V& lhs, const V& rhs) { return lhs * rhs; }, lhs, rhs); } template Expected operator*(const Expected& lhs, const V& rhs) { return lhs.map([&](const V& value) { return value * rhs; }); } template Expected operator*(const V& lhs, const Expected& rhs) { return rhs.map([&](const V& value) { return lhs * value; }); } // Arithmetic operator/ for values stored in expected values. Returns either the computed value // or the first unexpected among lhs and rhs. template Expected operator/(const Expected& lhs, const Expected& rhs) { return Apply([](const V& lhs, const V& rhs) { return lhs / rhs; }, lhs, rhs); } template Expected operator/(const Expected& lhs, const V& rhs) { return lhs.map([&](const V& value) { return value / rhs; }); } template Expected operator/(const V& lhs, const Expected& rhs) { return rhs.map([&](const V& value) { return lhs / value; }); } // Arithmetic operator% for values stored in expected values. Returns either the computed value // or the first unexpected among lhs and rhs. template Expected operator%(const Expected& lhs, const Expected& rhs) { return Apply([](const V& lhs, const V& rhs) { return lhs % rhs; }, lhs, rhs); } template Expected operator%(const Expected& lhs, const V& rhs) { return lhs.map([&](const V& value) { return value % rhs; }); } template Expected operator%(const V& lhs, const Expected& rhs) { return rhs.map([&](const V& value) { return lhs % value; }); } } // namespace nvidia #endif // NVIDIA_COMMON_EXPECTED_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/fixed_map.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_COMMON_FIXED_MAP_HPP_ #define NVIDIA_GXF_COMMON_FIXED_MAP_HPP_ #include #include #include "common/expected.hpp" #include "common/memory_utils.hpp" #include "common/type_utils.hpp" namespace nvidia { // Data structure that provides similar functionality to std::unordered_map but does not dynamically // reallocate memory and uses Expected type for error handling instead of exceptions. // This container is not thread-safe. template > class FixedMap { public: template class Iterator; template class ReverseIterator; template using ConstIterator = Iterator; // Use STL naming convention for compatibility with STL algorithms using key_type = Key; using mapped_type = T; using value_type = std::pair; using size_type = size_t; using iterator = Iterator; using reverse_iterator = ReverseIterator; using const_iterator = ConstIterator; using const_reverse_iterator = ReverseIterator; // Custom error codes for map enum struct Error { kOutOfMemory, // Memory allocation failed kInvalidKey, // Key is not in container kDuplicateKey, // Key is already in container kContainerFull, // Container is full kInvalidIterator, // Iterator is invalid }; // Expected type which uses class specific errors template using Expected = Expected; template class Iterator { public: static_assert(IsSame_v, FixedMap>); // iterator traits using iterator_category = std::bidirectional_iterator_tag; using value_type = TValue; using difference_type = std::ptrdiff_t; using pointer = TValue*; using reference = TValue&; constexpr Iterator() : container_{nullptr}, index_{-1} {} constexpr Iterator(TContainer& container, size_t start) : container_{&container}, index_{0} { *this += start; } constexpr Iterator(const Iterator& other) = default; constexpr Iterator(Iterator&& other) = default; constexpr Iterator& operator=(const Iterator& other) = default; constexpr Iterator& operator=(Iterator&& other) = default; constexpr Expected operator*() const { if (container_ == nullptr || container_->data_ == nullptr || index_ < 0 || index_ >= static_cast(container_->capacity_)) { return Unexpected{Error::kInvalidIterator}; } Bucket& bucket = container_->data_[index_]; if (!bucket.occupied) { return Unexpected{Error::kInvalidIterator}; } return bucket.value; } constexpr Iterator& operator+=(difference_type offset) { if (container_ == nullptr || container_->data_ == nullptr) { return *this; } while (true) { const Bucket& bucket = container_->data_[index_]; if (bucket.occupied) { break; } index_++; if (index_ >= static_cast(container_->capacity_)) { break; } } if ((offset > 0 && index_ >= static_cast(container_->capacity_)) || (offset < 0 && index_ <= 0)) { return *this; } while (offset > 0) { index_++; if (index_ >= static_cast(container_->capacity_)) { break; } const Bucket& bucket = container_->data_[index_]; if (bucket.occupied) { offset--; } } while (offset < 0) { index_--; if (index_ <= 0) { break; } const Bucket& bucket = container_->data_[index_]; if (bucket.occupied) { offset++; } } return *this; } constexpr Iterator& operator++() { *this += 1; return *this; } constexpr Iterator operator++(int) { Iterator iter = *this; ++(*this); return iter; } constexpr Iterator& operator-=(difference_type offset) { *this += -offset; return *this; } constexpr Iterator& operator--() { *this -= 1; return *this; } constexpr Iterator operator--(int) { Iterator iter = *this; --(*this); return iter; } friend constexpr Iterator operator+(Iterator a, difference_type n) { a += n; return a; } friend constexpr Iterator operator+(difference_type n, Iterator a) { return a + n; } friend constexpr Iterator operator-(Iterator a, difference_type n) { a -= n; return a; } friend constexpr difference_type operator-(const Iterator& a, const Iterator& b) { return a.index_ - b.index_; } friend constexpr bool operator==(const Iterator& a, const Iterator& b) { return a.container_ == b.container_ && a.index_ == b.index_; } friend constexpr bool operator!=(const Iterator& a, const Iterator& b) { return !(a == b); } private: // Container pointer TContainer* container_; // Iterator index difference_type index_; }; template class ReverseIterator { public: static_assert(IsSame_v || IsSame_v); using TValue = typename TIterator::value_type; // iterator traits using iterator_category = std::bidirectional_iterator_tag; using value_type = TValue; using difference_type = std::ptrdiff_t; using pointer = TValue*; using reference = TValue&; constexpr explicit ReverseIterator() : iter_{} {} constexpr explicit ReverseIterator(TIterator iter) : iter_{iter} {} constexpr ReverseIterator(const ReverseIterator& other) = default; constexpr ReverseIterator(ReverseIterator&& other) = default; constexpr ReverseIterator& operator=(const ReverseIterator& other) = default; constexpr ReverseIterator& operator=(ReverseIterator&& other) = default; constexpr TIterator base() const { return iter_; } constexpr Expected operator*() const { return *std::prev(iter_); } constexpr ReverseIterator& operator+=(difference_type offset) { iter_ -= offset; return *this; } constexpr ReverseIterator& operator++() { iter_ -= 1; return *this; } constexpr ReverseIterator operator++(int) { ReverseIterator iter = *this; ++(*this); return iter; } constexpr ReverseIterator& operator-=(difference_type offset) { iter_ += offset; return *this; } constexpr ReverseIterator& operator--() { iter_ += 1; return *this; } constexpr ReverseIterator operator--(int) { ReverseIterator iter = *this; --(*this); return iter; } friend constexpr ReverseIterator operator+(ReverseIterator a, difference_type n) { return ReverseIterator(a.iter_ - n); } friend constexpr ReverseIterator operator+(difference_type n, ReverseIterator a) { return ReverseIterator(a.iter_ - n); } friend constexpr ReverseIterator operator-(ReverseIterator a, difference_type n) { return ReverseIterator(a.iter_ + n); } friend constexpr difference_type operator-(const ReverseIterator& a, const ReverseIterator& b) { return b.iter_ - a.iter_; } friend constexpr bool operator==(const ReverseIterator& a, const ReverseIterator& b) { return a.iter_ == b.iter_; } friend constexpr bool operator!=(const ReverseIterator& a, const ReverseIterator& b) { return !(a == b); } private: /// Random-access iterator TIterator iter_; }; FixedMap() : data_{nullptr}, capacity_{0}, size_{0} {} FixedMap(const FixedMap& other) = delete; FixedMap(FixedMap&& other) : data_{nullptr}, capacity_{0}, size_{0} { *this = std::move(other); } FixedMap& operator=(const FixedMap& other) = delete; FixedMap& operator=(FixedMap&& other) { if (this != &other) { std::swap(data_, other.data_); std::swap(capacity_, other.capacity_); std::swap(size_, other.size_); } return *this; } ~FixedMap() { clear(); DeallocateArray(data_); } bool operator==(const FixedMap& other) const { if ((capacity_ != other.capacity_) || (size_ != other.size_)) { return false; } for (size_type i = 0; i < capacity_; i++) { if (data_[i].occupied) { if (!other.data_[i].occupied || (data_[i].value != other.data_[i].value)) { return false; } } } return true; } bool operator!=(const FixedMap& other) const { return !(*this == other); } constexpr iterator begin() { return iterator(*this, 0); } constexpr iterator end() { return iterator(*this, size_); } constexpr reverse_iterator rbegin() { return reverse_iterator(end()); } constexpr reverse_iterator rend() { return reverse_iterator(begin()); } constexpr const_iterator begin() const { return cbegin(); } constexpr const_iterator end() const { return cend(); } constexpr const_reverse_iterator rbegin() const { return crbegin(); } constexpr const_reverse_iterator rend() const { return crend(); } constexpr const_iterator cbegin() const { return const_iterator(*this, 0); } constexpr const_iterator cend() const { return const_iterator(*this, size_); } constexpr const_reverse_iterator crbegin() const { return const_reverse_iterator(cend()); } constexpr const_reverse_iterator crend() const { return const_reverse_iterator(cbegin()); } Expected operator[](const key_type& key) { Bucket* bucket = findMatchingBucket(key); if (!bucket) { auto result = emplace(std::make_pair(key, mapped_type())); if (!result) { return Unexpected{result.error()}; } bucket = findMatchingBucket(key); if (!bucket) { return Unexpected{Error::kInvalidKey}; } } return bucket->value.second; } // Returns the number of elements the container can currently hold size_type capacity() const { return capacity_; } // Returns the number of elements in the container size_type size() const { return size_; } // Returns true if the container has no elements bool empty() const { return size_ == 0; } // Returns true if the container has reached capacity bool full() const { return size_ == capacity_; } // Returns the load factor of the container double load_factor() const { return capacity_ > 0 ? static_cast(size_) / static_cast(capacity_) : 0.0; } // Checks if the container has a value for the given key bool contains(const key_type& key) const { return findMatchingBucket(key) != nullptr; } // Returns a reference to the value at the given key Expected at(const key_type& key) { Bucket* bucket = findMatchingBucket(key); if (!bucket) { return Unexpected{Error::kInvalidKey}; } return bucket->value.second; } // Returns a read-only reference to the value with the given key Expected at(const key_type& key) const { Bucket* bucket = findMatchingBucket(key); if (!bucket) { return Unexpected{Error::kInvalidKey}; } return bucket->value.second; } // Update a key that is already in the map Expected update(const key_type& key, const mapped_type& value) { Bucket* bucket = findMatchingBucket(key); if (!bucket) { return Unexpected{Error::kInvalidKey}; } bucket->value.second = value; return kSuccess; } // Assigns an the value to the given key if it exists, else creates a new object template Expected insert_or_assign(Args&&... args) { value_type value(std::forward(args)...); Bucket* bucket = findMatchingBucket(value.first); if (bucket) { bucket->value.second = value.second; return kSuccess; } else { return emplace(std::move(value)); } } // Creates a new object with the provided arguments and adds it using the given key template Expected emplace(Args&&... args) { value_type value(std::forward(args)...); if (findMatchingBucket(value.first)) { return Unexpected{Error::kDuplicateKey}; } Bucket* bucket = findEmptyBucket(value.first); if (!bucket) { return Unexpected{Error::kContainerFull}; } InplaceMoveConstruct(BytePointer(&bucket->value), std::move(value)); bucket->occupied = true; size_++; return kSuccess; } // Copies the object with the given key Expected insert(const value_type& value) { return emplace(value); } // Moves the object with the given key Expected insert(value_type&& value) { return emplace(std::forward(value)); } // Removes the object at the given key and destroys it Expected erase(const key_type& key) { Bucket* bucket = findMatchingBucket(key); if (!bucket) { return Unexpected{Error::kInvalidKey}; } Destruct(BytePointer(&bucket->value)); bucket->occupied = false; size_--; return kSuccess; } // Removes all objects from the vector void clear() { for (size_type i = 0; i < capacity_; i++) { Bucket* bucket = &data_[i]; if (bucket->occupied) { Destruct(BytePointer(&bucket->value)); bucket->occupied = false; } } size_ = 0; } // Allocates memory to hold the specified number of elements Expected reserve(size_type capacity) { if (capacity > capacity_) { Bucket* const temp_data = data_; const size_type temp_capacity = capacity_; const size_type temp_size = size_; data_ = AllocateArray(capacity); capacity_ = capacity; size_ = 0; if (data_ == nullptr) { data_ = temp_data; capacity_ = temp_capacity; size_ = temp_size; return Unexpected{Error::kOutOfMemory}; } for (size_type i = 0; i < capacity_; i++) { data_[i].occupied = false; } for (size_type i = 0; i < temp_capacity; i++) { Bucket* bucket = &temp_data[i]; if (bucket->occupied) { auto result = emplace(std::move(bucket->value)); if (!result) { return Unexpected{result.error()}; } } } DeallocateArray(temp_data); } return kSuccess; } // Copies the contents of the given map // Current contents are discarded // Fails if given map is larger than current capacity Expected copy_from(const FixedMap& other) { if (other.size_ > capacity_) { return Unexpected{Error::kContainerFull}; } clear(); for (size_type i = 0; i < other.capacity_; i++) { Bucket* bucket = &other.data_[i]; if (bucket->occupied) { auto result = emplace(bucket->value.first, bucket->value.second); if (!result) { return Unexpected{result.error()}; } } } return kSuccess; } private: // Container for a key-value pair struct Bucket { value_type value; bool occupied; }; // Searches for a matching bucket with the given key Bucket* findMatchingBucket(const key_type& key) const { if (capacity_ == 0) { return nullptr; } size_type index = hash(key); const size_type start = index; Bucket* bucket = &data_[index]; // Look for a matching bucket while (bucket->occupied) { if (bucket->value.first == key) { return bucket; } index = (index + 1) % capacity_; bucket = &data_[index]; if (index == start) { return nullptr; } } return nullptr; } // Searches for an empty bucket with the given key Bucket* findEmptyBucket(const key_type& key) const { if (capacity_ == 0) { return nullptr; } size_type index = hash(key); const size_type start = index; Bucket* bucket = &data_[index]; // Look for an empty bucket while (bucket->occupied) { index = (index + 1) % capacity_; bucket = &data_[index]; if (index == start) { return nullptr; } } return bucket; } // Computes a hash of the given key that can be used as a table index size_type hash(const key_type& key) const { return Hash{}(key) % capacity_; } // Special value for returning a success const Expected kSuccess{}; // Pointer to an array of entries Bucket* data_; // Maximum number of entries the container can hold size_type capacity_; // Number of entries stored size_type size_; }; } // namespace nvidia #endif // NVIDIA_GXF_COMMON_FIXED_MAP_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/fixed_string.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_COMMON_FIXED_STRING_HPP_ #define NVIDIA_GXF_COMMON_FIXED_STRING_HPP_ #include #include #include "common/expected.hpp" #include "common/iterator.hpp" #include "common/type_utils.hpp" namespace nvidia { // Safety container that substitutes std::string and uses Expected for error handling. // Uses a fixed-size buffer allocated on the stack for storage. template class FixedString { public: // Use STL naming convention for compatibility with STL algorithms using value_type = char; using size_type = size_t; using const_iterator = ConstRandomAccessIterator; using const_reverse_iterator = ReverseIterator; // Hash support struct Hash { template size_t operator()(const FixedString& str) const { return std::_Hash_impl::hash(str.data(), str.size()); } }; // Custom error codes for container enum struct Error { kArgumentNull, kExceedingPreallocatedSize, }; // Expected type which uses class specific errors template using Expected = Expected; // Constructors constexpr FixedString() { clear(); } template constexpr FixedString(const char (&str)[M]) { copy(str); } template constexpr FixedString(const FixedString& str) { copy(str); } // Assignment operators template constexpr FixedString& operator=(const char (&other)[M]) { copy(other); return *this; } template constexpr FixedString& operator=(const FixedString& other) { copy(other); return *this; } // ISO standards state the assignment operator for M = N cannot be a template constexpr FixedString& operator=(const FixedString& other) { copy(other); return *this; } constexpr const_iterator begin() const { return cbegin(); } constexpr const_iterator end() const { return cend(); } constexpr const_reverse_iterator rbegin() const { return crbegin(); } constexpr const_reverse_iterator rend() const { return crend(); } constexpr const_iterator cbegin() const { return const_iterator(*this, 0); } constexpr const_iterator cend() const { return const_iterator(*this, size_); } constexpr const_reverse_iterator crbegin() const { return const_reverse_iterator(cend()); } constexpr const_reverse_iterator crend() const { return const_reverse_iterator(cbegin()); } // Comparison operators template constexpr bool operator==(const char (&other)[M]) const { return compare(other) == 0; } template constexpr bool operator==(const FixedString& other) const { return compare(other) == 0; } template constexpr bool operator!=(const char (&other)[M]) const { return !(*this == other); } template constexpr bool operator!=(const FixedString& other) const { return !(*this == other); } template constexpr bool operator<(const char (&other)[M]) const { return compare(other) < 0; } template constexpr bool operator<(const FixedString& other) const { return compare(other) < 0; } template constexpr bool operator<=(const char (&other)[M]) const { return compare(other) <= 0; } template constexpr bool operator<=(const FixedString& other) const { return compare(other) <= 0; } template constexpr bool operator>(const char (&other)[M]) const { return !(*this <= other); } template constexpr bool operator>(const FixedString other) const { return !(*this <= other); } template constexpr bool operator>=(const char (&other)[M]) const { return !(*this < other); } template constexpr bool operator>=(const FixedString other) const { return !(*this < other); } // Returns the length of the string excluding the null terminator constexpr size_t size() const { return size_; } constexpr size_t length() const { return size_; } // Returns the number of characters the string can store excluding the null terminator constexpr size_t max_size() const { return kMaxSize; } // Returns the number of characters the string can store including the null terminator constexpr size_t capacity() const { return kCapacity; } // Returns true if the string is empty constexpr bool empty() const { return size_ == 0; } // Returns true if the string is full constexpr bool full() const { return size_ == kMaxSize; } // Returns a pointer to a null-terminated array of characters constexpr AddLvalueReference_t data() const { return data_; } constexpr AddLvalueReference_t c_str() const { return data_; } // Clears the string constexpr void clear() { size_ = 0; data_[size_] = '\0'; } // Appends a C-string to the end of the string constexpr Expected append(const char* str, size_t size) { if (str == nullptr) { return Unexpected{Error::kArgumentNull}; } const size_t length = strnlen(str, size); if (size_ + length > kMaxSize) { return Unexpected{Error::kExceedingPreallocatedSize}; } std::memcpy(&data_[size_], str, length); size_ += length; data_[size_] = '\0'; return kSuccess; } // Appends a character array to the end of the string template constexpr Expected append(const char (&str)[M]) { return append(str, M); } // Appends a fixed string to the end of the string template constexpr Expected append(const FixedString& str) { return append(str.data(), str.size()); } // Appends a character to the end of the string constexpr Expected append(char c) { return append(&c, 1); } // Copies a C-string to the string constexpr Expected copy(const char* str, size_t size) { clear(); return append(str, size); } // Copies a character array to the string template constexpr void copy(const char (&str)[M]) { static_assert(M <= kMaxSize, "Exceeding container capacity"); copy(str, M); } // Copies a fixed string to the string template constexpr void copy(const FixedString& str) { static_assert(M <= kMaxSize, "Exceeding container capacity"); copy(str.data(), str.size()); } // Compares string to a character array template constexpr int compare(const char (&str)[M]) const { const size_t length = strnlen(str, M); const int result = std::strncmp(data_, str, std::min(size_, length)); if (result != 0) { return result; } if (length > size_) { return -1; } if (length < size_) { return 1; } return 0; } // Compares string to a fixed string template constexpr int compare(const FixedString& str) const { return compare(str.data()); } private: // Storage capacity static constexpr size_t kCapacity = N + 1; // Maximum length of the string static constexpr size_t kMaxSize = N; // Special value for returning a success const Expected kSuccess{}; // String length size_t size_; // Data buffer char data_[kCapacity]; }; } // namespace nvidia #endif // NVIDIA_GXF_COMMON_FIXED_STRING_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/fixed_vector.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_COMMON_FIXED_VECTOR_HPP_ #define NVIDIA_GXF_COMMON_FIXED_VECTOR_HPP_ #include #include #include "common/byte.hpp" #include "common/expected.hpp" #include "common/iterator.hpp" #include "common/memory_utils.hpp" namespace nvidia { // Data structure that provides similar functionality to std::vector but does not dynamically // reallocate memory and uses Expected type for error handling instead of exceptions. // This container is not thread-safe. // // This container supports allocating memory on the stack or on the heap. If the template argument // N is specified and greater than 0, a container with a capacity of N will be created on the stack. // The stack allocated container cannot be resized after it is initialized. The heap allocated // container must use the reserve function to allocate memory before use. It does not support // copy assignment or construction. // Base implementation template class FixedVectorBase { public: // Use STL naming convention for compatibility with STL algorithms using value_type = T; using size_type = size_t; using iterator = RandomAccessIterator; using reverse_iterator = ReverseIterator; using const_iterator = ConstRandomAccessIterator; using const_reverse_iterator = ReverseIterator; virtual ~FixedVectorBase() = default; // Custom error codes for vector enum struct Error { kOutOfMemory, // Memory allocation failed kArgumentOutOfRange, // Argument is out of valid range kContainerEmpty, // Container is empty kContainerFull, // Container is fixed and reached max capacity kInvalidIterator, // Iterator is invalid }; // Expected type which uses class specific errors template using Expected = Expected; constexpr bool operator==(const FixedVectorBase& other) const { if (size_ != other.size_) { return false; } if (data_ == other.data_) { return true; } for (size_t i = 0; i < size_; i ++) { if (data_[i] != other.data_[i]) { return false; } } return true; } constexpr bool operator!=(const FixedVectorBase& other) const { return !(*this == other); } constexpr iterator begin() { return iterator(*this, 0); } constexpr iterator end() { return iterator(*this, size_); } constexpr reverse_iterator rbegin() { return reverse_iterator(end()); } constexpr reverse_iterator rend() { return reverse_iterator(begin()); } constexpr const_iterator begin() const { return cbegin(); } constexpr const_iterator end() const { return cend(); } constexpr const_reverse_iterator rbegin() const { return crbegin(); } constexpr const_reverse_iterator rend() const { return crend(); } constexpr const_iterator cbegin() const { return const_iterator(*this, 0); } constexpr const_iterator cend() const { return const_iterator(*this, size_); } constexpr const_reverse_iterator crbegin() const { return const_reverse_iterator(cend()); } constexpr const_reverse_iterator crend() const { return const_reverse_iterator(cbegin()); } constexpr Expected operator[](size_t index) { return at(index); } constexpr Expected operator[](size_t index) const { return at(index); } // Returns a pointer to data constexpr T* data() { return data_; } // Returns a read-only pointer to data constexpr const T* data() const { return data_; } // Returns the number of elements the vector can currently hold constexpr size_t capacity() const { return capacity_; } // Returns the number of elements in the vector constexpr size_t size() const { return size_; } // Returns true if the vector contains no elements constexpr bool empty() const { return size_ == 0; } // Returns true if the vector reached capacity constexpr bool full() const { return size_ == capacity_; } // Returns a reference to the element at the given index constexpr Expected at(size_t index) { if (index >= size_) { return Unexpected{Error::kArgumentOutOfRange}; } return data_[index]; } // Returns a read-only reference to the element at the given index constexpr Expected at(size_t index) const { if (index >= size_) { return Unexpected{Error::kArgumentOutOfRange}; } return data_[index]; } // Returns a reference to the first element constexpr Expected front() { if (empty()) { return Unexpected{Error::kContainerEmpty}; } return data_[0]; } // Returns a read-only reference to the first element constexpr Expected front() const { if (empty()) { return Unexpected{Error::kContainerEmpty}; } return data_[0]; } // Returns a reference to the last element constexpr Expected back() { if (empty()) { return Unexpected{Error::kContainerEmpty}; } return data_[size_ - 1]; } // Returns a read-only reference to the last element constexpr Expected back() const { if (empty()) { return Unexpected{Error::kContainerEmpty}; } return data_[size_ - 1]; } // Creates a new object with the provided arguments and adds it at the specified index template constexpr Expected emplace(size_t index, Args&&... args) { if (index > size_) { return Unexpected{Error::kArgumentOutOfRange}; } if (full()) { return Unexpected{Error::kContainerFull}; } if (index < size_) { ArrayMoveConstruct(BytePointer(&data_[index + 1]), &data_[index], size_ - index); } InplaceConstruct(BytePointer(&data_[index]), std::forward(args)...); size_++; return kSuccess; } // Creates a new object with the provided arguments and adds it to the end of the vector template constexpr Expected emplace_back(Args&&... args) { return emplace(size_, std::forward(args)...); } // Copies the object to the specified index constexpr Expected insert(size_t index, const T& obj) { return emplace(index, obj); } // Moves the object to the specified index constexpr Expected insert(size_t index, T&& obj) { return emplace(index, std::forward(obj)); } // Insert elements from another fixed vector object to the specified index constexpr Expected insert(iterator index, const_iterator start, const_iterator end) { ssize_t count = static_cast(std::distance(start, end)); size_t pos = static_cast(std::distance(begin(), index)); if ((pos > size_) || (size_ + count > capacity_) || (count < 0)) { return Unexpected{Error::kArgumentOutOfRange}; } auto maybe_value = *start; if (maybe_value) { const T* ptr = &(*maybe_value); if (pos < size_) { ArrayCopyConstruct(BytePointer(data_ + pos + count), &data_[pos], size_ - pos); } ArrayCopyConstruct(BytePointer(data_ + pos), ptr, count); size_ += count; } else { return Unexpected{Error::kInvalidIterator}; } return kSuccess; } // Copies the object to the end of the vector constexpr Expected push_back(const T& obj) { return emplace_back(obj); } // Moves the object to the end of the vector constexpr Expected push_back(T&& obj) { return emplace_back(std::forward(obj)); } // Removes the object at the specified index and destroys it constexpr Expected erase(size_t index) { if (index >= size_) { return Unexpected{Error::kArgumentOutOfRange}; } if (empty()) { return Unexpected{Error::kContainerEmpty}; } Destruct(BytePointer(&data_[index])); size_--; if (index < size_) { ArrayMoveConstruct(BytePointer(&data_[index]), &data_[index + 1], size_ - index); } return kSuccess; } // Removes the object at the end of the vector and destroys it constexpr Expected pop_back() { return erase(size_ - 1); } // Removes all objects from the vector constexpr void clear() { while (size_ > 0) { Destruct(BytePointer(&data_[--size_])); } } // Resizes the vector by removing objects from the end if shrinking // or by adding default objects to the end if expanding constexpr Expected resize(size_t count) { if (count > capacity_) { return Unexpected{Error::kArgumentOutOfRange}; } while (count > size_) { push_back(T()); } while (count < size_) { pop_back(); } return kSuccess; } // Resizes the vector by removing objects from the end if shrinking // or by adding copies of the given object to the end if expanding constexpr Expected resize(size_t count, const T& obj) { if (count > capacity_) { return Unexpected{Error::kArgumentOutOfRange}; } while (count > size_) { push_back(obj); } while (count < size_) { pop_back(); } return kSuccess; } protected: // Special value for returning a success const Expected kSuccess{}; FixedVectorBase() : data_{nullptr}, capacity_{0}, size_{0} {}; // Pointer to an array of objects T* data_; // Maximum number of objects the container can hold size_t capacity_; // Number of objects stored size_t size_; }; // Special value used to instantiate a FixedVector with heap memory allocation constexpr ssize_t kFixedVectorHeap = -1; // Vector with stack memory allocation template class FixedVector : public FixedVectorBase { public: static_assert(N >= 0, "N must be non-negative"); constexpr FixedVector() { data_ = ValuePointer(pool_); capacity_ = N; } constexpr FixedVector(const FixedVector& other) { *this = other; } constexpr FixedVector(FixedVector&& other) { *this = std::move(other); } constexpr FixedVector& operator=(const FixedVector& other) { if (this != &other) { data_ = ValuePointer(pool_); capacity_ = N; ArrayCopyConstruct(BytePointer(data_), other.data_, other.size_); size_ = other.size_; } return *this; } constexpr FixedVector& operator=(FixedVector&& other) { if (this != &other) { data_ = ValuePointer(pool_); capacity_ = N; ArrayMoveConstruct(BytePointer(data_), other.data_, other.size_); std::swap(size_, other.size_); } return *this; } ~FixedVector() { FixedVectorBase::clear(); } private: using FixedVectorBase::data_; using FixedVectorBase::capacity_; using FixedVectorBase::size_; // Size of memory pool for stack allocation static constexpr size_t kPoolSize = N * sizeof(T); // Memory pool for storing objects on the stack byte pool_[kPoolSize]; }; // Vector with heap memory allocation template class FixedVector : public FixedVectorBase { public: template using Expected = typename FixedVectorBase::template Expected; constexpr FixedVector() = default; constexpr FixedVector(const FixedVector& other) = delete; constexpr FixedVector(FixedVector&& other) { *this = std::move(other); } constexpr FixedVector& operator=(const FixedVector& other) = delete; constexpr FixedVector& operator=(FixedVector&& other) { if (this != &other) { std::swap(data_, other.data_); std::swap(capacity_, other.capacity_); std::swap(size_, other.size_); } return *this; } ~FixedVector() { FixedVectorBase::clear(); DeallocateArray(data_); } // Copies the contents of the given vector // Current contents are discarded // Fails if given vector is larger than current capacity constexpr Expected copy_from(const FixedVector& other) { if (other.size_ > capacity_) { return Unexpected{Error::kArgumentOutOfRange}; } FixedVectorBase::clear(); size_ = other.size_; ArrayCopyConstruct(BytePointer(data_), other.data_, size_); return kSuccess; } // Allocates memory to hold the specified number of elements constexpr Expected reserve(size_t capacity) { if (capacity > capacity_) { T* data = AllocateArray(capacity); if (!data) { return Unexpected{Error::kOutOfMemory}; } ArrayMoveConstruct(BytePointer(data), data_, size_); DeallocateArray(data_); data_ = data; capacity_ = capacity; } return kSuccess; } // Shrinks memory allocation to fit current number of elements constexpr Expected shrink_to_fit() { if (size_ < capacity_) { T* data = AllocateArray(size_); if (!data) { return Unexpected(Error::kOutOfMemory); } ArrayMoveConstruct(BytePointer(data), data_, size_); DeallocateArray(data_); data_ = data; capacity_ = size_; } return kSuccess; } private: using Error = typename FixedVectorBase::Error; using FixedVectorBase::kSuccess; using FixedVectorBase::data_; using FixedVectorBase::capacity_; using FixedVectorBase::size_; }; } // namespace nvidia #endif // NVIDIA_GXF_COMMON_FIXED_VECTOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/iterator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_COMMON_ITERATOR_HPP_ #define NVIDIA_GXF_COMMON_ITERATOR_HPP_ #include #include "common/expected.hpp" #include "common/type_utils.hpp" namespace nvidia { namespace detail { /// Type traits to determine if a type has `data()` template struct HasData : FalseType {}; template struct HasData().data())>> : TrueType {}; template constexpr bool HasData_v = HasData::value; /// Type traits to determine if a type has `size()` template struct HasSize : FalseType {}; template struct HasSize().size())>> : TrueType {}; template constexpr bool HasSize_v = HasSize::value; } // namespace detail /// Random-access iterator for containers with elements in contiguous memory. /// A pointer to the container is stored so the iterator does not get invalidated if elements are /// added and/or removed from the container. Incrementing/decrementing operations will saturate /// if the iterator reaches the end/beginning of the container. Element access is wrapped in /// an `Expected` to prevent dereferencing invalid memory. template class RandomAccessIterator { static_assert(detail::HasData_v, "TContainer must have data()"); static_assert(detail::HasSize_v, "TContainer must have size()"); static_assert(IsIntegral_v().size())>, "size() must return an integral type"); public: enum struct Error { kArgumentOutOfRange, kInvalidIterator, }; template using Expected = Expected; // iterator traits using iterator_category = std::random_access_iterator_tag; using value_type = TValue; using difference_type = std::ptrdiff_t; using pointer = TValue*; using reference = TValue&; constexpr RandomAccessIterator() : container_{nullptr}, index_{-1} {} constexpr RandomAccessIterator(TContainer& container, size_t start) : container_{&container}, index_{0} { *this += start; } template ::value && std::is_same::value, int>::type = 0> constexpr RandomAccessIterator(const RandomAccessIterator& other) : container_{other.container_}, index_{0} { *this += other.index_; } constexpr RandomAccessIterator(const RandomAccessIterator& other) = default; constexpr RandomAccessIterator(RandomAccessIterator&& other) = default; constexpr RandomAccessIterator& operator=(const RandomAccessIterator& other) = default; constexpr RandomAccessIterator& operator=(RandomAccessIterator&& other) = default; constexpr Expected operator*() const { return 0 <= index_ && index_ < static_cast(container_->size()) ? Expected{container_->data()[index_]} : Unexpected{Error::kInvalidIterator}; } constexpr Expected operator[](difference_type offset) const { if (container_ == nullptr) { return Unexpected{Error::kInvalidIterator}; } difference_type index = index_ + offset; return 0 <= index && index < static_cast(container_->size()) ? Expected{container_->data()[index]} : Unexpected{Error::kArgumentOutOfRange}; } constexpr RandomAccessIterator& operator+=(difference_type offset) { if (container_ == nullptr) { return *this; } difference_type index = index_ + offset; if (index < 0) { index = 0; } else if (index > static_cast(container_->size())) { index = container_->size(); } index_ = index; return *this; } constexpr RandomAccessIterator& operator++() { *this += 1; return *this; } constexpr RandomAccessIterator operator++(int) { RandomAccessIterator iter = *this; ++(*this); return iter; } constexpr RandomAccessIterator& operator-=(difference_type offset) { *this += -offset; return *this; } constexpr RandomAccessIterator& operator--() { *this -= 1; return *this; } constexpr RandomAccessIterator operator--(int) { RandomAccessIterator iter = *this; --(*this); return iter; } friend constexpr RandomAccessIterator operator+(RandomAccessIterator a, difference_type n) { a += n; return a; } friend constexpr RandomAccessIterator operator+(difference_type n, RandomAccessIterator a) { return a + n; } friend constexpr RandomAccessIterator operator-(RandomAccessIterator a, difference_type n) { a -= n; return a; } friend constexpr difference_type operator-(const RandomAccessIterator& a, const RandomAccessIterator& b) { return a.index_ - b.index_; } friend constexpr bool operator==(const RandomAccessIterator& a, const RandomAccessIterator& b) { return a.container_ == b.container_ && a.index_ == b.index_; } friend constexpr bool operator!=(const RandomAccessIterator& a, const RandomAccessIterator& b) { return !(a == b); } private: friend class RandomAccessIterator; /// Container pointer TContainer* container_; /// Iterator index difference_type index_; }; /// Constant Random-access iterator template using ConstRandomAccessIterator = RandomAccessIterator; /// Reverse iterator template class ReverseIterator { public: using TValue = typename TIterator::value_type; using Error = typename TIterator::Error; template using Expected = Expected; // iterator traits using iterator_category = std::random_access_iterator_tag; using value_type = TValue; using difference_type = std::ptrdiff_t; using pointer = TValue*; using reference = TValue&; constexpr explicit ReverseIterator() : iter_{} {} constexpr explicit ReverseIterator(TIterator iter) : iter_{iter} {} constexpr ReverseIterator(const ReverseIterator& other) = default; constexpr ReverseIterator(ReverseIterator&& other) = default; constexpr ReverseIterator& operator=(const ReverseIterator& other) = default; constexpr ReverseIterator& operator=(ReverseIterator&& other) = default; constexpr TIterator base() const { return iter_; } constexpr Expected operator*() const { return *std::prev(iter_); } constexpr Expected operator[](difference_type offset) const { return std::prev(iter_)[-offset]; } constexpr ReverseIterator& operator+=(difference_type offset) { iter_ -= offset; return *this; } constexpr ReverseIterator& operator++() { iter_ -= 1; return *this; } constexpr ReverseIterator operator++(int) { ReverseIterator iter = *this; ++(*this); return iter; } constexpr ReverseIterator& operator-=(difference_type offset) { iter_ += offset; return *this; } constexpr ReverseIterator& operator--() { iter_ += 1; return *this; } constexpr ReverseIterator operator--(int) { ReverseIterator iter = *this; --(*this); return iter; } friend constexpr ReverseIterator operator+(ReverseIterator a, difference_type n) { return ReverseIterator(a.iter_ - n); } friend constexpr ReverseIterator operator+(difference_type n, ReverseIterator a) { return ReverseIterator(a.iter_ - n); } friend constexpr ReverseIterator operator-(ReverseIterator a, difference_type n) { return ReverseIterator(a.iter_ + n); } friend constexpr difference_type operator-(const ReverseIterator& a, const ReverseIterator& b) { return b.iter_ - a.iter_; } friend constexpr bool operator==(const ReverseIterator& a, const ReverseIterator& b) { return a.iter_ == b.iter_; } friend constexpr bool operator!=(const ReverseIterator& a, const ReverseIterator& b) { return !(a == b); } private: /// Random-access iterator TIterator iter_; }; } // namespace nvidia #endif // NVIDIA_GXF_COMMON_ITERATOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/logger.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_LOGGER_HPP_ #define NVIDIA_COMMON_LOGGER_HPP_ #include #include #include #include "gxf/logger/gxf_logger.hpp" #define GXF_LOG_LEVEL_PANIC 0 #define GXF_LOG_LEVEL_ERROR 1 #define GXF_LOG_LEVEL_WARNING 2 #define GXF_LOG_LEVEL_INFO 3 #define GXF_LOG_LEVEL_DEBUG 4 #define GXF_LOG_LEVEL_VERBOSE 5 // clang-format off // Set the default active logging level to VERBOSE(5) if not defined #if !defined(GXF_LOG_ACTIVE_LEVEL) # define GXF_LOG_ACTIVE_LEVEL 5 // GXF_LOG_LEVEL_VERBOSE #endif // Define GXF_LOG_ACTIVE_LEVEL before including `common/logger.hpp` to control the logging level // at compile time. This allows you to skip logging at certain levels. // // Example: // #define GXF_LOG_ACTIVE_LEVEL 2 // #include "common/logger.hpp" // ... // // With this setting, logging will occur only at the WARNING(2), ERROR(1), and PANIC(0) levels. // // You can define GXF_LOG_ACTIVE_LEVEL in your build system. For instance, in CMake, use: // // target_compile_definitions(my_target PRIVATE GXF_LOG_ACTIVE_LEVEL=2) // // This sets the active logging level to WARNING(2) for the target `my_target`. // // Alternatively, define GXF_LOG_ACTIVE_LEVEL at compile time by passing `-DGXF_LOG_ACTIVE_LEVEL=2` // directly to the compiler. // // In the Bazel build system, set this in your build configuration as follows: // // cc_binary( // name = "my_binary", // srcs = ["my_binary.cc"], // copts = ["-DGXF_LOG_ACTIVE_LEVEL=2"], // ) // // This sets the active logging level to WARNING(2) for the target `my_binary`. // // Or, when using a Bazel build command: // bazel build --copt=-DGXF_LOG_ACTIVE_LEVEL=3 //path:to_your_target // // This sets the active logging level to INFO(3) for the target `//path:to_your_target`. // Logs a verbose message #if GXF_LOG_ACTIVE_LEVEL >= GXF_LOG_LEVEL_VERBOSE # define GXF_LOG_VERBOSE(...) \ ::nvidia::Log(__FILE__, __LINE__, ::nvidia::Severity::VERBOSE, __VA_ARGS__) #else # define GXF_LOG_VERBOSE(...) (void)0 #endif // Logs a debug message #if GXF_LOG_ACTIVE_LEVEL >= GXF_LOG_LEVEL_DEBUG # define GXF_LOG_DEBUG(...) \ ::nvidia::Log(__FILE__, __LINE__, ::nvidia::Severity::DEBUG, __VA_ARGS__) #else # define GXF_LOG_DEBUG(...) (void)0 #endif // Logs an informational message #if GXF_LOG_ACTIVE_LEVEL >= GXF_LOG_LEVEL_INFO # define GXF_LOG_INFO(...) \ ::nvidia::Log(__FILE__, __LINE__, ::nvidia::Severity::INFO, __VA_ARGS__) #else # define GXF_LOG_INFO(...) (void)0 #endif // Logs a warning #if GXF_LOG_ACTIVE_LEVEL >= GXF_LOG_LEVEL_WARNING # define GXF_LOG_WARNING(...) \ ::nvidia::Log(__FILE__, __LINE__, ::nvidia::Severity::WARNING, __VA_ARGS__) #else # define GXF_LOG_WARNING(...) (void)0 #endif // Logs an error #if GXF_LOG_ACTIVE_LEVEL >= GXF_LOG_LEVEL_ERROR # define GXF_LOG_ERROR(...) \ ::nvidia::Log(__FILE__, __LINE__, ::nvidia::Severity::ERROR, __VA_ARGS__) #else # define GXF_LOG_ERROR(...) (void)0 #endif // Logs a panic #if GXF_LOG_ACTIVE_LEVEL >= GXF_LOG_LEVEL_PANIC # define GXF_LOG_PANIC(...) \ ::nvidia::Log(__FILE__, __LINE__, ::nvidia::Severity::PANIC, __VA_ARGS__) #else # define GXF_LOG_PANIC(...) (void)0 #endif // clang-format on namespace nvidia { // Function which is used for logging. It can be changed to intercept the logged messages. // Additional arguments can be supplied via LoggingFunctionArg. extern void (*LoggingFunction)(const char* file, int line, Severity severity, const char* log, void* arg); extern void* LoggingFunctionArg; // Default implementation of the logging function which prints to console void DefaultConsoleLogging(const char* file, int line, Severity severity, const char* log, void* arg); // Redirects the output for a given log severity. void Redirect(std::FILE* file, Severity severity = Severity::ALL); // Sets the log severity from the environment variable. // If the environment variable is not set or invalid, the severity is not changed. // Returns true if the environment variable is accessible and the severity was updated from it. bool SetSeverityFromEnv(const char* env_name = kGxfLogEnvName); // Returns the log severity from the environment variable. // If the environment variable is not set or invalid, returns Severity::COUNT. // If 'error_code' is not null, it will be set to 1 if the environment variable is set but invalid, // or to 0 otherwise. Severity GetSeverityFromEnv(const char* env_name = kGxfLogEnvName, int* error_code = nullptr); // Sets global log severity thus effectively disabling all logging with lower severity void SetSeverity(Severity severity); // Returns global log severity Severity GetSeverity(); // Converts the message and argument into a string and pass it to LoggingFunction. template void Log(const char* file, int line, Severity severity, const char* txt, ...) __attribute__((format(printf, 4, 5))); // NOLINT template void Log(const char* file, int line, Severity severity, const char* txt, ...) { va_list args1; va_start(args1, txt); va_list args2; va_copy(args2, args1); std::vector buf(1 + std::vsnprintf(NULL, 0, txt, args1)); va_end(args1); auto buf_data = buf.data(); auto buf_size = buf.size(); std::vsnprintf(buf_data, buf_size, txt, args2); va_end(args2); logger::GxfLogger& logger = logger::GlobalGxfLogger::instance(); logger.log(file, line, nullptr, static_cast(severity), buf_data); } } // namespace nvidia #endif // NVIDIA_COMMON_LOGGER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/memory_utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_MEMORY_UTILS_HPP_ #define NVIDIA_COMMON_MEMORY_UTILS_HPP_ #include #include #include #include #include #include "common/byte.hpp" namespace nvidia { // Convert a raw byte pointer `src` to a concrete type T template T* ValuePointer(byte* src) { return reinterpret_cast(src); } // Convert a const raw byte pointer `src` to a concrete type T template const T* ValuePointer(const byte* src) { return reinterpret_cast(src); } // Convert a type T pointer `src` to a raw byte pointer template byte* BytePointer(T* src) { return reinterpret_cast(src); } // Convert a const type T pointer `src` to a raw byte pointer template const byte* BytePointer(const T* src) { return reinterpret_cast(src); } // Call the destructor for type T on the object located at `src`. template void Destruct(byte* src) { reinterpret_cast(src)->~T(); } // Construct an object of type T with the provided arguments into the memory at `dst` with // placement new operator. template T* InplaceConstruct(byte* dst, Args&&... args) { return new (dst) T{std::forward(args)...}; } // Move construct an object of type T into the memory at `dst` with placement new operator. template T* InplaceMoveConstruct(byte* dst, T&& other) { return new (dst) T{std::forward(other)}; } // Copy construct an object of type T into the memory at `dst` with placement new operator. template T* InplaceCopyConstruct(byte* dst, const T& other) { return new (dst) T{other}; } // Move constructs an array of objects of type T into the memory at `dst` // Used if object is movable template ::value>* = nullptr> void ArrayMoveConstruct(byte* dst, T* src, size_t count) { // Reverse move direction to handle overlapping memory segments const bool reverse = dst > BytePointer(src) && dst < BytePointer(src + count); for (size_t i = 0; i < count; i++) { const size_t index = reverse ? count - 1 - i : i; InplaceMoveConstruct(dst + sizeof(T) * index, std::move(src[index])); } } // Move constructs an array of objects of type T into the memory at `dst` // Used if object is not movable but trivially copyable template ::value && std::is_trivially_copyable::value>* = nullptr> void ArrayMoveConstruct(byte* dst, T* src, size_t count) { std::memmove(dst, src, sizeof(T) * count); } // Move constructs an array of objects of type T into the memory at `dst` // Used if object is not movable and not trivially copyable template ::value && !std::is_trivially_copyable::value>* = nullptr> void ArrayMoveConstruct(byte* dst, T* src, size_t count) { // Reverse move direction to handle overlapping memory segments const bool reverse = dst > BytePointer(src) && dst < BytePointer(src + count); for (size_t i = 0; i < count; i++) { const size_t index = reverse ? count - 1 - i : i; InplaceCopyConstruct(dst + sizeof(T) * index, src[index]); } } // Copy constructs an array of objects of type T into the memory at `dst` // Used if object is trivially copyable template ::value>* = nullptr> void ArrayCopyConstruct(byte* dst, T* src, size_t count) { std::memmove(dst, src, sizeof(T) * count); } // Copy constructs an array of objects of type T into the memory at `dst` // Used if object is not trivially copyable template ::value>* = nullptr> void ArrayCopyConstruct(byte* dst, T* src, size_t count) { // Reverse move direction to handle overlapping memory segments const bool reverse = dst > BytePointer(src) && dst < BytePointer(src + count); for (size_t i = 0; i < count; i++) { const size_t index = reverse ? count - 1 - i : i; InplaceCopyConstruct(dst + sizeof(T) * index, src[index]); } } // Allocates an array with `size` number of objects of type T // Does not call object constructor template T* AllocateArray(size_t size) { return static_cast(::operator new(size * sizeof(T), std::nothrow)); } // Deallocates the array `data` of objects of type T // Does not call object destructor template void DeallocateArray(T* data) { ::operator delete(data); } // Construct an object of type T with the provided arguments and returns a unique pointer to it // Null pointer is returned on error template std::unique_ptr MakeUniqueNoThrow(Args&&... args) { return std::unique_ptr(new(std::nothrow) T{std::forward(args)...}); } // Construct an object of type T with the provided arguments and returns a shared pointer to it // Null pointer is returned on error template std::shared_ptr MakeSharedNoThrow(Args&&... args) { return std::shared_ptr(new(std::nothrow) T{std::forward(args)...}); } } // namespace nvidia #endif // NVIDIA_COMMON_MEMORY_UTILS_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/nvtx_helper.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_NVTX_HELPER_HPP_ #define NVIDIA_COMMON_NVTX_HELPER_HPP_ #include #include "nvtx3/nvToolsExt.h" // Helper functions to create named color events for NVTX profiling inline nvtxEventAttributes_t CreateGreenEvent(const std::string& message, uint32_t category) { nvtxEventAttributes_t eventAttrib = {0}; eventAttrib.version = NVTX_VERSION; eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; eventAttrib.colorType = NVTX_COLOR_ARGB; eventAttrib.color = 0xFF76b900; // NVIDIA GREEN eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; eventAttrib.message.ascii = message.c_str(); eventAttrib.category = category; return eventAttrib; } inline nvtxEventAttributes_t CreateRedEvent(const std::string& message, uint32_t category) { nvtxEventAttributes_t eventAttrib = {0}; eventAttrib.version = NVTX_VERSION; eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; eventAttrib.colorType = NVTX_COLOR_ARGB; eventAttrib.color = 0xFFFe2712; // Red eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; eventAttrib.message.ascii = message.c_str(); eventAttrib.category = category; return eventAttrib; } inline nvtxEventAttributes_t CreateBlackEvent(const std::string& message, uint32_t category) { nvtxEventAttributes_t eventAttrib = {0}; eventAttrib.version = NVTX_VERSION; eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; eventAttrib.colorType = NVTX_COLOR_ARGB; eventAttrib.color = 0xFF010203; // Rich black eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; eventAttrib.message.ascii = message.c_str(); eventAttrib.category = category; return eventAttrib; } inline nvtxEventAttributes_t CreateBlueEvent(const std::string& message, uint32_t category) { nvtxEventAttributes_t eventAttrib = {0}; eventAttrib.version = NVTX_VERSION; eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; eventAttrib.colorType = NVTX_COLOR_ARGB; eventAttrib.color = 0xFF66a1fe; // Light Blue eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; eventAttrib.message.ascii = message.c_str(); eventAttrib.category = category; return eventAttrib; } #endif // NVIDIA_COMMON_NVTX_HELPER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/singleton.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_SINGLETON_HPP_ #define NVIDIA_COMMON_SINGLETON_HPP_ namespace gxf { // A singleton which supports creation at pre-execution time // Usage: For a class `MyType` with a member function `myMember` you can just write: // Singleton::Get().myMember(); // This will automatically create a singleton, i.e. return the same instance each time you call Get. // The constructor of MyType will be called at pre-execution time, i.e. before entering main. // If you use multiple singletons they will all be created at pre-execution time, but you should // not rely on a particular instantiation order. template struct Singleton { public: Singleton& operator=(Singleton&) = delete; // Get the singleton static T& Get() { static T singleton; Use(dummy_); return singleton; } private: // Helpers to force pre-execution time static void Use(const T&) {} static T& dummy_; }; // Force instantiation of the singleton at pre-execution time template T& Singleton::dummy_ = Singleton::Get(); } // namespace gxf #endif // NVIDIA_COMMON_SINGLETON_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/span.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_COMMON_SPAN_HPP_ #define NVIDIA_GXF_COMMON_SPAN_HPP_ #include "common/byte.hpp" #include "common/expected.hpp" #include "common/iterator.hpp" #include "common/type_utils.hpp" namespace nvidia { namespace detail { /// Type traits to enable comparing `Span` with `Span` template using EnableIfComparable_t = EnableIf_t< IsSame_v, RemoveConst_t> >; /// Type traits to determine if type stores elements in contiguous memory template using EnableIfContiguous_t = EnableIf_t, HasSize>>; } // namespace detail /// Container to hold a pointer and size for contiguous memory. /// `Span` can be passed between functions and components and ensures that the size of the array is /// always available and can be checked for safe memory access. `Span` only wraps existing memory. template class Span { public: using element_type = T; using value_type = RemoveCV_t; using size_type = size_t; using iterator = RandomAccessIterator; using reverse_iterator = ReverseIterator; /// Custom error codes for `Span` enum struct Error { kArgumentOutOfRange, kContainerEmpty, }; /// `Expected` which uses `Span::Error` template using Expected = Expected; constexpr Span(T* data, size_t size) : data_{data}, size_{data != nullptr ? size : 0} {} constexpr Span() : Span(nullptr, 0) {} template constexpr Span(T (&array)[N]) : Span(array, N) {} /// Conversion from other types that have `data()` and `size()` functions template > constexpr Span(U& other) : Span(other.data(), other.size()) {} /// Implicit conversion from `Span` to `Span` operator Span() const { return Span(data_, size_); } ~Span() = default; constexpr Span(const Span& other) = default; constexpr Span(Span&& other) = default; constexpr Span& operator=(const Span&) = default; constexpr Span& operator=(Span&&) = default; constexpr iterator begin() const { return iterator(*this, 0); } constexpr iterator end() const { return iterator(*this, size_); } constexpr reverse_iterator rbegin() const { return reverse_iterator(end()); } constexpr reverse_iterator rend() const { return reverse_iterator(begin()); } constexpr Expected operator[](size_t index) const { return at(index); } /// Returns a pointer to the underlying data constexpr T* data() const { return data_; } /// Returns the number of elements in the `Span` constexpr size_t size() const { return size_; } /// Returns the size of the `Span` in bytes constexpr size_t size_bytes() const { return size_ * sizeof(T); } /// Returns true if the `Span` has no elements constexpr bool empty() const { return size_ == 0; } /// Returns a reference to the element at `index` constexpr Expected at(size_t index) const { return index < size_ ? Expected{data_[index]} : Unexpected{Error::kArgumentOutOfRange}; } /// Returns a reference to the first element constexpr Expected front() const { return !empty() ? Expected{data_[0]} : Unexpected{Error::kContainerEmpty}; } /// Returns a reference to the last element constexpr Expected back() const { return !empty() ? Expected{data_[size_ - 1]} : Unexpected{Error::kContainerEmpty}; } /// Returns a `Span` consisting of `count` elements starting from `offset` constexpr Expected subspan(size_t offset, size_t count) const { return offset <= size_ && count <= size_ && offset + count <= size_ ? Expected{Span(data_ + offset, count)} : Unexpected{Error::kArgumentOutOfRange}; } /// Returns a `Span` starting from `offset` constexpr Expected subspan(size_t offset) const { return subspan(offset, size_ - offset); } /// Returns a `Span` consisting of the first `count` elements constexpr Expected first(size_t count) const { return subspan(0, count); } /// Returns a `Span` consisting of the last `count` elements constexpr Expected last(size_t count) const { return subspan(size_ - count, count); } private: /// Pointer to data T* data_; /// Size of data size_t size_; }; template > constexpr bool operator==(const Span& a, const Span& b) { if (a.size() != b.size()) { return false; } if (a.data() == b.data()) { return true; } for (size_t i = 0; i < a.size(); i++) { if (a.data()[i] != b.data()[i]) { return false; } } return true; } template > constexpr bool operator!=(const Span& a, const Span& b) { return !(a == b); } } // namespace nvidia #endif // NVIDIA_GXF_COMMON_SPAN_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/strong_type.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_COMMON_STRONG_TYPE_HPP_ #define NVIDIA_GXF_COMMON_STRONG_TYPE_HPP_ #include #include "common/type_utils.hpp" namespace nvidia { /// The base type for a /// [strong type](https://www.fluentcpp.com/2016/12/08/strong-types-for-strong-interfaces). /// It is useful for making lightweight types which are distinct. Unlike type aliases /// (@c typedef or @c using), two @c StrongType types are not substitutable, even if the /// backing type is the same. /// /// The primary use case for this type is numeric identifiers. For example, imagine a sensor /// system where the sensor is identified by a @c uint32_t. Beyond being a 32-bit integer, this /// value shares almost no properties with the C type. Arithmetic and bit shifts do not make a /// lot of sense for this value -- there is no meaning to the result of multiplication between /// two sensor IDs. Comparing a sensor ID to any non-sensor ID value is probably a bug. By /// wrapping ID values into a dedicated @c SensorId @c StrongType, this behavior is prevented. /// /// @code /// // Create two types: Foo and Bar, both wrapping a uint64_t /// using Foo = StrongType; /// using Bar = StrongType; /// /// void fooOnly(const Foo&); /// void barOnly(const Bar&); /// /// int main() { /// // Values must be constructed explicitly /// auto foo = Foo(106); /// auto bar = Bar(314); /// /// fooOnly(foo); // <- legal /// fooOnly(bar); // <- illegal: a Bar type is distinct from Foo /// fooOnly(foo.value()); // <- illegal: no implicit construction /// barOnly(foo); // <- illegal: foo is not a Bar /// } /// @endcode template class StrongType { public: /// The underlying type of this type. using value_type = TValue; /// Default-construct an instance. This overload is only enabled if /// @ref value_type is default-constructible. constexpr StrongType() = default; /// Construct an instance from @a value. /// /// @param value The value to convert from. template constexpr explicit StrongType(UValue&& value) noexcept(IsNothrowConstructible_v) : value_(std::forward(value)) {} constexpr explicit operator value_type() const& noexcept { return value_; } constexpr explicit operator value_type() & noexcept { return value_; } constexpr explicit operator value_type() && noexcept { return value_; } constexpr value_type const& value() const & noexcept { return value_; } constexpr value_type& value() & noexcept { return value_; } constexpr value_type&& value() && noexcept { return std::move(value_); } constexpr value_type const* operator->() const noexcept { return &value_; } constexpr value_type* operator->() noexcept { return &value_; } /// Comparison operatorions for the underlying type. friend constexpr bool operator==(const StrongType& lhs, const StrongType& rhs) { return lhs.value() == rhs.value(); } friend constexpr bool operator!=(const StrongType& lhs, const StrongType& rhs) { return lhs.value() != rhs.value(); } friend constexpr bool operator<=(const StrongType& lhs, const StrongType& rhs) { return lhs.value() <= rhs.value(); } friend constexpr bool operator>=(const StrongType& lhs, const StrongType& rhs) { return lhs.value() >= rhs.value(); } friend constexpr bool operator<(const StrongType& lhs, const StrongType& rhs) { return lhs.value() < rhs.value(); } friend constexpr bool operator>(const StrongType& lhs, const StrongType& rhs) { return lhs.value() > rhs.value(); } private: /// The underlying value of this type. value_type value_; }; } // namespace nvidia #endif // NVIDIA_GXF_COMMON_STRONG_TYPE_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/type_name.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_TYPE_NAME_HPP_ #define NVIDIA_COMMON_TYPE_NAME_HPP_ #include #if defined(__clang__) inline char* TypenameAsStringImpl(const char* begin, char* output, int32_t max_length) { // Return nullptr since this is not implemented return nullptr; } #elif defined(__GNUC__) #include "type_name_gnuc.hpp" #elif defined(_MSC_VER) // Not yet implemented #endif namespace nvidia { namespace helper { /** * Returns the pretty function name. It includes the complete function name along with the namespace * for template parameters. * Compiler using gcc-13 or later strips the namespace of the template parameter if * PRETTY_FUNCTION is called in the same namespace as that of the namespace of template parameter. * Compiler does not strip the namespace if the function that calls the PRETTY_FUNCTION macro is * called in a different namespace. * * @return the pretty function name as a const char* */ template const char* PrettyFunctionName() { return __PRETTY_FUNCTION__; } /** * Returns the sizeof the pretty function name. */ template constexpr int32_t PrettyFunctionSize() { return sizeof(__PRETTY_FUNCTION__); } } // namespace helper } // namespace nvidia namespace nvidia { // Gives a string representation of the name of a C++ type. // // The function will compute the typename during the first invocation and store it in heap memory. // Computation of the typename is linear in the length of the typename and does not involve dynamic // memory allocations. // // For example: // namespace foo { // struct Bar {}; // } // namespace // TyenameAsString(); // returns "foo::Bar" // // Note: Only "simple" class types in global namespace or a "normal" namespaces are guaranteed to // work. Templates, lambdas and anonymous namespaces are not guaranteed to work as expected. template const char* TypenameAsString() { // Ideally the typename string would be computed at compile time, however this does not seem to // be possible. Thus the typename string is computed the first time this function is evaluated // and cached for future function evaluations. const char* template_name = nvidia::helper::PrettyFunctionName(); // Use upper bound to be safe. constexpr int32_t kMaxNameLength = nvidia::helper::PrettyFunctionSize(); static char s_name[kMaxNameLength] = {0}; // Initialize with 0 to get a null-terminated string. static char* result = s_name; if (s_name[0] == 0 && result != nullptr) { // Check for first invocation of this function. result = TypenameAsStringImpl(template_name, s_name, kMaxNameLength); } return result; } } // namespace nvidia #endif // NVIDIA_COMMON_TYPE_NAME_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/type_name_gnuc.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_TYPE_NAME_GNUC_HPP_ #define NVIDIA_COMMON_TYPE_NAME_GNUC_HPP_ #include namespace nvidia { // For the GNU compiler __PRETTY_FUNCTION__ is a null-terminated string with the following form: // const char* nvidia::TypenameAsString() [with T = nvidia::gxf::Component] // We would like to extract the type name as "nvidia::gxf::Component". // The result is stored in the given string 'output'. If the type name is longer than max_length // or another error occurs the function returns nullptr; otherwise 'output' is returned. char* TypenameAsStringGnuC(const char* begin, char* output, int32_t max_length); // Compiler-specific implementation of the TypenameAsString function. inline char* TypenameAsStringImpl(const char* begin, char* output, int32_t max_length) { return TypenameAsStringGnuC(begin, output, max_length); } } // namespace nvidia #endif // NVIDIA_COMMON_TYPE_NAME_GNUC_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/type_utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_COMMON_TYPE_UTILS_HPP_ #define NVIDIA_COMMON_TYPE_UTILS_HPP_ #include // GXF definitions for common class definitions. These should behave identically // ISO standard definitions. They are defined locally to minimize dependencies of core GXF code // on any stl implementations. namespace nvidia { // https://en.cppreference.com/w/cpp/types/void_t template using void_t = void; // https://en.cppreference.com/w/cpp/types/type_identity template struct TypeIdentity { using type = T; }; template using TypeIdentity_t = typename TypeIdentity::type; // https://en.cppreference.com/w/cpp/types/integral_constant template struct IntegralConstant { static constexpr T value = v; }; template struct BoolConstant : IntegralConstant {}; struct TrueType : BoolConstant {}; struct FalseType : BoolConstant {}; // https://en.cppreference.com/w/cpp/types/conditional template struct Conditional : TypeIdentity {}; template struct Conditional : TypeIdentity {}; template using Conditional_t = typename Conditional::type; // https://en.cppreference.com/w/cpp/types/conjunction template struct Conjunction : TrueType {}; template struct Conjunction : Conditional, B>::type {}; template constexpr bool Conjunction_v = Conjunction::value; // https://en.cppreference.com/w/cpp/types/disjunction template struct Disjunction : FalseType {}; template struct Disjunction : Conditional>::type {}; template constexpr bool Disjunction_v = Disjunction::value; // https://en.cppreference.com/w/cpp/types/negation template struct Negation : BoolConstant(B::value)> {}; template constexpr bool Negation_v = Negation::value; // https://en.cppreference.com/w/cpp/types/remove_reference template struct RemoveReference : TypeIdentity {}; template struct RemoveReference : TypeIdentity {}; template struct RemoveReference : TypeIdentity {}; template using RemoveReference_t = typename RemoveReference::type; // https://en.cppreference.com/w/cpp/types/remove_cv template struct RemoveCV : TypeIdentity {}; template struct RemoveCV : TypeIdentity {}; template struct RemoveCV : TypeIdentity {}; template struct RemoveCV : TypeIdentity {}; template using RemoveCV_t = typename RemoveCV::type; template struct RemoveConst : TypeIdentity {}; template struct RemoveConst : TypeIdentity {}; template using RemoveConst_t = typename RemoveConst::type; template struct RemoveVolatile : TypeIdentity {}; template struct RemoveVolatile : TypeIdentity {}; template using RemoveVolatile_t = typename RemoveVolatile::type; // https://en.cppreference.com/w/cpp/types/remove_cvref template struct RemoveCVRef : RemoveCV::type>{}; template using RemoveCVRef_t = typename RemoveCVRef::type; // https://en.cppreference.com/w/cpp/types/add_reference template struct AddLvalueReference { private: template static constexpr TypeIdentity Test(void*); template static constexpr TypeIdentity Test(...); public: using type = typename decltype(Test(nullptr))::type; }; template struct AddRvalueReference { private: template static constexpr TypeIdentity Test(void*); template static constexpr TypeIdentity Test(...); public: using type = typename decltype(Test(nullptr))::type; }; template using AddLvalueReference_t = typename AddLvalueReference::type; template using AddRvalueReference_t = typename AddRvalueReference::type; // https://en.cppreference.com/w/cpp/utility/declval template AddRvalueReference_t Declval() noexcept { static_assert(Conditional_t::value, "Declval() cannot be used in an evaluated context."); } // https://en.cppreference.com/w/cpp/types/decay template struct Decay { private: template static constexpr auto Id(U u) noexcept { return u; } template static constexpr decltype(Id(Declval())) Test(void*); template static constexpr void Test(...) {} public: using type = decltype(Test(nullptr)); }; template using Decay_t = typename Decay::type; // https://en.cppreference.com/w/cpp/types/enable_if template struct EnableIf {}; template struct EnableIf : TypeIdentity {}; template using EnableIf_t = typename EnableIf::type; // https://en.cppreference.com/w/cpp/types/is_same template struct IsSame : FalseType {}; template struct IsSame : TrueType {}; template constexpr bool IsSame_v = IsSame::value; // https://en.cppreference.com/w/cpp/types/is_void template struct IsVoid : IsSame::type> {}; template constexpr bool IsVoid_v = IsVoid::value; // // https://en.cppreference.com/w/cpp/types/is_const template struct IsConst : FalseType {}; template struct IsConst : TrueType {}; template constexpr bool IsConst_v = IsConst::value; // https://en.cppreference.com/w/cpp/types/is_reference template struct IsReference : FalseType {}; template struct IsReference : TrueType {}; template struct IsReference : TrueType {}; template constexpr bool IsReference_v = IsReference::value; // https://en.cppreference.com/w/cpp/types/is_constructible template struct IsConstructible { private: template(Declval()))> static constexpr bool TestCast(void*) { return true; } template static constexpr bool TestCast(...) { return false; } template struct Test : FalseType {}; template struct Test<1, U, void> : BoolConstant(nullptr)> {}; template struct Test()...))>> : TrueType {}; public: static constexpr bool value = Test::value; }; template constexpr bool IsConstructible_v = IsConstructible::value; // https://en.cppreference.com/w/cpp/types/is_default_constructible template using IsDefaultConstructible = IsConstructible; template constexpr bool IsDefaultConstructible_v = IsDefaultConstructible::value; // https://en.cppreference.com/w/cpp/types/is_nothrow_constructible template struct IsNothrowConstructible { private: template(Declval()))> static constexpr bool TestCast(void*) { return Result; } template static constexpr bool TestCast(...) { return false; } template struct Test : FalseType {}; template struct Test<0, U, void_t> : BoolConstant {}; template struct Test<1, U, void> : BoolConstant(nullptr)> {}; template struct Test()...))>> : BoolConstant()...))> {}; public: static constexpr bool value = Test::value; }; template constexpr bool IsNothrowConstructible_v = IsNothrowConstructible::value; // https://en.cppreference.com/w/cpp/types/is_nothrow_default_constructible template using IsNothrowDefaultConstructible = IsNothrowConstructible; template constexpr bool IsNothrowDefaultConstructible_v = IsNothrowDefaultConstructible::value; // https://en.cppreference.com/w/cpp/types/is_convertible template struct IsConvertible { private: template ()(Declval()))> static constexpr bool Test(void*) { return true; } template static constexpr bool Test(...) { return false; } public: static constexpr bool value = (IsVoid_v && IsVoid_v) || Test(nullptr); }; template constexpr bool IsConvertible_v = IsConvertible::value; // https://en.cppreference.com/w/cpp/types/is_convertible template struct IsNothrowConvertible { private: template static constexpr T DecayFunc(T) noexcept; template (Declval()))> static constexpr bool Test(void*) { return Result; } template static constexpr bool Test(...) { return false; } public: static constexpr bool value = (IsVoid_v && IsVoid_v) || Test(nullptr); }; template constexpr bool IsNothrowConvertible_v = IsNothrowConvertible::value; // https://en.cppreference.com/w/cpp/types/is_assignable template struct IsAssignable : FalseType {}; template struct IsAssignable() = Declval())>> : TrueType{}; template constexpr bool IsAssignable_v = IsAssignable::value; // https://en.cppreference.com/w/cpp/types/is_integral template struct IsIntegral : BoolConstant< IsSame_v::type> || IsSame_v::type> || IsSame_v::type> || IsSame_v::type> || IsSame_v::type> || IsSame_v::type> || IsSame_v::type> || IsSame_v::type> || IsSame_v::type>> {}; template constexpr bool IsIntegral_v = IsIntegral::value; // https://en.cppreference.com/w/cpp/types/is_floating_point template struct IsFloatingPoint : BoolConstant< IsSame_v::type> || IsSame_v::type> || IsSame_v::type>> {}; template constexpr bool IsFloatingPoint_v = IsFloatingPoint::value; // https://en.cppreference.com/w/cpp/types/is_arithmetic template struct IsArithmetic : BoolConstant || IsFloatingPoint_v> {}; template constexpr bool IsArithmetic_v = IsArithmetic::value; // https://en.cppreference.com/w/cpp/types/is_signed template > struct IsSigned : BoolConstant<(T(-1) < T(0))> {}; template struct IsSigned : FalseType {}; template constexpr bool IsSigned_v = IsSigned::value; // https://en.cppreference.com/w/cpp/types/is_unsigned template > struct IsUnsigned : BoolConstant<(T(0) < T(-1))> {}; template struct IsUnsigned : FalseType {}; template constexpr bool IsUnsigned_v = IsUnsigned::value; // https://en.cppreference.com/w/cpp/types/make_signed template >> struct MakeSigned : TypeIdentity {}; template <> struct MakeSigned : TypeIdentity {}; template <> struct MakeSigned : TypeIdentity {}; template <> struct MakeSigned : TypeIdentity {}; template <> struct MakeSigned : TypeIdentity {}; template using MakeSigned_t = typename MakeSigned::type; // https://en.cppreference.com/w/cpp/types/make_unsigned template >> struct MakeUnsigned : TypeIdentity {}; template <> struct MakeUnsigned : TypeIdentity {}; template <> struct MakeUnsigned : TypeIdentity {}; template <> struct MakeUnsigned : TypeIdentity {}; template <> struct MakeUnsigned : TypeIdentity {}; template using MakeUnsigned_t = typename MakeUnsigned::type; } // namespace nvidia #endif // NVIDIA_COMMON_TYPE_UTILS_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/unique_index_map.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_COMMON_UNIQUE_INDEX_MAP_HPP_ #define NVIDIA_GXF_COMMON_UNIQUE_INDEX_MAP_HPP_ #include "common/expected.hpp" namespace nvidia { // Provides a basic fixed capacity container for tracking objects and assigning a unique id to every // object inserted. It provides constant time insert/delete/access for all elements with the // generated uid. This container guarantees that uids are never reused, and will return an // Unexpected Error if it runs out of capacity. template class UniqueIndexMap { private: // number of bits to use for holding the version number static constexpr uint64_t kVersionSize = 32; // number of bits to use for holding the index into the underlying container static constexpr uint64_t kIndexSize = 32; // bitmask for Version number static constexpr uint64_t kVersionMask = ((1ULL << kVersionSize) - 1ULL) << kIndexSize; // bitmask for Index number static constexpr uint64_t kIndexMask = (1ULL << kIndexSize) - 1ULL; static_assert(kIndexSize + kVersionSize == 64, "Invalid UID bit length"); static_assert((kVersionMask ^ kIndexMask) == 0xFFFFFFFFFFFFFFFF, "bitmasks must cover full size of uint64_t"); public: // Custom Error codes for construction and access of UniqueIndexMap map. enum struct Error { kArgumentInvalid, // Invalid construction/initialization parameter kOutOfMemory, // Could not allocate memory during initialization kContainerFull, // UniqueIndexMap is full kNotFound // UID does not exits in UniqueIndexMap }; // Expected type for UniqueIndexMap which uses class specific Error type. template using Expected = Expected; UniqueIndexMap() : uids_{nullptr}, data_{nullptr}, capacity_{0}, size_{0}, next_{0} {} UniqueIndexMap(const UniqueIndexMap&) = delete; UniqueIndexMap(UniqueIndexMap&& other) : uids_{other.uids_}, data_{other.data_}, capacity_{other.capacity_}, size_{other.size_}, next_{other.next_} { other.reset_values(); } UniqueIndexMap& operator=(const UniqueIndexMap& other) = delete; UniqueIndexMap& operator=(UniqueIndexMap&& other) { deinitialize(); uids_ = other.uids_; data_ = other.data_; capacity_ = other.capacity_; size_ = other.size_; next_ = other.next_; other.reset_values(); return *this; } ~UniqueIndexMap() { deinitialize(); } // Deallocates the memory allocated in initialize void deinitialize() { for (uint64_t i = 0; i < capacity_; ++i) { if (GetIndex(uids_[i]) == i) { data_[i].~T(); } } delete[] uids_; ::operator delete(data_); reset_values(); } // Allocate memory up to the provided capacity and initialize values for implicit free list. // Returns Unexpected if max_capacity is too large. Expected initialize(uint64_t max_capacity) { if (max_capacity > (1ULL << kIndexSize)) { return Unexpected{Error::kArgumentInvalid}; } capacity_ = max_capacity; uids_ = new (std::nothrow) uint64_t[max_capacity]; data_ = static_cast(::operator new(max_capacity * sizeof(T), std::nothrow)); if (uids_ == nullptr || data_ == nullptr) { return Unexpected{Error::kOutOfMemory}; } for (uint64_t i = 0; i < max_capacity; ++i) { uids_[i] = i + 1; } return {}; } // Check if there exists an object with the provided UID. Returns true if the uid exists in the // allocated range and if the version numbers match. bool valid(uint64_t uid) const { const uint64_t idx = GetIndex(uid); return (idx < capacity_) && (uids_[idx] == uid); } // Insert a new object into the container and return the generated UID via move constructor. // Return Unexpected if the object cannot be inserted. Expected insert(T&& object) { return emplace(static_cast(object)); } // Insert a new object into the container and return the generated UID via copy constructor. // Return Unexpected if the object cannot be inserted. Expected insert(const T& object) { return emplace(object); } // Construct a new object with the provided arguments directly in the container, and return the // generated UID via copy. Return Unexpected if the object cannot be inserted. template Expected emplace(Args&&... args) { if (size_ == capacity_) { return Unexpected{Error::kOutOfMemory}; } if (GetVersion(next_) == (1ULL << kVersionSize) - 1ULL) { return Unexpected{Error::kContainerFull}; } const uint64_t idx = GetIndex(next_); const uint64_t temp = next_; next_ = uids_[idx]; uids_[idx] = temp + (1ULL << kIndexSize); new (&data_[idx]) T{static_cast(args)...}; ++size_; return uids_[idx]; } // Erase the object tracked by UID. Return Unexpected if UID is not valid. Expected erase(uint64_t uid) { if (!valid(uid)) { return Unexpected{Error::kNotFound}; } uint64_t idx = GetIndex(uid); uids_[idx] = next_; next_ = uid; --size_; data_[idx].~T(); return {}; } // Get a pointer to the object tracked by UID. Returns an error if UID is not valid. Expected try_get(uint64_t uid) { if (!valid(uid)) { return Unexpected{Error::kNotFound}; } return &data_[GetIndex(uid)]; } // Get a pointer to the object tracked by UID. Returns an error if UID is not valid. Expected try_get(uint64_t uid) const { if (!valid(uid)) { return Unexpected{Error::kNotFound}; } return &data_[GetIndex(uid)]; } // Performs a linear search and returns the UID of the object. // Returns an error if object is not found Expected find(const T& object) const { for (size_t i = 0; i < capacity_; i++) { if (valid(uids_[i]) && data_[i] == object) { return uids_[i]; } } return Unexpected{Error::kNotFound}; } // Maximum capacity of the unique index map. inline uint64_t capacity() const { return capacity_; } // Current number of elements in the container. inline uint64_t size() const { return size_; } private: static uint64_t GetVersion(uint64_t uid) { return uid >> kIndexSize; } static uint64_t GetIndex(uint64_t uid) { return uid & kIndexMask; } // Resets all pointers and storage parameters to zero, without calling delete, primarily to be // used with move operators. void reset_values() { uids_ = nullptr; data_ = nullptr; capacity_ = 0; size_ = 0; next_ = 0; } uint64_t* uids_; // ids with implicit list of free elements T* data_; // objects storage uint64_t capacity_; // maximum number of concurrent objects uint64_t size_; // current number of objects uint64_t next_; // next "free" element in the container }; } // namespace nvidia #endif // NVIDIA_GXF_COMMON_UNIQUE_INDEX_MAP_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/common/yaml_parser.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_COMMON_YAML_PARSER_HPP_ #define NVIDIA_GXF_COMMON_YAML_PARSER_HPP_ #include #include #include #include #include "common/logger.hpp" #include "yaml-cpp/yaml.h" inline static bool is_space(unsigned char c) { return c == ' '; } /** * Custom YAML parser for std::complex types * * Handles parsing of strings containing a complex floating point value. * * Examples of valid strings are: * "1.0 + 2.5j" * "-1.0 - 3i" * "1+3.3j" * * There may be 0 or 1 space between a + or - sign and the digits. * Either "i" or "j" must appear immediately after the second number. */ template struct YAML::convert> { static Node encode(const std::complex& data) { std::stringstream ss; ss << data.real(); if (data.imag() >= 0) { ss << '+'; } ss << data.imag() << 'j'; Node node = YAML::Load(ss.str()); return node; } static bool decode(const Node& node, std::complex& data) { if (!node.IsScalar()) { GXF_LOG_ERROR("complex decode: expected a scalar"); return false; } std::string value = node.as(); std::regex complex_reg("\\s*([+-]?\\s?\\d*\\.?\\d+)\\s?([+-]{1}\\s?\\d*\\.?\\d+)[ij]{1}\\s*$"); std::smatch m; if (std::regex_search(value, m, complex_reg)) { if (m.size() != 3) { GXF_LOG_ERROR("unexpected match size: [%ld], matched: [%s]", m.size(), m.str(0).c_str()); } // extract the real and imaginary components of the number std::string real_str = m.str(1); std::string imag_str = m.str(2); // remove any white space around + or - (necessary for std::stod to work) real_str.erase(std::remove_if(real_str.begin(), real_str.end(), is_space), real_str.end()); imag_str.erase(std::remove_if(imag_str.begin(), imag_str.end(), is_space), imag_str.end()); // format real and imaginary strings as floating point double real = std::stod(real_str); double imag = std::stod(imag_str); data = std::complex(real, imag); } else { GXF_LOG_ERROR("failed to match expected regex for complex"); return false; } return true; } }; // operator overload for std::complex template YAML::Emitter& operator<<(YAML::Emitter& out, const std::complex& c) { std::stringstream ss; ss << c.real(); if (c.imag() >= 0) ss << '+'; ss << c.imag() << 'j'; out << ss.str(); return out; } #endif // NVIDIA_GXF_COMMON_YAML_PARSER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/dlpack/dlpack.h ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2017-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef DLPACK_DLPACK_H_ #define DLPACK_DLPACK_H_ /** * \brief Compatibility with C++ */ #ifdef __cplusplus #define DLPACK_EXTERN_C extern "C" #else #define DLPACK_EXTERN_C #endif /*! \brief The current version of dlpack */ #define DLPACK_VERSION 80 /*! \brief The current ABI version of dlpack */ #define DLPACK_ABI_VERSION 1 /*! \brief DLPACK_DLL prefix for windows */ #ifdef _WIN32 #ifdef DLPACK_EXPORTS #define DLPACK_DLL __declspec(dllexport) #else #define DLPACK_DLL __declspec(dllimport) #endif #else #define DLPACK_DLL #endif #include #include #ifdef __cplusplus extern "C" { #endif /*! * \brief The device type in DLDevice. */ #ifdef __cplusplus typedef enum : int32_t { #else typedef enum { #endif /*! \brief CPU device */ kDLCPU = 1, /*! \brief CUDA GPU device */ kDLCUDA = 2, /*! * \brief Pinned CUDA CPU memory by cudaMallocHost */ kDLCUDAHost = 3, /*! \brief OpenCL devices. */ kDLOpenCL = 4, /*! \brief Vulkan buffer for next generation graphics. */ kDLVulkan = 7, /*! \brief Metal for Apple GPU. */ kDLMetal = 8, /*! \brief Verilog simulator buffer */ kDLVPI = 9, /*! \brief ROCm GPUs for AMD GPUs */ kDLROCM = 10, /*! * \brief Pinned ROCm CPU memory allocated by hipMallocHost */ kDLROCMHost = 11, /*! * \brief Reserved extension device type, * used for quickly test extension device * The semantics can differ depending on the implementation. */ kDLExtDev = 12, /*! * \brief CUDA managed/unified memory allocated by cudaMallocManaged */ kDLCUDAManaged = 13, /*! * \brief Unified shared memory allocated on a oneAPI non-partititioned * device. Call to oneAPI runtime is required to determine the device * type, the USM allocation type and the sycl context it is bound to. * */ kDLOneAPI = 14, /*! \brief GPU support for next generation WebGPU standard. */ kDLWebGPU = 15, /*! \brief Qualcomm Hexagon DSP */ kDLHexagon = 16, } DLDeviceType; /*! * \brief A Device for Tensor and operator. */ typedef struct { /*! \brief The device type used in the device. */ DLDeviceType device_type; /*! * \brief The device index. * For vanilla CPU memory, pinned memory, or managed memory, this is set to 0. */ int32_t device_id; } DLDevice; /*! * \brief The type code options DLDataType. */ typedef enum { /*! \brief signed integer */ kDLInt = 0U, /*! \brief unsigned integer */ kDLUInt = 1U, /*! \brief IEEE floating point */ kDLFloat = 2U, /*! * \brief Opaque handle type, reserved for testing purposes. * Frameworks need to agree on the handle data type for the exchange to be well-defined. */ kDLOpaqueHandle = 3U, /*! \brief bfloat16 */ kDLBfloat = 4U, /*! * \brief complex number * (C/C++/Python layout: compact struct per complex number) */ kDLComplex = 5U, /*! \brief boolean */ kDLBool = 6U, } DLDataTypeCode; /*! * \brief The data type the tensor can hold. The data type is assumed to follow the * native endian-ness. An explicit error message should be raised when attempting to * export an array with non-native endianness * * Examples * - float: type_code = 2, bits = 32, lanes = 1 * - float4(vectorized 4 float): type_code = 2, bits = 32, lanes = 4 * - int8: type_code = 0, bits = 8, lanes = 1 * - std::complex: type_code = 5, bits = 64, lanes = 1 * - bool: type_code = 6, bits = 8, lanes = 1 (as per common array library convention, the underlying storage size of bool is 8 bits) */ typedef struct { /*! * \brief Type code of base types. * We keep it uint8_t instead of DLDataTypeCode for minimal memory * footprint, but the value should be one of DLDataTypeCode enum values. * */ uint8_t code; /*! * \brief Number of bits, common choices are 8, 16, 32. */ uint8_t bits; /*! \brief Number of lanes in the type, used for vector types. */ uint16_t lanes; } DLDataType; /*! * \brief Plain C Tensor object, does not manage memory. */ typedef struct { /*! * \brief The data pointer points to the allocated data. This will be CUDA * device pointer or cl_mem handle in OpenCL. It may be opaque on some device * types. This pointer is always aligned to 256 bytes as in CUDA. The * `byte_offset` field should be used to point to the beginning of the data. * * Note that as of Nov 2021, multiply libraries (CuPy, PyTorch, TensorFlow, * TVM, perhaps others) do not adhere to this 256 byte aligment requirement * on CPU/CUDA/ROCm, and always use `byte_offset=0`. This must be fixed * (after which this note will be updated); at the moment it is recommended * to not rely on the data pointer being correctly aligned. * * For given DLTensor, the size of memory required to store the contents of * data is calculated as follows: * * \code{.c} * static inline size_t GetDataSize(const DLTensor* t) { * size_t size = 1; * for (tvm_index_t i = 0; i < t->ndim; ++i) { * size *= t->shape[i]; * } * size *= (t->dtype.bits * t->dtype.lanes + 7) / 8; * return size; * } * \endcode */ void* data; /*! \brief The device of the tensor */ DLDevice device; /*! \brief Number of dimensions */ int32_t ndim; /*! \brief The data type of the pointer*/ DLDataType dtype; /*! \brief The shape of the tensor */ int64_t* shape; /*! * \brief strides of the tensor (in number of elements, not bytes) * can be NULL, indicating tensor is compact and row-majored. */ int64_t* strides; /*! \brief The offset in bytes to the beginning pointer to data */ uint64_t byte_offset; } DLTensor; /*! * \brief C Tensor object, manage memory of DLTensor. This data structure is * intended to facilitate the borrowing of DLTensor by another framework. It is * not meant to transfer the tensor. When the borrowing framework doesn't need * the tensor, it should call the deleter to notify the host that the resource * is no longer needed. */ typedef struct DLManagedTensor { /*! \brief DLTensor which is being memory managed */ DLTensor dl_tensor; /*! \brief the context of the original host framework of DLManagedTensor in * which DLManagedTensor is used in the framework. It can also be NULL. */ void * manager_ctx; /*! \brief Destructor signature void (*)(void*) - this should be called * to destruct manager_ctx which holds the DLManagedTensor. It can be NULL * if there is no way for the caller to provide a reasonable destructor. * The destructors deletes the argument self as well. */ void (*deleter)(struct DLManagedTensor * self); } DLManagedTensor; #ifdef __cplusplus } // DLPACK_EXTERN_C #endif #endif // DLPACK_DLPACK_H_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/application.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_APPLICATION_HPP_ #define NVIDIA_GXF_APPLICATION_HPP_ #include #include #include #include #include #include #include #include "common/assert.hpp" #include "gxf/app/arg.hpp" #include "gxf/app/config_parser.hpp" #include "gxf/app/driver.hpp" #include "gxf/app/extension_manager.hpp" #include "gxf/app/segment.hpp" #include "gxf/app/worker.hpp" #include "gxf/core/expected_macro.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { template std::shared_ptr create_app(Args&&... args) { auto app = std::make_shared(std::forward(args)...); return app; } /** * @brief Enum representing the application mode of execution. * An application can either have segments or entities in its * compose() api. */ enum class ExecutionMode : int8_t { kUnset = 0, kSingleSegment, kMultiSegment, kDistributed, }; /** * @brief Scaffolding layer to create applications imperatively. Users implement a virtual * compose() api where individual building blocks of an application is constructed, configured * and connected with each other. * */ class Application : public Segment { private: friend class Worker; friend class Driver; public: Application(); ~Application(); Application(const Application&) = delete; Application& operator=(const Application&) = delete; Application(Application&&) = delete; Application& operator=(Application&&) = delete; virtual void compose() {} /** * @brief Set segment config file * * @param file_path Absolute path to the yaml config file for segments * distributed execution * @return Expected Success or error code */ Expected setConfig(const std::string& file_path); /** * @brief Set segment config file * * @param argc CLI argument count * @param argv CLI argument array, the second is config file path for segments * distributed execution * @return Expected Success or error code */ Expected setConfig(int argc, char** argv); /** * @brief Creates a segment in plan with its own context. The graph for the segment * will be composed() after creation * * @tparam SegmentT Type of segment * @param name Name of the segment * @return std::shared_ptr Shared pointer of the segment */ template >>> std::shared_ptr createSegment(const char* name) { if (segments_plan_.find(name) != segments_plan_.end()) { GXF_LOG_ERROR("ProxySegment with name [%s] already exists. " "Segment names have to be unique", name); return nullptr; } std::shared_ptr element = std::make_shared(); element->setName(name); segments_plan_.emplace(name, element); return element; } /** * @brief API to load extensions at runtime * * @param manifest path to manifest file with list of extensions * @return Expected Success or error code */ Expected loadExtensionManifest(const char* manifest); /** * @brief Adds a UCX connection between two entities with many : many tx and rx * Ucx Transmitter and Ucx Receiver components are added to the source and target entities in * both of the segments * @param source Segment with the entity transmitting the message * @param target Segment with the entity receiving entity. A message available term is added * along with the Ucx Receiver * @param port_maps Segment port map with entity and queue name to be used for connection. * @return Expected Success if connection was added successfully, error code on failure */ Expected connect(SegmentPtr source, SegmentPtr target, std::vector port_maps); /** * @brief Sets the severity level of the logs (corresponding to GXF_LOG_* logging macros) * for a specific segment * * * @param name Name of the segment * @param severity a valid severity level as defined in `gxf_severity_t`. Logs corresponding to * any level <= severity will be logged. * @return gxf_result_t On success the function returns GXF_SUCCESS. */ gxf_result_t setSegmentSeverity(const char* name, gxf_severity_t severity); /** * @brief A blocking api to run the graph. If the application contains multiple segments, * each segment is launched asynchronously and this thread is blocked until each one of * the segments have finished execution. If the graph contains multiple entities, * then this thread is blocked until the graph execution is complete. * @return Expected Success or error code */ Expected run(); /** * @brief A non blocking api call to run an application. If the application contains multiple * segments, each segment is launched asynchronously. * @return Expected Success or error code */ Expected runAsync(); /** * @brief A non blocking api to stop all running running segments or entities. * * @return Expected Success or error code */ Expected interrupt(); /** * @brief A blocking API to waits until the graph execution has completed * * @return Expected Success or error code */ Expected wait(); /** * @brief In-place add a GraphWorker Component into Application's root context, * in which case Application's context should only hold and run GraphWorker or GraphDriver */ template Expected setWorker(const std::string& name, Args... args) { if (worker_ != nullptr) { GXF_LOG_ERROR("Worker already created with name: %s", worker_->name().c_str()); return Unexpected{GXF_FAILURE}; } worker_ = std::make_shared(this, name); std::vector arg_list; if constexpr (sizeof...(args) > 0) { arg_list = parseArgsOfType(args...); } // 1. parse worker its own port int32_t port = -1; Expected arg_port = findArg(arg_list, kPort, GXF_PARAMETER_TYPE_INT32); if (!arg_port) { GXF_LOG_ERROR("Failed to find arg: %s when set GraphWorker[%s]", kPort, name.c_str()); return Unexpected{arg_port.error()}; } port = arg_port.value().as(); // 2. parse driver_ip std::string driver_ip; Expected arg_driver_ip = findArg(arg_list, kDriverIp, GXF_PARAMETER_TYPE_STRING); if (!arg_driver_ip) { GXF_LOG_ERROR("Arg 'driver_ip' is wrong when set GraphWorker[%s]", name.c_str()); return Unexpected{arg_driver_ip.error()}; } driver_ip = arg_driver_ip.value().as(); // 3. parse driver_port int32_t driver_port = -1; Expected arg_driver_port = findArg(arg_list, kDriverPort, GXF_PARAMETER_TYPE_INT32); if (!arg_driver_port) { GXF_LOG_ERROR("Arg 'driver_port' is wrong when set GraphWorker[%s]", name.c_str()); return Unexpected{arg_driver_port.error()}; } driver_port = arg_driver_port.value().as(); std::unordered_set segment_names; for (const auto& arg : arg_list) { auto it = segments_.find(arg.key()); if (it != segments_.end()) { GXF_LOG_DEBUG("Add Segment[name: %s] to GraphWorker[name: %s]", it->first.c_str(), name.c_str()); segment_names.emplace(it->first); } } if (!segment_names.empty()) { GXF_LOG_ERROR("No segments selected in setWorker() arg list"); return Unexpected{GXF_ARGUMENT_INVALID}; } RETURN_IF_ERROR(worker_->setPort(port)); RETURN_IF_ERROR(worker_->setDriverIp(driver_ip)); RETURN_IF_ERROR(worker_->setDriverPort(driver_port)); RETURN_IF_ERROR(worker_->setSegments(segment_names)); return Success; } /** * @brief In-place add a GraphDriver Component into Application's root context, * in which case Application's context should only hold and run GraphWorker or GraphDriver */ template Expected setDriver(const std::string& name, Args... args) { if (driver_ != nullptr) { GXF_LOG_ERROR("Driver already created with name: %s", driver_->name().c_str()); return Unexpected{GXF_FAILURE}; } driver_ = std::make_shared(this, name); std::vector arg_list; if constexpr (sizeof...(args) > 0) { arg_list = parseArgsOfType(args...); } // parse driver its own port int32_t port = -1; Expected arg_port = findArg(arg_list, kPort, GXF_PARAMETER_TYPE_INT32); if (!arg_port) { GXF_LOG_ERROR("Arg 'port' is wrong when set GraphDriver[%s]", name.c_str()); return Unexpected{arg_port.error()}; } port = arg_port.value().as(); RETURN_IF_ERROR(driver_->setPort(port)); return Success; } using Segment::connect; private: Expected commitCompose(); Expected commitSegment(SegmentPtr segment, const char* name); Expected commitConnect(SegmentPtr source, SegmentPtr target, std::vector port_maps); Expected checkConfiguration(); Expected activate(); Expected deactivate(); Expected finalize(); Expected setupCrashHandler(); std::map> segments_; std::map> segments_plan_; std::unordered_set segment_connections_; std::unordered_set segment_connections_plan_; std::unordered_set enabled_segments_; std::string name_; ExecutionMode mode_{ExecutionMode::kUnset}; ExtensionManager extension_manager_; uint64_t next_ucx_port_ = 13337U; // will be set to DEFAULT_UCX_PORT by constructor WorkerPtr worker_; DriverPtr driver_; std::unique_ptr config_parser_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_APPLICATION_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/arg.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_ARG_HPP_ #define NVIDIA_GXF_GRAPH_ARG_HPP_ #include #include #include #include #include #include #include "yaml-cpp/yaml.h" #include "common/type_name.hpp" #include "common/type_utils.hpp" #include "gxf/core/parameter_parser.hpp" #include "gxf/core/parameter_parser_std.hpp" #include "gxf/core/parameter_registrar.hpp" #include "gxf/core/parameter_wrapper.hpp" namespace nvidia { namespace gxf { class ProxyComponent; /** * @brief Struct to hold type info of an Arg * */ typedef struct ArgInfo { gxf_parameter_type_t type; std::string type_name; int32_t rank = 0; std::array::kMaxRank> shape = {0}; } ArgInfo; /** * @brief ArgOverride for scalar parameter type * * @tparam T A valid argument type */ template struct ArgOverride { static Expected apply(ArgInfo& info) { info.type = ParameterTypeTrait::type; info.type_name.assign(ParameterTypeTrait::type_name); info.rank = 0; if (info.type == GXF_PARAMETER_TYPE_CUSTOM) { return Unexpected{GXF_ARGUMENT_INVALID}; } return Success; } static Expected wrap(const T& value) { return YAML::Node(value); } }; /** * @brief Specialized ArgOverride for args of type handle * * @tparam T A valid argument type */ template struct ArgOverride> { static Expected apply(ArgInfo& info) { info.type = GXF_PARAMETER_TYPE_HANDLE; info.type_name.assign(TypenameAsString()); info.rank = 0; return Success; } static Expected wrap(const Handle& value) { std::string c_name = value.name(); const char* entity_name; gxf_uid_t eid = kNullUid; auto result = GxfComponentEntity(value.context(), value.cid(), &eid); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Unable to find the entity for %s", c_name.c_str()); return Unexpected{result}; } result = GxfEntityGetName(value.context(), eid, &entity_name); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Unable to get the entity name"); return Unexpected{result}; } std::string full_name = std::string(entity_name) + "/" + c_name; return YAML::Node(full_name); } }; /** * @brief Specialized ArgOverride for args of type std::vector * * @tparam T A valid argument type */ template struct ArgOverride> { static Expected apply(ArgInfo& info) { // Get the element info ArgInfo element_info; const auto result = ArgOverride::apply(element_info); if (!result) { return ForwardError(result); } info.type = element_info.type; info.type_name = element_info.type_name; // Fetch the shape of and update it to the current ArgInfo for (int32_t i = 0; i < element_info.rank; ++i) { info.shape[i] = element_info.shape[i]; } // A vector increases the rank by 1 and adds shape [-1] to . info.shape[element_info.rank] = -1; info.rank = element_info.rank + 1; return Success; } static Expected wrap(const std::vector& value) { YAML::Node node(YAML::NodeType::Sequence); for (const auto& val : value) { auto maybe = ArgOverride::wrap(val); if (!maybe) { return Unexpected{maybe.error()}; } node.push_back(maybe.value()); } return node; } }; /** * @brief Specialized ArgOverride for parameters of type std::array * * @tparam T A valid argument type * @tparam N length of the array */ template struct ArgOverride> { static Expected apply(ArgInfo& info) { // Get the element info ArgInfo element_info; const auto result = ArgOverride::apply(element_info); if (!result) { return ForwardError(result); } info.type = element_info.type; info.type_name = element_info.type_name; // Fetch the shape of and update it to the current ArgInfo for (int32_t i = 0; i < element_info.rank; ++i) { info.shape[i] = element_info.shape[i]; } // An array increases the rank by 1 and adds shape [N] to . info.shape[element_info.rank] = N; info.rank = element_info.rank + 1; return Success; } static Expected wrap(const std::array& value) { YAML::Node node(YAML::NodeType::Sequence); for (const auto& val : value) { auto maybe = ArgOverride::wrap(val); if (!maybe) { return Unexpected{maybe.error()}; } node.push_back(maybe.value()); } return node; } }; /** * @brief Specialized ArgOverride for parameters of type ProxyComponent * */ template <> struct ArgOverride { static Expected apply(ArgInfo& info) { info.type = GXF_PARAMETER_TYPE_HANDLE; info.rank = 0; return Success; } static Expected wrap(const ProxyComponent& value) { return YAML::Node(); } }; /** * @brief Argument interface to enable configuring parameters in GXF Components from * the application layer. All parameter types from gxf_parameter_type_t enum is supported. * */ class Arg { public: ~Arg() = default; // Constructors explicit Arg(const std::string& key) : key_(key) {} template Arg(const std::string& key, const T& value) { key_ = key; auto result = ArgOverride::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg [%s] of type [%s] with error [%s]", key.c_str(), TypenameAsString(), GxfResultStr(result.error())); return; } set_value(value); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key.c_str(), info_.type_name.c_str()); } template Arg(const std::string& key, const Handle& value) { key_ = key; auto result = ArgOverride>::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg type %s ", key.c_str()); return; } set_value>(value); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key.c_str(), info_.type_name.c_str()); if (!value.is_null()) { handle_cid_ = value->cid(); // handle_tid_ = value->tid(); GxfComponentTypeId(value.context(), info_.type_name.c_str(), &handle_tid_); } } // Special case for string literals typed arguments Arg(const std::string& key, const char* value) { key_ = key; auto result = ArgOverride::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg [%s] of type [%s] with error [%s]", key.c_str(), TypenameAsString(), GxfResultStr(result.error())); return; } set_value(value); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key.c_str(), info_.type_name.c_str()); } Arg(const std::string& key, const ProxyComponent& value) { key_ = key; info_.type = GXF_PARAMETER_TYPE_HANDLE; // info_.type_name = value.type_name(); handle_cid_ = kUnspecifiedUid; info_.rank = 0; set_value(value); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key.c_str(), info_.type_name.c_str()); } template ::value>> Arg(const std::string& key, T&& value) { using DeducedT = std::remove_reference_t>; key_ = key; auto result = ArgOverride::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg type %s ", key.c_str()); return; } set_value(std::forward(value)); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key.c_str(), info_.type_name.c_str()); } template ::value>> Arg(const std::string& key, Handle&& value) { using DeducedT = std::remove_reference_t>>; key_ = key; auto result = ArgOverride::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg type %s ", key.c_str()); return; } if (!value.is_null()) { handle_cid_ = value->cid(); // handle_tid_ = value->tid(); GxfComponentTypeId(value.context(), info_.type_name.c_str(), &handle_tid_); } set_value>(std::forward>(value)); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key.c_str(), info_.type_name.c_str()); } Arg(const std::string& key, ProxyComponent&& value) { key_ = key; info_.type = GXF_PARAMETER_TYPE_HANDLE; // info_.type_name = value.type_name(); handle_cid_ = kUnspecifiedUid; info_.rank = 0; set_value(std::forward(value)); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key.c_str(), info_.type_name.c_str()); } template >>> Arg& operator=(const T& value) { auto result = ArgOverride::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg type %s ", key_.c_str()); return *this; } set_value(value); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key_.c_str(), info_.type_name.c_str()); return *this; } template >>> Arg& operator=(const Handle& value) { auto result = ArgOverride>::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg type %s ", key_.c_str()); return *this; } if (!value.is_null()) { handle_cid_ = value->cid(); // handle_tid_ = value->tid(); GxfComponentTypeId(value.context(), info_.type_name.c_str(), &handle_tid_); } set_value>(value); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key_.c_str(), info_.type_name.c_str()); return *this; } Arg& operator=(ProxyComponent& value) { info_.type = GXF_PARAMETER_TYPE_HANDLE; // info_.type_name = value.type_name(); handle_cid_ = kUnspecifiedUid; info_.rank = 0; set_value(value); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key_.c_str(), info_.type_name.c_str()); return *this; } template > && !std::is_lvalue_reference::value>> Arg&& operator=(T&& value) { using DeducedT = std::remove_reference_t>; auto result = ArgOverride::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg type %s ", key_.c_str()); return std::move(*this); } set_value(std::forward(value)); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key_.c_str(), info_.type_name.c_str()); return std::move(*this); } template >> && !std::is_lvalue_reference>::value>> Arg&& operator=(Handle&& value) { using DeducedT = std::remove_reference_t>>; auto result = ArgOverride::apply(info_); if (!result) { GXF_LOG_ERROR("Invalid Arg type %s ", key_.c_str()); return std::move(*this); } if (!value.is_null()) { handle_cid_ = value->cid(); // handle_tid_ = value->tid(); GxfComponentTypeId(value.context(), info_.type_name.c_str(), &handle_tid_); } set_value>(std::forward>(value)); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key_.c_str(), info_.type_name.c_str()); return std::move(*this); } Arg&& operator=(ProxyComponent&& value) { info_.type = GXF_PARAMETER_TYPE_HANDLE; // info_.type_name = value.type_name(); handle_cid_ = kUnspecifiedUid; info_.rank = 0; set_value(value); GXF_LOG_VERBOSE("Arg: [%s], Type : [%s] created", key_.c_str(), info_.type_name.c_str()); return std::move(*this); } template >> T as() const { const T* value = std::any_cast(&value_); if (value == nullptr) { GXF_LOG_ERROR("Arg [%s] cannot be read as [%s]", key_.c_str(), TypenameAsString()); return T(); } return *value; } const gxf_uid_t handle_uid() const { return handle_cid_; } const gxf_tid_t handle_tid() const { return handle_tid_; } const char* key() const { return key_.c_str(); } const std::string arg_type_name() const { return info_.type_name; } const ArgInfo arg_info() const { return info_; } const YAML::Node yaml_node() const { return yaml_node_; } const int32_t rank() const { return info_.rank; } const std::array::kMaxRank> shape() const { return info_.shape; } const gxf_parameter_type_t parameter_type() const { return info_.type; } bool has_value() const { return value_.has_value(); } std::any value() const { return value_; } private: std::any value_; std::string key_; ArgInfo info_; gxf_uid_t handle_cid_ = kNullUid; gxf_tid_t handle_tid_ = GxfTidNull(); YAML::Node yaml_node_{}; template void set_value(const T& value) { value_ = value; auto maybe_yaml = ArgOverride::wrap(value); if (!maybe_yaml) { GXF_LOG_ERROR("Arg [%s] failed to parse as a YAML node with error [%s]", key_.c_str(), GxfResultStr(maybe_yaml.error())); } else { yaml_node_ = maybe_yaml.value(); } } template void set_value(T&& value) { auto maybe_yaml = ArgOverride::wrap(value); if (!maybe_yaml) { GXF_LOG_ERROR("Arg [%s] failed to parse as a YAML node with error [%s]", key_.c_str(), GxfResultStr(maybe_yaml.error())); } else { yaml_node_ = maybe_yaml.value(); } value_ = std::move(value); } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_ARG_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/arg_parse.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_ARG_PARSE_HPP_ #define NVIDIA_GXF_GRAPH_ARG_PARSE_HPP_ #include #include #include "gxf/app/arg.hpp" #include "gxf/app/proxy_component.hpp" #include "gxf/core/component.hpp" namespace nvidia { namespace gxf { /** * @brief Function returns a list of elements filtered from an input parameter pack of * arguments * * @tparam T Type of parameter to be filtered from the parameter pack * @return std::vector */ template std::vector parseArgsOfType(const First& first, const Rest&... rest) { std::vector arg_list; if constexpr (std::is_same_v) { arg_list.push_back(first); } if constexpr (sizeof...(rest) > 0) { auto rest_list = parseArgsOfType(rest...); arg_list.insert(arg_list.end(), rest_list.begin(), rest_list.end()); } return arg_list; } // Returns a list of proxyComponent args from a list of args // The proxy component args are removed from the input arg list std::vector filterProxyComponents(std::vector& args); // Sets a parameter value for a component using the info stored in Arg type Expected applyArg(Handle component, const Arg& arg); // Returns an arg from a list of args Expected findArg(const std::vector& args, const std::string& key, const gxf_parameter_type_t type); } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_ARG_PARSE_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/config_parser.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_CONFIG_PARSER_HPP_ #define NVIDIA_GXF_GRAPH_CONFIG_PARSER_HPP_ #include #include #include #include "gxf/core/expected.hpp" #include "yaml-cpp/yaml.h" namespace YAML { class Node; } namespace nvidia { namespace gxf { // identifiers static constexpr const char* kSegmentConfig = "segment_config"; static constexpr const char* kMemberType = "member"; static constexpr const char* kMemberParam = "parameters"; static constexpr const char* kEnabledSegments = "enabled_segments"; static constexpr const char* kWorker = "worker"; static constexpr const char* kDriver = "driver"; // attributes static constexpr const char* kName = "name"; static constexpr const char* kEnabled = "enabled"; static constexpr const char* kPort = "port"; static constexpr const char* kDriverIp = "driver_ip"; static constexpr const char* kDriverPort = "driver_port"; static constexpr const char* kRemoteAccess = "remote_access"; static constexpr const char* kServerIpAddress = "server_ip_address"; /** * @brief Read and parse YAML config files * */ class ConfigParser { public: struct SegmentConfig { struct EnabledSegments { std::vector names; }; struct Worker { bool enabled = true; std::string name; int32_t port = 0; std::string driver_ip; int32_t driver_port = 0; }; struct Driver { bool enabled = false; std::string name; int32_t port = 0; }; EnabledSegments enabled_segments; Worker worker; Driver driver; bool enable_all_segments = true; }; ConfigParser() { segment_control_ = std::make_shared(); } /** * Main API */ Expected setFilePath(const std::string& file_path); Expected setFilePath(int argc, char** argv); Expected> getSegmentConfig(); private: std::string file_path_; std::shared_ptr segment_control_; private: std::string getExecutablePath(); }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_CONFIG_PARSER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/driver.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_APPLICATION_DRIVER_HPP_ #define NVIDIA_GXF_APPLICATION_DRIVER_HPP_ #include #include #include "gxf/app/segment.hpp" #include "gxf/std/graph_driver.hpp" namespace nvidia { namespace gxf { class Application; /** * @brief GraphDriver representation in Application API layer * It drives the execution of all remote GraphWorkers * */ class Driver { public: Driver(Application* owner, const std::string& name); std::string name() { return name_; } Expected setPort(uint32_t port) { port_ = port; return Success; } // commit the setup into GraphWorker Expected commit(); private: Application* owner_; std::string name_; GraphEntityPtr driver_entity_; // core component Handle graph_driver_; // server interface object Handle server_; // client interface object Handle client_; // driver server's own port uint32_t port_; }; typedef std::shared_ptr DriverPtr; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_APPLICATION_DRIVER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/entity_group.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_ENTITY_GROUP_HPP_ #define NVIDIA_GXF_ENTITY_GROUP_HPP_ #include #include #include #include #include "gxf/app/graph_entity.hpp" namespace nvidia { namespace gxf { /** * @brief A wrapper over EntityGroup C APIs to manage a programmable * entity group in C++ API layer * */ class EntityGroup { public: EntityGroup() = default; ~EntityGroup() = default; EntityGroup(const EntityGroup&) = delete; EntityGroup& operator=(const EntityGroup&) = delete; /** * @brief Creates a programmable entity group with the runtime context and sets its name * * @param context A valid GXF context * @param name Name of the graph entity */ Expected setup(gxf_context_t context, const char* name); /** * @brief Add single entity into this entity group. * All Resouce components within the group will be automatically resolved to owner components * that has corresponding type of Resource members registered. * * @param GraphEntityPtr An entity in C++ API representation */ Expected add(GraphEntityPtr entity); /** * @brief Add a list of entities into this entity group. * All Resouce components within the group will be automatically resolved to owner components * that has corresponding type of Resource members registered. * * @param entity_members A list of entities in C++ API representation */ Expected add(std::vector entity_members); /** * @return This entity group ID. */ gxf_uid_t gid() const { return gid_; } /** * @return This entity group name. */ std::string name() const { return name_; } private: gxf_uid_t gid_{kNullUid}; std::string name_; std::map entity_members_; }; typedef std::shared_ptr EntityGroupPtr; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_ENTITY_GROUP_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/extension_manager.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_EXTENSION_MANAGER_HPP_ #define NVIDIA_GXF_GRAPH_EXTENSION_MANAGER_HPP_ #include #include #include // NOLINT #include #include "common/fixed_vector.hpp" #include "gxf/core/expected.hpp" #include "gxf/std/extension.hpp" namespace nvidia { namespace gxf { /** * @brief Loads extensions and allows to create instances of their components. * */ class ExtensionManager { public: ExtensionManager() = default; ~ExtensionManager() = default; ExtensionManager(const ExtensionManager&) = delete; ExtensionManager(ExtensionManager&&) = delete; ExtensionManager& operator=(const ExtensionManager&) = delete; ExtensionManager& operator=(ExtensionManager&&) = delete; // Loads a GXF extension from the given file Expected registerExtensions(gxf_context_t context); Expected load(const char* filename); Expected load(Extension* extension, void* handle = nullptr); Expected loadManifest(const char* filename); Expected unloadAll(); // Gets list of TIDs for loaded Extensions. // [in/out] extension_num is for capacity of parameter extensions // [out] extensions is memory to write TIDs to Expected getExtensions(uint64_t* extension_count, gxf_tid_t* extensions); // Gets description for specified (loaded) extension and list of components It provides Expected getExtensionInfo(gxf_tid_t eid, gxf_extension_info_t* info); private: std::set handles_; std::map component_factory_; std::map extension_factory_; std::vector factories_; mutable std::shared_timed_mutex mutex_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_EXTENSION_MANAGER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/graph_entity.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_ENTITY_HPP_ #define NVIDIA_GXF_GRAPH_ENTITY_HPP_ #include #include #include #include #include #include #include "gxf/app/arg.hpp" #include "gxf/app/arg_parse.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/gxf.h" #include "gxf/std/clock.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/resources.hpp" #include "gxf/std/scheduling_terms.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { /** * @brief A wrapper over nvidia::gxf::Entity to manage a programmable * graph entity. * */ class GraphEntity { public: GraphEntity() = default; ~GraphEntity() = default; GraphEntity(const GraphEntity&) = delete; GraphEntity& operator=(const GraphEntity&) = delete; /** * @brief Creates a programmable entity with the runtime context and sets its name * * @param context A valid GXF context * @param name Name of the graph entity */ Expected setup(gxf_context_t context, const char* name) { const GxfEntityCreateInfo entity_create_info = {name, GXF_ENTITY_CREATE_PROGRAM_BIT}; auto result = GxfCreateEntity(context, &entity_create_info, &eid_); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Failed to create entity [%s] with error %s", name, GxfResultStr(result)); return Unexpected{result}; } GxfEntityRefCountInc(context, eid_); Entity::Own(context, eid_).map([&](Entity entity) { entity_ = std::move(entity); }); return Success; } /** * @brief Creates a generic component of type T and sets the parameter values from Args * pack of args. * * Transmitters, Receivers, Clocks and Scheduling Term component names have to be unique. * * @tparam T Type of component. Must be derived from nvidia::gxf::Component * @param name Name of the component * @param args Args must be of type Arg * @return Handle Handle to newly created component. Null handle if component was not created. */ template Handle add(const char* name = nullptr, Args && ... args) { std::vector arg_list; if constexpr (sizeof...(args) > 0) { arg_list = parseArgsOfType(std::forward(args)...); } return add(name, std::move(arg_list)); } /** * @brief Creates a generic component of type T and sets the parameter values from arg_list. * * Transmitters, Receivers, Clocks and Scheduling Term component names have to be unique. * * @tparam T Type of component. Must be derived from nvidia::gxf::Component * @param name Name of the component * @param arg_list vector of Arg used for initializing the component's parameters. * @return Handle Handle to newly created component. Null handle if component was not created. */ template Handle add(const char* name, std::vector arg_list) { auto maybe_component = addComponent(name, arg_list); if (!maybe_component) { return Handle::Null(); } return maybe_component.value(); } /** * @brief Finds all components of given type. Returns an empty vector if component is not found * * @tparam T Type of component to search for * @return FixedVector, N> List of handles to components of the same type */ template FixedVector, N> findAll() const { auto maybe_result = entity_.findAll(); return maybe_result ? maybe_result.value() : FixedVector, N>(); } /** * @brief Gets a component by type and name. Returns null handle if no such component. * * @tparam T Type of component to search for * @param name Name of the component to look for * @return Handle Handle to component, if component is found. Null handle if * no such component. */ template Handle get(const char* name = nullptr) const { auto maybe_handle = entity_.get(name); if (!maybe_handle) { GXF_LOG_WARNING("Failed to find component [%s] with name [%s] in entity [%s] with error %s", TypenameAsString(), name, entity_.name(), GxfResultStr(maybe_handle.error())); return Handle::Null(); } return maybe_handle.value(); } /** * @brief Get a component by type and name. Returns an Unexpected in the case that the * component is not found. Unlike `get` no error is logged if a component is not found. * * @tparam T Type of component to search for * @param name Name of the component to look for * @return Expected> Handle to the component, if component is found. * Otherwise, an Unexpected is returned. */ template Expected> try_get(const char* name = nullptr) const { auto maybe_handle = entity_.get(name); if (!maybe_handle) { return Unexpected{GXF_ENTITY_COMPONENT_NOT_FOUND}; } return maybe_handle.value(); } /** * @brief Gets a component by type and name. Returns null handle if no such component. * * @param type_name Fully qualified C++ type name of the component to search for * @param name Name of the component to look for * @return Handle Handle to component, if component is found. Null handle if * no such component. */ Handle get(const char* type_name, const char* name = nullptr) const; /** * @brief Get a component by type and name. Returns an Unexpected in the case that the * component is not found. Unlike `get` no error is logged if a component is not found. * * @param type_name Fully qualified C++ type name of the component to search for * @param name Name of the component to look for * @return Expected> Handle to the component, if component is found. * Otherwise, an Unexpected is returned. */ Expected> try_get(const char* type_name, const char* name = nullptr) const; /** * @brief Adds a codelet of type T with given name and sets the parameter values from Args * * @tparam T Type of codelet. Must be derived from nvidia::gxf::Codelet * @param name name of the codelet * @param args Args must be of type Arg * @return Handle Handle to newly created component */ template Handle addCodelet(const char* name = nullptr, Args... args) { static_assert(std::is_base_of::value, "Requested type is not a codelet"); if (!codelet_.is_null()) { GXF_LOG_ERROR("Graph Entity is already configured with a codelet [%s]", codelet_->name()); return Handle::Null(); } auto codelet = add(name, args...); if (!codelet) { return codelet; } codelet_ = codelet; return codelet; } /** * @brief Adds a codelet with a given C++ type name. * * @param type_name The fully qualified C++ type name of the codelet component * @param name Name of the codelet * @param arg_list Arguments for the codelet * @return Handle Handle to newly created codelet component */ Handle addCodelet(const char* type_name, const char* name = nullptr, const std::vector& arg_list = {}); /** * @brief Adds a component with a given C++ type name. * * @param type_name The fully qualified C++ type name of the component * @param name Name of the component * @param arg_list Arguments for the component * @return Handle Handle to newly created component */ Handle addComponent(const char* type_name, const char* name = nullptr, const std::vector& arg_list = {}); /** * @brief Adds a component of Clock type T and sets the parameter values from Args * * @tparam T Type of clock. Must be derived from nvidia::gxf::Clock. * @param name Name of the clock * @param args Args must be of type Arg * @return Handle Handle to newly created clock component */ template Handle addClock(const char* name = nullptr, Args... args) { static_assert(std::is_base_of::value, "Requested type is not a clock"); auto clock = add(name, args...); return clock; } /** * @brief Adds a clock component with a given C++ type name. * * @param type_name The fully qualified C++ type name of the clock * @param name Name of the clock * @param arg_list Arguments for the clock component * @return Handle Handle to newly created clock */ Handle addClock(const char* type_name, const char* name = nullptr, const std::vector& arg_list = {}); /** * @brief Get the Clock object from a graph entity. Returns null handle if no clock component * has been created yet. Returns the first clock if no component name is provided. If name is * provided, exact instance of the clock is returned if found else a Null handle. * * @param name Name of the clock component to lookup * @return Handle */ Handle getClock(const char* name = nullptr); /** * @brief Adds a component of SchedulingTerm type T and sets the parameter values from Args * * @tparam T Type of SchedulingTerm. Must be derived from nvidia::gxf::SchedulingTerm * @param name name of the scheduling term * @param args Args must be of type Arg * @return Handle Handle to newly created scheduling term component */ template Handle addSchedulingTerm(const char* name = nullptr, Args... args) { static_assert(std::is_base_of::value, "Requested type is not a SchedulingTerm"); auto term = add(name, args...); return term; } /** * @brief Adds a scheduling term component with a given C++ type name. * * @param type_name The fully qualified C++ type name of the scheduling term * @param name Name of the scheduling term * @return Handle Handle to newly created scheduling term */ Handle addSchedulingTerm(const char* type_name, const char* name = nullptr, const std::vector& arg_list = {}); /** * @brief Adds a component of Transmitter type T with name and sets the parameter values from * Args * * Name of the transmitter should match the parameter name of the underlying codelet * The name of the transmitter component is updated based on the parameter rank info. * A Downstream receptive scheduling term is also added to monitor the transmitter component * * If codelet parameter is a scalar, name of the transmitter is also same as the parameter key * Parameter> | name - "key" * * If codelet parameter is a vector/array, the name of the transmitter component is key_%d where * 'd' is the index of this transmitter in the codelet parameter. * Parameter> | name - "key_0", "key_1", "key_2" * * @tparam T Type of Transmitter. Must be derived from nvidia::gxf::Transmitter * @param name Name of the transmitter component * @param omit_term Boolean flag controlling whether or not a default downstream receptive * scheduling term is added. If true, no scheduling term is added. * @param args Args must be of type Arg * @return Handle Handle to newly created transmitter component */ template Handle addTransmitter(const char* name, bool omit_term = false, Args... args) { static_assert(std::is_base_of::value, "Requested type is not a Transmitter"); auto maybe_tx_name = formatTxName(name); if (!maybe_tx_name) { return Handle::Null(); } auto tx_name = maybe_tx_name.value(); auto tx = add(tx_name.c_str(), args...); if (!tx) { return tx; } if (!omit_term) { // auto adds a downstream receptive scheduling term auto term = this->add(tx_name.c_str()); term->setTransmitter(tx); } std::string full_name = std::string(this->name()) + "/" + tx_name; auto result = updatePort(name, full_name); if (!result) { GXF_LOG_ERROR("Failed to add Transmitter [%s] with error [%s]", tx_name.c_str(), GxfResultStr(result.error())); } return tx; } /** * @brief Adds a component of Transmitter of the corresponding type_name. * Name of the transmitter should match the parameter name of the underlying codelet * The name of the transmitter component is updated based on the parameter rank info. * * If codelet parameter is a scalar, name of the transmitter is also same as the parameter key * Parameter> | name - "key" * * If codelet parameter is a vector/array, the name of the transmitter component is key_%d where * 'd' is the index of this transmitter in the codelet parameter. * Parameter> | name - "key_0", "key_1", "key_2" * * @param type_name The fully qualified C++ type name of the transmitter component * @param name Name of the transmitter component * @param arg_list Arguments for the transmitter component * @param omit_term Boolean flag controlling whether or not a default downstream receptive * scheduling term is added. If true, no scheduling term is added. * @return Handle Handle to newly created transmitter component */ Handle addTransmitter(const char* type_name, const char* name = nullptr, const std::vector& arg_list = {}, bool omit_term = false); /** * @brief Transmitter component lookup using name * * @param name name of a transmitter component which has been previously created * @return Handle Handle to transmitter component if found, Null handle if * no such component. */ Handle getTransmitter(const char* name) { for (auto it = tx_queues_.begin(); it != tx_queues_.end(); ++it) { if (!strcmp(it->second->name(), name)) { return it->second; } } return Handle::Null(); } /** * @brief Adds a component of Receiver type T with name and sets the parameter values from Args * * Name of the receiver should match the parameter name of the underlying codelet * The name of the receiver component is updated based on the parameter rank info. * A Message available scheduling term is also added to monitor the receiver component * * If codelet parameter is a scalar, name of the receiver is also same as the parameter key * Parameter> | name - "key" * * If codelet parameter is a vector/array, the name of the receiver component is key_%d where * 'd' is the index of this receiver in the codelet parameter. * Parameter> | name - "key_0", "key_1", "key_2" * * @tparam T Type of Receiver. Must be derived from nvidia::gxf::Receiver * @param name Name of the receiver component * @param omit_term Boolean flag controlling whether or not a default message available * scheduling term is added. If true, no scheduling term is added. * @param args Args must be of type Arg * @return Handle Handle to newly created receiver component */ template Handle addReceiver(const char* name, bool omit_term = false, Args... args) { static_assert(std::is_base_of::value, "Requested type is not a Receiver"); auto maybe_rx_name = formatRxName(name); if (!maybe_rx_name) { return Handle::Null(); } auto rx_name = maybe_rx_name.value(); auto rx = add(rx_name.c_str(), args...); if (!rx) { return rx; } if (!omit_term) { // auto adds a message available scheduling term auto term = this->add(rx_name.c_str()); term->setReceiver(rx); } std::string full_name = std::string(this->name()) + "/" + rx_name; auto result = updatePort(name, full_name); if (!result) { GXF_LOG_ERROR("Failed to add Receiver [%s] with error [%s]", rx_name.c_str(), GxfResultStr(result.error())); } return rx; } /** * @brief Adds a component of Receiver of the corresponding type_name. * Name of the receiver should match the parameter name of the underlying codelet * The name of the receiver component is updated based on the parameter rank info. * * If codelet parameter is a scalar, name of the receiver is also same as the parameter key * Parameter> | name - "key" * * If codelet parameter is a vector/array, the name of the receiver component is key_%d where * 'd' is the index of this receiver in the codelet parameter. * Parameter> | name - "key_0", "key_1", "key_2" * * @param type_name The fully qualified C++ type name of the receiver component * @param name Name of the receiver component * @param arg_list Arguments for the receiver component * @param omit_term Boolean flag controlling whether or not a default message available * scheduling term is added. If true, no scheduling term is added. * @return Handle Handle to newly created receiver component */ Handle addReceiver(const char* type_name, const char* name = nullptr, const std::vector& arg_list = {}, bool omit_term = false); /** * @brief Receiver component lookup using name * * @param name name of a receiver component which has been previously created * @return Handle Handle to receiver component if found, Null handle if * no such component. */ Handle getReceiver(const char* name) { for (auto it = rx_queues_.begin(); it != rx_queues_.end(); ++it) { if (!strcmp(it->second->name(), name)) { return it->second; } } return Handle::Null(); } /** * @brief Update the capacity and min_size parameter of a transmitter and its corresponding * downstream receptive scheduling term * * @param name Name of the transmitter component * @param capacity capacity of the transmitter to be set * @param policy policy of the transmitter to be set * @param min_size min size of the downstream receptive term to be set * @return Expected On success the function returns Success */ Expected configTransmitter(const char* name, uint64_t capacity, uint64_t policy, uint64_t min_size) { if (tx_queues_.find(name) == tx_queues_.end()) { GXF_LOG_ERROR("Transmitter [%s] is not found in entity [%s]", name, this->name()); return Unexpected{GXF_ENTITY_COMPONENT_NOT_FOUND}; } Handle tx = tx_queues_.at(name); tx->setParameter("capacity", capacity); tx->setParameter("policy", policy); if (terms_.find(name) == terms_.end()) { GXF_LOG_ERROR("Scheduling term [%s] is not found in entity [%s]", name, this->name()); return Unexpected{GXF_ENTITY_COMPONENT_NOT_FOUND}; } Handle term = terms_.at(name); term->setParameter("min_size", min_size); return Success; } /** * @brief Update the capacity and min_size parameter of a receiver and its corresponding * message available scheduling term * * @param name Name of the receiver component * @param capacity capacity of the receiver to be set * @param policy policy of the receiver to be set * @param min_size min size of the message available term to be set * @return Expected On success the function returns Success */ Expected configReceiver(const char* name, uint64_t capacity, uint64_t policy, uint64_t min_size) { if (rx_queues_.find(name) == rx_queues_.end()) { GXF_LOG_ERROR("Receiver [%s] is not found in entity [%s]", name, this->name()); return Unexpected{GXF_ENTITY_COMPONENT_NOT_FOUND}; } Handle rx = rx_queues_.at(name); rx->setParameter("capacity", capacity); rx->setParameter("policy", policy); if (terms_.find(name) == terms_.end()) { GXF_LOG_ERROR("Scheduling term [%s] is not found in entity [%s]", name, this->name()); return Unexpected{GXF_ENTITY_COMPONENT_NOT_FOUND}; } Handle term = terms_.at(name); term->setParameter("min_size", min_size); return Success; } Expected activate() { return entity_.activate(); } Expected deactivate() { return entity_.deactivate(); } gxf_context_t context() const { return entity_.context(); } gxf_uid_t eid() const { return entity_.eid(); } bool is_null() const { return entity_.is_null(); } Handle get_codelet() { return codelet_; } /** * @brief The name of the entity or empty string if no name has been given to the entity. * * @return const char* pointer to name of the entity */ const char* name() const { return entity_.name(); } /** * @brief Given a name for a transmitter to be connected to the codelet, return a formatted * string back which can be used for a new transmitter component creation * If the codelet's tx parameter is a scalar, the tx name is the same as the parameter key * If the codelet's tx parameter is a vector, the tx name would be "key_0", "key_1" ... * * @param tx_name name of transmitter component * @return Expected formatted name of transmitter component */ Expected formatTxName(const char* tx_name); /** * @brief Given a name for a receiver to be connected to the codelet, return a formatted * string back which can be used for a new receiver component creation * If the codelet's rx parameter is a scalar, the rx name is the same as the parameter key * If the codelet's rx parameter is a vector, the rx name would be "key_0", "key_1" ... * * @param rx_name name of receiver component * @return Expected formatted name of receiver component */ Expected formatRxName(const char* rx_name); Expected updatePort(const char* key, std::string value); private: // Creates a generic component of type T and sets the parameter values from arg_list. // // Transmitters, Receivers, Clocks and Scheduling Term component names have to be unique. // If the component type has been registered on any of the extensions which have been loaded, the // new type would be registered to a runtime extension. template Expected> addComponent(const char* name = nullptr, const std::vector& arg_list = {}) { static_assert(std::is_base_of::value, "Requested type is not a component"); // Check if another component with same name and base type exists // return failure if it exists, otherwise proceed with component creation if constexpr (std::is_base_of::value) { if (!codelet_.is_null() && !strcmp(codelet_->name(), name)) { GXF_LOG_ERROR("Codelet with same name [%s] already exists in entity [%s]", name, entity_.name()); return Unexpected{GXF_FAILURE}; } } else if constexpr (std::is_base_of::value) { if (terms_.find(name) != terms_.end()) { GXF_LOG_ERROR("Scheduling term with same name [%s] already exists in entity [%s]", name, entity_.name()); return Unexpected{GXF_FAILURE}; } } else if constexpr (std::is_base_of::value) { if (tx_queues_.find(name) != tx_queues_.end()) { GXF_LOG_ERROR("Transmitter with same name [%s] already exists in entity [%s]", name, entity_.name()); return Unexpected{GXF_FAILURE}; } } else if constexpr (std::is_base_of::value) { if (rx_queues_.find(name) != rx_queues_.end()) { GXF_LOG_ERROR("Receiver with same name [%s] already exists in entity [%s]", name, entity_.name()); return Unexpected{GXF_FAILURE}; } } else if constexpr (std::is_base_of::value) { if (clocks_.find(name) != clocks_.end()) { GXF_LOG_ERROR("Clock with same name [%s] already exists in entity [%s]", name, entity_.name()); return Unexpected{GXF_FAILURE}; } } Expected> maybe_component = entity_.add(name); if (!maybe_component) { GXF_LOG_ERROR("Failed to add handle for component named [%s] to entity [%s] with error %s", name, entity_.name(), GxfResultStr(maybe_component.error())); return ForwardError(maybe_component); } Handle component = maybe_component.value(); for (auto arg : arg_list) { applyArg(component, arg); } if constexpr (std::is_base_of::value) { if (!codelet_.is_null()) { GXF_LOG_DEBUG( "Graph Entity is already configured with a codelet [%s]. New codelet " "will be created but not managed by entity [%s]", codelet_->name(), entity_.name()); } else { codelet_ = component; } } else if constexpr (std::is_base_of::value) { terms_.emplace(name, component); } else if constexpr (std::is_base_of::value) { tx_queues_.emplace(name, component); } else if constexpr (std::is_base_of::value) { rx_queues_.emplace(name, component); } else if constexpr (std::is_base_of::value) { clocks_.emplace(name, component); } components_.emplace(component.get()->cid(), component); return component; } // Create a Handle of the specified type corresponding to a fully qualified C++ type name and // add it to the entity. template Expected> createHandle(const char* type_name, const char* name = nullptr) { gxf_tid_t tid; gxf_context_t context = entity_.context(); gxf_result_t result = GxfComponentTypeId(context, type_name, &tid); if (!isSuccessful(result)) { GXF_LOG_ERROR("Typename [%s] not found. Is this type registered?", type_name); return Unexpected{result}; } auto maybe_untyped_handle = entity_.add(tid, name); if (!maybe_untyped_handle) { GXF_LOG_ERROR("Failed to add handle for [%s] to entity [%s] with error %s", type_name, entity_.name(), GxfResultStr(maybe_untyped_handle.error())); return ForwardError(maybe_untyped_handle); } auto maybe_handle = Handle::Create(maybe_untyped_handle.value()); if (!maybe_handle) { GXF_LOG_ERROR("Failed to convert untyped handle to handle with error %s", GxfResultStr(maybe_handle.error())); return ForwardError(maybe_handle); } return maybe_handle.value(); } // A single codelet per GraphEntity Handle codelet_{Handle::Null()}; // global component lookup based on uid std::map> components_; // scheduling term component lookup by name std::map> terms_; // transmitter component lookup by name std::map> tx_queues_; // receiver component lookup by name std::map> rx_queues_; // clock component lookup by name std::map> clocks_; // resource lookup by name std::map> resources_; gxf_uid_t eid_{kNullUid}; Entity entity_; }; typedef std::shared_ptr GraphEntityPtr; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_ENTITY_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/graph_utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_UTILS_HPP_ #define NVIDIA_GXF_GRAPH_UTILS_HPP_ #include namespace nvidia { namespace gxf { static gxf_tid_t generate_tid() { std::random_device rd; std::mt19937_64 generator(rd()); std::uniform_int_distribution dis(0, UINT64_MAX); // Generate two 64-bit random numbers to create a UUID uint64_t random1 = dis(generator); uint64_t random2 = dis(generator); // Combine the random numbers to create a UUID string std::string uuid_str = std::to_string(random1) + std::to_string(random2); GXF_LOG_VERBOSE("UUID generated %s", uuid_str.c_str()); return gxf_tid_t{random1, random2}; } } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_UTILS_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/proxy_component.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_PROXY_COMPONENT_HPP_ #define NVIDIA_GXF_PROXY_COMPONENT_HPP_ #include #include #include #include "common/assert.hpp" #include "gxf/core/component.hpp" #include "gxf/core/expected_macro.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { /** * @brief A type to aid in lazy component creation by storing component type * and arg info * */ class ProxyComponent { public: ProxyComponent() {} ProxyComponent(const std::string& type_name, const std::string& component_name, const std::vector& args) : typename_(type_name), component_name_(component_name), args_(args) {} std::string type_name() const { return typename_; } std::string name() const { return component_name_; } std::vector args() const { return args_; } private: std::string typename_; std::string component_name_; std::vector args_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_PROXY_COMPONENT_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/segment.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SEGMENT_HPP_ #define NVIDIA_GXF_SEGMENT_HPP_ #include #include #include #include #include #include #include #include #include "common/assert.hpp" #include "gxf/app/arg.hpp" #include "gxf/app/arg_parse.hpp" #include "gxf/app/entity_group.hpp" #include "gxf/app/graph_entity.hpp" #include "gxf/app/graph_utils.hpp" #include "gxf/app/proxy_component.hpp" #include "gxf/core/expected_macro.hpp" #include "gxf/core/gxf.h" #include "gxf/std/default_extension.hpp" #include "gxf/std/resources.hpp" #include "gxf/std/scheduler.hpp" #include "gxf/std/scheduling_terms.hpp" namespace nvidia { namespace gxf { /** * @brief A entity - entity connection specified using tx and rx component names * tx - transmitter component name * rx - receiver component name * The queue names should match the parameter keys of the codelet in the corresponding GraphEntity * for a successful connection between the two graph entities. */ typedef struct PortPair { PortPair(std::string tx, std::string rx) : tx(tx), rx(rx) {} std::string tx; std::string rx; } PortPair; /** * @brief An open port in an segment is specified using entity and queue component names. * SegmentPort name is in the format "." * Entity Name - name of a graph entity created in the segment * Queue Name - tx or rx component name which should match the parameter keys of the codelet in * the corresponding GraphEntity for a successful connection */ typedef struct SegmentPort { auto split_string(std::string port_name) { std::string entity; std::string queue; // Find the position of the dot size_t index = port_name.find('.'); if (index != std::string::npos) { entity = port_name.substr(0, index); queue = port_name.substr(index + 1); } else { GXF_LOG_ERROR( "Invalid port name [%s]. Port names should follow [Entity.Queue] naming convention", port_name.c_str()); } return std::make_pair(entity, queue); } auto split_string2(std::string port_name) { size_t first_pivot = port_name.find("."); size_t second_pivot = port_name.substr(first_pivot + 1).find("."); size_t third_pivot = port_name.find_last_of("."); if (first_pivot == std::string::npos || second_pivot == std::string::npos || third_pivot == std::string::npos) { GXF_LOG_ERROR( "Invalid port name [%s]. For port names with 3 dots, " "it should follow [Segment.Entity.Queue] naming convention", port_name.c_str()); } std::string segment = port_name.substr(0, first_pivot); std::string entity = port_name.substr(first_pivot + 1, second_pivot); std::string queue = port_name.substr(third_pivot + 1); return std::make_tuple(segment, entity, queue); } std::string to_string() { if (!segment.empty()) { return segment + "." + entity + "." + queue; } else { return entity + "." + queue; } } SegmentPort(std::string name) { int count = std::count(name.begin(), name.end(), '.'); if (count == 2) { std::tie(segment, entity, queue) = split_string2(name); } else { std::tie(entity, queue) = split_string(name); } } std::string segment; std::string entity; std::string queue; bool operator==(const SegmentPort& other) const { return segment == other.segment && entity == other.entity && queue == other.queue; } } SegmentPort; /** * @brief A segment - segment connection specified using the segment port info * SegmentPort name is in the format "." where the queues are tx * or rx components. * tx - SegmentPort in the source segment * rx - SegmentPort in the sink segment * * The queue names should match the parameter keys of the codelet in the corresponding GraphEntity * for a successful connection between the two segments */ typedef struct SegmentPortPair { SegmentPortPair(std::string tx, std::string rx) : tx(tx), rx(rx) {} SegmentPort tx; SegmentPort rx; bool operator==(const SegmentPortPair& other) const { return tx == other.tx && rx == other.rx; } } SegmentPortPair; /** * @brief Enum representing the type of scheduler to be used in the application. * This enum is primarily used as an input to setScheduler api * */ enum class SchedulerType: int8_t { kGreedy = 0, kMultiThread, KEventBased, }; const constexpr SchedulerType Greedy = SchedulerType::kGreedy; const constexpr SchedulerType MultiThread = SchedulerType::kMultiThread; const constexpr SchedulerType EventBased = SchedulerType::KEventBased; /** * @brief Segment is a group of graph entities created in a single GXF runtime context. A segment * will have its own scheduler. Graph entities in a segment are connected with each other via * double buffer transmitter and receiver components. A segment can also be connected other * segments via ucx transmitters and receivers. * * Segments are created and managed by the nvidia::gxf::Application class. */ class Segment { public: Segment() = default; virtual ~Segment() = default; Segment(Segment&&) = delete; Segment& operator=(Segment&&) = delete; Segment(const Segment&) = delete; Segment& operator=(const Segment&) = delete; virtual void compose() {} /** * @brief Creates a graph entity with a codelet of type CodeletT along with a parameter pack of * Arg & ProxyComponent. The codelet component will be used to auto populate connection queues and * their corresponding scheduling terms. Args can be used to specify a variable list of components to be * created along with the codelet in the graph entity. Args can also be used to specify a variable list * of Arg type to update any parameter values of the codelet * * @tparam CodeletT Codelet component to be added in the Graph Entity * @tparam Args Pack of Arg or ProxyComponent objects * @param name Name of the graph entity * @param args Pack of Arg or ProxyComponent objects * @return GraphEntityPtr A newly created graph entity object with the requested components. */ template GraphEntityPtr makeEntity(const char* name, Args... args) { static_assert(std::is_base_of::value, "Requested type is not a Codelet"); gxf_tid_t tid; gxf_result_t result = GxfComponentTypeId(context_, TypenameAsString(), &tid); if (result == GXF_FACTORY_UNKNOWN_CLASS_NAME) { // dynamically register the new component auto result = registerCodelet(); if (result != GXF_SUCCESS) { return nullptr; } } auto entity = createGraphEntity(name); auto codelet = entity->addCodelet(name); if constexpr (sizeof...(args) > 0) { // First create all proxy components std::vector proxy_list = parseArgsOfType(args...); for (auto proxy : proxy_list) { createFromProxy(proxy, entity); } // parse all codelet args std::vector arg_list = parseArgsOfType(args...); // filter all proxy component args and create them auto proxy_args = filterProxyComponents(arg_list); for (auto arg : proxy_args) { auto proxy = arg.as(); auto handle = createFromProxy(proxy, entity); applyArg(codelet, Arg(arg.key(), handle)); } for (auto arg : arg_list) { applyArg(codelet, arg); } } return entity; } /** * @brief Creates a graph entity without a codelet and with a parameter pack of Arg * & ProxyComponent. Args can be used to specify a variable list of components to be * created along with the graph entity. * * @tparam Args Pack of Arg or ProxyComponent objects * @param name Name of the graph entity * @param args Pack of Arg or ProxyComponent objects * @return GraphEntityPtr A newly created graph entity object with the requested components. */ template GraphEntityPtr makeEntity(const char* name, Args... args) { auto entity = createGraphEntity(name); if constexpr (sizeof...(args) > 0) { // First create all proxy components std::vector proxy_list = parseArgsOfType(args...); for (auto proxy : proxy_list) { createFromProxy(proxy, entity); } } return entity; } EntityGroupPtr makeEntityGroup(const char* name, const std::vector& entity_members = {}) { auto entity_group = createEntityGroup(name); entity_group->add(entity_members); return entity_group; } /** * @brief Creates a scheduling term of requested type and applies parameter component values * from a parameter pack of arguments. This api does not create the requested gxf native component. * A Proxy component value is returned which has the type info and arg list needed to create this * scheduling term. createFromProxy() api is used to create this component given any specific GraphEntity. * * @tparam T Type of GXF scheduling term. Type must be derived from nvidia::gxf::SchedulingTerm type. * @param name name of the component * @param args Parameter pack of arguments / parameter values to be applied to the component * @return ProxyComponent */ template ProxyComponent makeTerm(const char* name, Args... args) { static_assert(std::is_base_of::value, "Requested type is not a SchedulingTerm"); std::vector arg_list; const std::string type_name(TypenameAsString()); if constexpr (sizeof...(args) > 0) { arg_list = parseArgsOfType(args...); } return ProxyComponent(type_name, name, arg_list); } /** * @brief Creates a resource of requested type and applies parameter component values * from a parameter pack of arguments. This api does not create the requested gxf native component. * A Proxy component value is returned which has the type info and arg list needed to create this * resource. createFromProxy() api is used to create this component given any specific GraphEntity. * * @tparam T Type of GXF resource. Type must be derived from nvidia::gxf::ResourceBase type. * @param name name of the component * @param args Parameter pack of arguments / parameter values to be applied to the component * @return ProxyComponent */ template ProxyComponent makeResource(const char* name, Args... args) { // TODO(chandrahasj) Enable this check when allocator // types have been updated with resource base type // static_assert(std::is_base_of::value, // "Requested type is not a Resource"); std::vector arg_list; const std::string type_name(TypenameAsString()); if constexpr (sizeof...(args) > 0) { arg_list = parseArgsOfType(args...); } return ProxyComponent(type_name, name, arg_list); } /** * @brief Adds a clock component to the segment and applies parameter component values * from a parameter pack of arguments. * * @tparam T Type of GXF clock component. Type must be derived from nvidia::gxf::Clock type. * @param name Name of the clock component * @param args Parameter pack of arguments / parameter values to be applied to the component * @return Handle Handle to newly created clock component. Null handle if component was not * created. */ template Handle setClock(const char* name, Args... args) { static_assert(std::is_base_of::value, "Requested type is not a Clock"); if (!clock_entity_) { clock_entity_ = createGraphEntity("ClockEntity_" + name_); } auto clock = clock_entity_->add(name); std::vector arg_list; if constexpr (sizeof...(args) > 0) { arg_list = parseArgsOfType(args...); } for (auto arg : arg_list) { applyArg(clock, arg); } return clock; } /** * @brief Adds a scheduler component to the segment and applies parameter component values * from a parameter pack of arguments. * * @tparam T Type of GXF scheduler component. Type must be derived from nvidia::gxf::Scheduler type. * @param args Parameter pack of arguments / parameter values to be applied to the component * @return Handle Handle to newly created scheduler component. Null handle if component was not * created. */ template Handle setScheduler(Args... args) { std::vector arg_list; if constexpr (sizeof...(args) > 0) { arg_list = parseArgsOfType(args...); } return setScheduler(schedulerType, arg_list); } /** * @brief Add a scheduler to the segment based on the input SchedulerType enum. If the segment contains * a clock component, the same component will be reused to configure the scheduler. If no clock components * are found in the segment, a new RealTimeClock component will be added to the segment. * * @param scheduler Type of the scheduler to be added. One of kGreedy, kMultithread or kEventBased * @return Handle Handle to newly created scheduler component. Null handle if component was not * created. */ Handle setScheduler(const SchedulerType& scheduler, std::vector arg_list = {}); /** * @brief Adds a double buffer queue based connection between two entities with * 1:1 tx and rx connectivity. * * @param source Origin graph entity for the connection * @param target Destination graph entity for the connection * @return Expected On success the function returns Success */ virtual Expected connect(GraphEntityPtr& source, GraphEntityPtr& target); /** * @brief Adds a single double buffer queue based connection between two entities * with a port pair specified. * * @param source Origin graph entity for the connection * @param target Destination graph entity for the connection * @param port_pair Port pair containing info of connection to be created * @return Expected On success the function returns Success */ virtual Expected connect(GraphEntityPtr& source, GraphEntityPtr& target, PortPair port_pair); /** * @brief Adds multiple double buffer queue based connections between two entities * with many : many tx and rx. Connections between two graph entities are created * sequentially. * * @param source Origin graph entity for the connection * @param target Destination graph entity for the connection * @param port_pairs List of port pairs containing info of connections to be created * @return Expected On success the function returns Success */ virtual Expected connect(GraphEntityPtr& source, GraphEntityPtr& target, std::vector port_pairs); /** * @brief Get the Entity object with given name. A nullptr is returned if entity is * not found. * * @param name Name of the graph entity. API is Case sensitive. * @return std::shared_ptr Pointer to underlying graph entity object */ std::shared_ptr getEntity(const char* name) { for (auto& [uid, entity] : entities_) { if (std::strcmp(name, entity->name()) == 0) { return entity; } } GXF_LOG_ERROR("Graph Entity [%s] not found", name); return nullptr; } /** * @brief Fetch the name of the segment * * @return const char* pointer to name of the segment */ const char* name() const { return name_.c_str(); } /** * @brief Fetch the context of a segment * * @return gxf_context_t */ gxf_context_t context() { return context_; } /** * @brief Activates all the graph entities in the segment * * @return Expected On success the function returns Success */ Expected activate() { GXF_LOG_INFO("Activating segment [%s] ....", name_.c_str()); gxf_result_t result = GxfGraphActivate(context_); return result == GXF_SUCCESS ? Success : Unexpected{result}; } /** * @brief Deactivates all the graph entities in the segment * * @return Expected On success the function returns Success */ Expected deactivate() { GXF_LOG_INFO("Deactivating segment [%s] ....", name_.c_str()); gxf_result_t result = GxfGraphDeactivate(context_); return result == GXF_SUCCESS ? Success : Unexpected{result}; } /** * @brief A blocking api to run the segment. This thread is blocked (sleeping) * until the segment execution is complete. * * @return Expected On success the function returns Success */ Expected run() { GXF_LOG_INFO("Running segment [%s] ....", name_.c_str()); gxf_result_t result = GxfGraphRun(context_); return result == GXF_SUCCESS ? Success : Unexpected{result}; } /** * @brief A non blocking api to execute a segment. API returns immediately after * starting the segment execution. wait() can be used to wait until execution * has finished. * @return Expected On success the function returns Success */ Expected runAsync() { GXF_LOG_INFO("Running segment [%s] ....", name_.c_str()); gxf_result_t result = GxfGraphRunAsync(context_); return result == GXF_SUCCESS ? Success : Unexpected{result}; } /** * @brief A non blocking api to stop a previously running segment. Segment is not guaranteed * to have stopped when this api returns. wait() can be used to wait until the execution * has finished. * * @return Expected On success the function returns Success */ Expected interrupt() { GXF_LOG_INFO("Interrupting segment [%s] ....", name_.c_str()); gxf_result_t result = GxfGraphInterrupt(context_); return result == GXF_SUCCESS ? Success : Unexpected{result}; } /** * @brief A blocking API to wait until the segment execution has completed. * * @return gxf_result_t On success the function returns GXF_SUCCESS. */ Expected wait() { GXF_LOG_INFO("Waiting on segment [%s]....", name_.c_str()); gxf_result_t result = GxfGraphWait(context_); return result == GXF_SUCCESS ? Success : Unexpected{result}; } /** * @brief Sets the severity level of the logs (corresponding to GXF_LOG_* logging macros) * for a segment * * @param severity a valid severity level as defined in `gxf_severity_t`. Logs corresponding to * any level <= severity will be logged. * @return gxf_result_t On success the function returns GXF_SUCCESS. */ gxf_result_t setSeverity(gxf_severity_t severity) { return GxfSetSeverity(context_, severity); } /** * @brief Saves the segment information containing entities, components and their corresponding * parameter values in a yaml representation * * @param filepath path to save the resulting graph yaml file * @return Expected On success the function returns Success */ Expected saveToFile(const char* filepath) { gxf_result_t code = GxfGraphSaveToFile(context_, filepath); return ExpectedOrCode(code); } /** * @brief Loads parameters for graph entities composed in the segment / application. * YAML file follows the GXF graph specification * * @param filepath path to a valid parameters file * @return Expected On success the function returns Success */ Expected loadParameterFile(const char* filepath) { gxf_result_t code = GxfGraphLoadFile(context_, filepath); return ExpectedOrCode(code); } /** * @brief Create a Network Context in the segment which can be used by UCX Connections * added in the application. A new graph entity with the name "NetworkContext" will be added * to the segment context with a UcxContext component and a corresponding entity and component * serializers * * @return Expected On success the function returns Success */ Expected createNetworkContext(); /** * @brief Creates a component in graph entity based on the type information from the ProxyComponent * * @param component A proxy component object * @param entity A pointer to graph entity to be used for creating the component * @return Handle Handle to newly created component */ Handle createFromProxy(ProxyComponent& component, GraphEntityPtr& entity); /** * @brief This function is expected to be called by the application layer to assign a context to the * segment and a runtime extension for on the fly registration of components * * @param segment_context A valid GXF context to be assigned to the segment * @param name A valid name for the segment * @param runtime_ext Pointer to a GXF extension which can be used to register any components at runtime * @return Expected On success the function returns Success */ Expected setup(gxf_context_t segment_context, const char* name, std::shared_ptr runtime_ext) { name_.assign(name); context_ = segment_context; runtime_ext_ = runtime_ext; is_setup_ = true; return Success; } Expected setName(const char* name) { name_ = name; return Success; } Expected checkConfiguration() { return Success; } protected: /** * @brief Creates a programmable graph entity with the given name * * @param name Name of the graph entity * @return GraphEntityPtr Pointer to newly created entity */ GraphEntityPtr createGraphEntity(std::string name) { GXF_LOG_DEBUG("Creating graph entity [%s]", name.c_str()); auto entity = std::make_shared(); if (!entity->setup(context_, name.c_str())) { return nullptr; } entities_.emplace(entity->eid(), entity); return entity; } /** * @brief Creates a programmable graph entity group with the given name * * @param name Name of the graph entity * @return EntityGroupPtr Pointer to newly created entity group */ EntityGroupPtr createEntityGroup(std::string name) { GXF_LOG_DEBUG("Creating graph entity group [%s]", name.c_str()); auto entity_group = std::make_shared(); if (!entity_group->setup(context_, name.c_str())) { return nullptr; } entity_groups_.emplace(entity_group->gid(), entity_group); return entity_group; } // Registers a new codelet type with the runtime extension template gxf_result_t registerCodelet() { static_assert(std::is_base_of::value, "Requested type is not a Codelet"); gxf_tid_t new_tid = generate_tid(); auto result = runtime_ext_->add(new_tid, TypenameAsString(), TypenameAsString(), TypenameAsString()); if (!result) { return ToResultCode(result); } return GxfRegisterComponentInExtension(context_, new_tid, runtime_ext_->tid()); } // Extension to register components on the fly std::shared_ptr runtime_ext_; std::map entities_; std::map entity_groups_; GraphEntityPtr scheduler_entity_; GraphEntityPtr clock_entity_; GraphEntityPtr connect_entity_; GraphEntityPtr network_ctx_; gxf_context_t context_ = kNullContext; std::string name_; bool is_setup_{false}; }; typedef std::shared_ptr SegmentPtr; struct SegmentConnection { SegmentConnection(SegmentPtr source, SegmentPtr target, std::vector port_maps) : source(source), target(target), port_maps(port_maps) {} SegmentPtr source; SegmentPtr target; std::vector port_maps; bool operator==(const SegmentConnection& other) const { if (source != other.source || target != other.target) { return false; } if (port_maps.size() != other.port_maps.size()) { return false; } for (size_t i = 0; i < port_maps.size(); i++) { if (!(port_maps.at(i) == other.port_maps.at(i))) { return false; } } return true; } struct Hash { std::size_t operator()(const SegmentConnection& sc) const { std::size_t h1 = std::hash{}(sc.source); std::size_t h2 = std::hash{}(sc.target); std::size_t h3 = std::hash{}(sc.port_maps.size()); return h1 ^ h2 ^ h3; } }; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SEGMENT_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/app/worker.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_APPLICATION_WORKER_HPP_ #define NVIDIA_GXF_APPLICATION_WORKER_HPP_ #include #include #include #include "gxf/app/segment.hpp" #include "gxf/std/graph_worker.hpp" namespace nvidia { namespace gxf { class Application; /** * @brief GraphWorker representation in Application API layer * It manages the execution of selected segments * */ class Worker { public: Worker(Application* owner, const std::string& name); std::string name() { return name_; } Expected setPort(uint32_t port) { port_ = port; return Success; } Expected setDriverIp(const std::string& ip) { driver_ip_ = ip; return Success; } Expected setDriverPort(uint32_t port) { driver_port_ = port; return Success; } // set selected segments to run Expected setSegments(const std::unordered_set& segment_names) { segment_names_ = segment_names; return Success; } // commit the setup into GraphWorker Expected commit(); private: Application* owner_; std::string name_; GraphEntityPtr worker_entity_; // core component Handle graph_worker_; // server interface object Handle server_; // client interface object Handle client_; // worker server's own port uint32_t port_ = 0; // target driver server's IP address std::string driver_ip_; // target driver server's port uint32_t driver_port_ = 0; // selected segments to run by this worker std::unordered_set segment_names_; }; typedef std::shared_ptr WorkerPtr; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_APPLICATION_WORKER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/behavior_tree/constant_behavior.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_BT_CONSTANT_BEHAVIOR_HPP_ #define NVIDIA_GXF_BT_CONSTANT_BEHAVIOR_HPP_ #include "gxf/std/codelet.hpp" #include "gxf/std/controller.hpp" #include "gxf/std/scheduling_terms.hpp" namespace nvidia { namespace gxf { // Constant Behavior Codelet switches its own status to the configured desired // ||constant_status| after each tick. class ConstantBehavior : public Codelet { public: virtual ~ConstantBehavior() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t tick() override; private: // the desired status to switch to during each tick Parameter constant_status_; enum ConstantBehaviorType { CONSTANT_SUCCESS = 0, CONSTANT_FAILURE = 1, }; // its own scheduling term to start/stop itself Parameter> s_term_; SchedulingConditionType ready_conditions; SchedulingConditionType never_conditions; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_BT_CONSTANT_BEHAVIOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/behavior_tree/entity_count_failure_repeat_controller.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_BT_ENTITY_COUNT_FAILURE_REPEAT_CONTROLLER_HPP_ #define NVIDIA_GXF_BT_ENTITY_COUNT_FAILURE_REPEAT_CONTROLLER_HPP_ #include "gxf/core/parameter_parser_std.hpp" #include "gxf/std/controller.hpp" namespace nvidia { namespace gxf { // Repeat the entity on failure up to |max_repeat_count_| times, then deactivate // the entity class EntityCountFailureRepeatController : public Controller { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_controller_status_t control(gxf_uid_t eid, Expected code) override; private: size_t repeat_count_; Parameter max_repeat_count_; gxf_controller_status_t controller_status; // Take gxf_result_t codelet::tick() to entity_state_t // controller_status.behavior_status entity_state_t setBehaviorStatus(gxf_result_t tick_result); // Set execution status based on behavior status and repeat counter gxf_execution_status_t setExecStatus(entity_state_t& behavior_status); // if code = EntityItem::execute() returns FAILURE & exec_status != // GXF_EXECUTE_FAILURE set behavior status to GXF_BEHAVIOR_RUNNING so that // parent codelet knows it's running Parameter return_behavior_running_if_failure_repeat_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_BT_ENTITY_COUNT_FAILURE_REPEAT_CONTROLLER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/behavior_tree/parallel_behavior.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_BT_PARALLEL_BEHAVIOR_HPP_ #define NVIDIA_GXF_BT_PARALLEL_BEHAVIOR_HPP_ #include #include "gxf/std/codelet.hpp" #include "gxf/std/controller.hpp" #include "gxf/std/scheduling_terms.hpp" namespace nvidia { namespace gxf { // Runs its child entities in parallel. By default, succeeds when all child // entities succeed and fails when all child entities fail. class ParallelBehavior : public Codelet { public: virtual ~ParallelBehavior() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t tick() override; private: // parent codelet points to children's scheduling terms to schedule child // entities Parameter > > children_; std::vector > children; std::vector children_eid; // its own scheduling term to start/stop itself Parameter > s_term_; Handle s_term; size_t getNumChildren() const; entity_state_t GetChildStatus(size_t child_id); gxf_result_t startChild(size_t child_id); gxf_result_t stopAllChild(); Parameter success_threshold_; Parameter failure_threshold_; SchedulingConditionType ready_conditions; SchedulingConditionType never_conditions; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_BT_PARALLEL_BEHAVIOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/behavior_tree/repeat_behavior.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_BT_REPEAT_BEHAVIOR_HPP_ #define NVIDIA_GXF_BT_REPEAT_BEHAVIOR_HPP_ #include #include "gxf/std/codelet.hpp" #include "gxf/std/controller.hpp" #include "gxf/std/scheduling_terms.hpp" namespace nvidia { namespace gxf { // Repeat Behavior // Repeats its only child entity. By default, won’t repeat when the child entity // fails. This can be customized using parameters. class RepeatBehavior : public Codelet { public: virtual ~RepeatBehavior() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t tick() override; private: // parent codelet points to children's scheduling terms to schedule child // entities Parameter > > children_; std::vector > children; std::vector children_eid; // its own scheduling term to start/stop itself Parameter > s_term_; Handle s_term; Parameter repeat_after_failure_; size_t getNumChildren() const; entity_state_t GetChildStatus(size_t child_id); gxf_result_t startChild(size_t child_id); SchedulingConditionType ready_conditions; SchedulingConditionType never_conditions; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_BT_REPEAT_BEHAVIOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/behavior_tree/selector_behavior.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_BT_SELECTOR_BEHAVIOR_HPP_ #define NVIDIA_GXF_BT_SELECTOR_BEHAVIOR_HPP_ #include #include "gxf/std/codelet.hpp" #include "gxf/std/controller.hpp" #include "gxf/std/scheduling_terms.hpp" namespace nvidia { namespace gxf { // Selector Behavior // Runs all child entities in sequence until one succeeds, then reports success. // If all child entities fail (or no child entities are present), this codelet // fails. class SelectorBehavior : public Codelet { public: virtual ~SelectorBehavior() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t tick() override; private: // parent codelet points to children's scheduling terms to schedule child // entities Parameter > > children_; std::vector > children; std::vector children_eid; // its own scheduling term to start/stop itself Parameter > s_term_; Handle s_term; size_t getNumChildren() const; entity_state_t GetChildStatus(size_t child_id); gxf_result_t startChild(size_t child_id); size_t current_child_id; SchedulingConditionType ready_conditions; SchedulingConditionType never_conditions; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_BT_SELECTOR_BEHAVIOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/behavior_tree/sequence_behavior.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_BT_SEQUENCE_BEHAVIOR_HPP_ #define NVIDIA_GXF_BT_SEQUENCE_BEHAVIOR_HPP_ #include #include "common/fixed_vector.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/controller.hpp" #include "gxf/std/scheduling_terms.hpp" namespace nvidia { namespace gxf { // Sequence Behavior // Runs its child entities in sequence, in the order in which they are defined. // Succeeds when all child entities succeed, or fails as soon as one child // entity fails. class SequenceBehavior : public Codelet { public: virtual ~SequenceBehavior() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t tick() override; private: // parent codelet points to children's scheduling terms to schedule child // entities Parameter, kMaxComponents> > children_; FixedVector, kMaxComponents> children; std::vector children_eid; // its own scheduling term to start/stop itself Parameter > s_term_; Handle s_term; size_t getNumChildren() const; entity_state_t GetChildStatus(size_t child_id); gxf_result_t startChild(size_t child_id); size_t current_child_id; SchedulingConditionType ready_conditions; SchedulingConditionType never_conditions; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_BT_SEQUENCE_BEHAVIOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/behavior_tree/switch_behavior.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_BT_SWITCH_BEHAVIOR_HPP_ #define NVIDIA_GXF_BT_SWITCH_BEHAVIOR_HPP_ #include #include "common/fixed_vector.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/controller.hpp" #include "gxf/std/scheduling_terms.hpp" namespace nvidia { namespace gxf { // Switch Behavior // Runs the child entity with the index defined as desired_behavior. class SwitchBehavior : public Codelet { public: virtual ~SwitchBehavior() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t tick() override; private: // parent codelet points to children's scheduling terms to schedule child // entities // Parameter > > children_; // std::vector > children; Parameter, kMaxComponents> > children_; FixedVector, kMaxComponents> children; std::vector children_eid; // its own scheduling term to start/stop itself Parameter > s_term_; Handle s_term; // the child entity to switch to. this child entity will run when this parent // entity runs and the parent entity will return this child entity's behavior // status may not be empty Parameter desired_behavior_; size_t getNumChildren() const; entity_state_t GetChildStatus(size_t child_id); gxf_result_t startChild(size_t child_id); size_t current_child_id; SchedulingConditionType ready_conditions; SchedulingConditionType never_conditions; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_BT_SWITCH_BEHAVIOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/behavior_tree/timer_behavior.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_BT_TIMER_BEHAVIOR_HPP_ #define NVIDIA_GXF_BT_TIMER_BEHAVIOR_HPP_ #include "gxf/std/clock.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/controller.hpp" #include "gxf/std/scheduling_terms.hpp" namespace nvidia { namespace gxf { // Timer Behavior // Waits for a specified amount of time delay, // and switches to the configured result switch_status afterwards. class TimerBehavior : public Codelet { public: virtual ~TimerBehavior() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t tick() override; private: // a specified time (in seconds) after which the status of this node will be // changed Parameter delay_; // the desired status to switch to when the tick time is delay_ seconds after // first tick Setting this value to “running” will lead to undefined behavior // in the application. Parameter switch_status_; enum SwitchStatus { kSwitchToSuccess = 0, kSwitchToFailure = 1, kSwitchToRunning = 2, }; // Use this clock to get wait time since first tick Parameter> clock_; // its own scheduling term to start/stop itself Parameter> s_term_; bool is_first_tick_ = true; // timestamp of the last tick which caused a status switch int64_t last_switch_timestamp_ = 0; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_BT_TIMER_BEHAVIOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/common_expected_macro.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include "common/expected.hpp" // Concatenates its two arguments. #define EXPECTED_MACRO_INTERNAL_CONCAT(a, b) EXPECTED_MACRO_INTERNAL_CONCAT_IMPL(a, b) #define EXPECTED_MACRO_INTERNAL_CONCAT_IMPL(a, b) a##b // Converts its argument to a string at compile time. #define EXPECTED_MACRO_INTERNAL_TO_STRING(x) EXPECTED_MACRO_INTERNAL_TO_STRING_IMPL(x) #define EXPECTED_MACRO_INTERNAL_TO_STRING_IMPL(x) #x // Gets the current location in the source code in the format "file:line". #define EXPECTED_MACRO_INTERNAL_FILE_LINE() __FILE__ ":" EXPECTED_MACRO_INTERNAL_TO_STRING(__LINE__) // Helper to support logging a default message and an optional custom message. #define EXPECTED_MACRO_INTERNAL_LOG_IN_EXPECT_MACRO(expression_result, expression_string, ...) \ nvidia::expected_macro::LogHelper(__FILE__, __LINE__, expression_result, expression_string, \ ##__VA_ARGS__); // Helper to check the return type of the expression used in RETURN_IF_ERROR. #define EXPECTED_MACRO_INTERNAL_CHECK_EXPRESSION_IS_RESULT(expression_result) \ static_assert( \ nvidia::expected_macro::IsStatus::value || \ nvidia::expected_macro::IsUnwrappable::value , \ EXPECTED_MACRO_INTERNAL_FILE_LINE() \ ": RETURN_IF_ERROR can only be used with expressions that return a result type. You " \ "can register a type as a result type unwrappable with one of" \ "`template <> struct IsUnwrappable : std::true_type {};` or " \ "`template <> struct IsStatus : std::true_type {}`. "); // Helper to check the return type of the expression used in UNWRAP_OR_RETURN. #define EXPECTED_MACRO_INTERNAL_CHECK_EXPRESSION_IS_UNWRAPPABLE(expression_result) \ static_assert( \ nvidia::expected_macro::IsUnwrappable::value, \ EXPECTED_MACRO_INTERNAL_FILE_LINE() \ ": UNWRAP_OR_RETURN can only be used with expressions that return an unwrappable type. " \ "You can register a type as being unwrappable with " \ "`template <> struct IsUnwrappable : std::true_type {};`. For expressions " \ "returning a status instead of an unwrappable use `RETURN_IF_ERROR` instead."); // Evaluates an expression that returns a result type. If the returned result contains an error it // returns the error. This macro can only be used in functions that also return a result type. // // Per default the macro already creates an error message that includes the evaluated expression. If // needed an optional string can be passed that will be appended to the default error message. It is // also possible to use format specifiers to customize the string. // // It is also possible to pass the Severity used for logging as an additional argument. This is // required if using a custom error message. // // Example: // Expected DoSomething(); // Expected DoAnotherThing(); // // Expected foo(){ // RETURN_IF_ERROR(DoSomething()); // RETURN_IF_ERROR(DoAnotherThing(), Severity::WARNING); // RETURN_IF_ERROR(DoAnotherThing(), Severity::WARNING, "Custom error message."); // } #define RETURN_IF_ERROR(expression, ...) \ ({ \ auto maybe_result = (expression); \ EXPECTED_MACRO_INTERNAL_CHECK_EXPRESSION_IS_RESULT(maybe_result) \ if (!nvidia::expected_macro::IsValid(maybe_result)) { \ EXPECTED_MACRO_INTERNAL_LOG_IN_EXPECT_MACRO(maybe_result, #expression, ##__VA_ARGS__) \ return nvidia::expected_macro::ProxyFactory::FromStatusOrUnwrappable(maybe_result); \ } \ }) // Evaluates an expression that returns a type that can be casted to a boolean. If the expression is // false it returns an error. This macro can only be used in functions returning a result type. // // The difference to RETURN_IF_ERROR is that this macro will always cast the expression to a // boolean. Thus if your expression returns a status that can be more than just true/false you will // loose the additional information. In those cases RETURN_IF_ERROR is preferred. Use this macro // only to check preconditions like a < b, or c != nullptr. // // Per default the macro already creates an error message that includes the evaluated expression. If // needed an optional string can be passed that will be appended to the default error message. It is // also possible to use format specifiers to customize the string. // // It is also possible to pass the Severity used for logging as an additional argument. This is // required if using a custom error message. // // Example: // Expected foo(){ // RETURN_IF_FALSE(1 > 2); // RETURN_IF_FALSE(1 > 2, Severity::WARNING); // RETURN_IF_FALSE(1 > 2, Severity::WARNING, "1 is not bigger than 2"); // } #define RETURN_IF_FALSE(expression, ...) \ do { \ const bool result = static_cast(expression); \ if (!result) { \ EXPECTED_MACRO_INTERNAL_LOG_IN_EXPECT_MACRO(result, #expression, ##__VA_ARGS__) \ return nvidia::expected_macro::ProxyFactory::FromStatusOrUnwrappable(result); \ } \ } while (0) // Evaluates an expression that returns an unwrappable type. If the returned type contains an error // it returns the error, else it unwraps the value. This macro can only be used in functions // returning a result type. // // Per default the macro already creates an error message that includes the evaluated expression. If // needed an optional string can be passed that will be appended to the default error message. It is // also possible to use format specifiers to customize the string. // // It is also possible to pass the Severity used for logging as an additional argument. // // Note that this macro uses expression-statements (i.e. the ({ }) surrounding the macro) which are // a non-standard functionality. However they are present in almost all compilers. We currently only // know of MSVC that does not support this. // // Example: // Expected GetString(); // Expected GetAnotherString(); // // Expected CountCombinedStringLength(){ // const std::string str1 = UNWRAP_OR_RETURN(GetString()); // std::string str2; // str2 = UNWRAP_OR_RETURN(GetAnotherString(), "This should not fail. Str1 has value %s.", // str1.c_str()); // const std::string str3 = UNWRAP_OR_RETURN(GetAnotherString(), Severity::WARNING); // const std::string str4 = UNWRAP_OR_RETURN(GetAnotherString(), Severity::WARNING, // "Custom error message"); // return str1.size() + str2.size() + str3.size() + str4.size(); // } #define UNWRAP_OR_RETURN(expression, ...) \ ({ \ auto maybe_result = (expression); \ EXPECTED_MACRO_INTERNAL_CHECK_EXPRESSION_IS_UNWRAPPABLE(maybe_result) \ if (!nvidia::expected_macro::IsValid(maybe_result)) { \ EXPECTED_MACRO_INTERNAL_LOG_IN_EXPECT_MACRO(maybe_result, #expression, ##__VA_ARGS__) \ return nvidia::expected_macro::ProxyFactory::FromUnwrappable(maybe_result); \ } \ std::move(maybe_result.value()); \ }) // All functions in the following namespace have to be specialized for a given result type in order // to enable the macro for the type. namespace nvidia::expected_macro { // Type trait to check if a type can be used as a status. template struct IsStatus : std::false_type {}; // Type trait to check if a type can be used as an unwrappable. template struct IsUnwrappable : std::false_type {}; // The value that represents the default error for a given status type. template constexpr Status DefaultError(); // Check if a result types is valid. template constexpr bool IsValid(const Result& result) { return static_cast(result); } // Helper struct to get the status type of a result. This is needed for the StatusValue helper below // to automatically infer the return type. // // Per default we use the same type as the // result, which holds for all status types. Thus this only has to be specialized for unwrappable // types. template struct StatusType { using Type = Result; }; // Helper function to get the status of a result. We have to use a static member function instead of // a free function because we want the possibility for a user to only provide a partial template // specialization of this. template struct StatusValue { static constexpr typename StatusType::Type Get(const Result& result) { return result; } }; // Get the name corresponding to a status, s.t. it can be printed. template struct StatusName { static std::string Get(Status status); }; // Get the invalid unwrappable corresponding to an unwrappable. Eg. std::nullopt for std::optional. template struct InvalidUnwrappable { static Unwrappable Get(Status status); }; constexpr Severity kDefaultSeverity = Severity::ERROR; template constexpr typename StatusType::Type GetStatus(const Result& result) { return StatusValue::Get(result); } template std::string GetStatusName(Status status) { return StatusName::Get(status); } template Unwrappable GetInvalidUnwrappable(Status status) { return InvalidUnwrappable::Get(status); } // ProxyFactory to create an ResultProxy. We create a separate class for these functions // because ResultProxy is templated and thus could not be used without explicitly // specifying the template. template class ResultProxy; // ProxyFactory to create an ResultProxy. We create a separate class for these functions // because ResultProxy is templated and thus could not be used without explicitly // specifying the template. class ProxyFactory { public: // Constructs the proxy from an unwrappable type. The unwrappable has to be in an error state. We // do not check this because the macro should have already done this check. We use static // methods instead of constructors to explicitly disallow construction from certain types in // different situations. template < typename Unwrappable, typename = std::enable_if_t::value>> static ResultProxy::Type> FromUnwrappable( const Unwrappable& unwrappable) { return ResultProxy(GetStatus(unwrappable)); } // Constructs the proxy from a status type. The status has to be in an error state. We do not // check this because the macro should have already done this check. We use static methods instead // of constructors to explicitly disallow construction from certain types in different situations. template static ResultProxy::Type> FromStatusOrUnwrappable( const Result& result) { return ResultProxy(GetStatus(result)); } }; // A proxy class to allow implicit casting of one result type to another result type. Thus in a // function that returns a result type one can simply return this proxy and then it will implicitly // cast to the appropriate return type. template class ResultProxy { public: // Casts the proxy to a status or unwrappable type. Note that this cast is not allowed to be // explicit. template < typename T, typename = std::enable_if_t::value || IsUnwrappable::value>> constexpr operator T() const { if constexpr (IsStatus::value) { return castToStatus(); } else { return castToInvalidUnwrappable(); } } private: // Constructs the proxy from a status type. The status has to be in an error state. // We do not check for this because we rely on the macro already having done that check. constexpr explicit ResultProxy(Status error) : error_(error) {} // Casts the proxy to a status type. If the error type is not equal to the proxy's error type, // a default error is used. template constexpr OtherStatus castToStatus() const { static_assert(IsStatus::value, "OtherStatus has to be a status type."); if constexpr (std::is_same_v) { return error_; } else { return DefaultError(); } } // Casts the proxy to an invalid unwrappable type (eg. std::nullopt or nvidia::Unexpected). template constexpr Unwrappable castToInvalidUnwrappable() const { static_assert( IsUnwrappable::value, "Unwrappable has to be a status type."); using OtherStatus = typename StatusType::Type; return GetInvalidUnwrappable(castToStatus()); } Status error_; // TODO(tazhang): enable the following. // static_assert(IsStatus::value, "Status has to be a status type."); friend ProxyFactory; }; // Helper function for the logging in the above macros. This version should be used when the user // also specifies the logging severity. The variadic arguments can be used to do string // interpolation in the custom_text variable. template void LogHelper(const char* file, int line, const ExpressionResult& expression_result, const std::string& expression_string, Severity severity, const std::string& custom_txt = "", Args... args) { const auto error = GetStatus(expression_result); const std::string text = "Expression '" + expression_string + "' failed with error '" + GetStatusName(error) + "'. " + custom_txt; // GCC is not able to do format security validation when the string is coming from a variadic // template, even if the string is originally a char* ignore this warning until a more recent GCC // version fixes this behavior. #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-security" ::nvidia::Log(file, line, severity, text.c_str(), args...); #pragma GCC diagnostic pop } // Overload of the LogHelper above. This version does not take the severity as an argument and used // the default severity instead. template void LogHelper(const char* file, int line, const ExpressionResult& expression_result, const std::string& expression_string, const std::string& custom_text = "", Args... args) { LogHelper(file, line, expression_result, expression_string, kDefaultSeverity, custom_text, args...); } } // namespace nvidia::expected_macro ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/component.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_COMPONENT_HPP #define NVIDIA_GXF_CORE_COMPONENT_HPP #include #include #include #include #include "common/assert.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" #include "gxf/core/handle.hpp" #include "gxf/core/parameter.hpp" #include "gxf/core/parameter_storage.hpp" #include "gxf/core/registrar.hpp" namespace nvidia { namespace gxf { // Components are parts of an entity and provide their functionality. The Component class is the // base class of all GXF components. class Component { public: virtual ~Component() = default; Component(const Component& component) = delete; Component(Component&& component) = delete; Component& operator=(const Component& component) = delete; Component& operator=(Component&& component) = delete; // Used to register all parameters of the components. Do not use this function for other purposes // as it might be called at anytime by the runtime. // // Example: // class Foo : public Component { // public: // gxf_result_t registerInterface(Registrar* registrar) override { // registrar->parameter(count_, "count", 1); // } // Parameter count_; // }; virtual gxf_result_t registerInterface(Registrar* registrar) { registrar_ = registrar; parameter_storage_ = registrar_->getParameterStorage(); registrar->registerParameterlessComponent(); return GXF_SUCCESS; } // Use to start the lifetime of a component and should be used instead of the constructor. // Called after all components of an entity are created. The order in which components within // the same entity are initialized is undefined. virtual gxf_result_t initialize() { return GXF_SUCCESS; } // Use to end the lifetime of a component and should be used instead of the deconstructor. // The order in which components within the same entity are deinitialized is undefined. virtual gxf_result_t deinitialize() { return GXF_SUCCESS; } gxf_context_t context() const noexcept { return context_; } gxf_uid_t eid() const noexcept { return eid_; } gxf_uid_t cid() const noexcept { return cid_; } gxf_tid_t tid() const noexcept { return tid_; } const char* type_name() const noexcept { return typename_; } // The entity which owns this component Entity entity() const noexcept { // FIXME(v1) check that value exists return Entity::Shared(context(), eid()).value(); } // Gets the name of the component const char* name() const noexcept { const char* result; const gxf_result_t code = GxfComponentName(context(), cid(), &result); return (code == GXF_SUCCESS) ? result : ""; } // This function shall only be called by GXF and is used to setup the component. void internalSetup(gxf_context_t context, gxf_uid_t eid, gxf_uid_t cid, Registrar* registrar) { context_ = context; eid_ = eid; cid_ = cid; GxfComponentType(context_, cid_, &tid_); GxfComponentTypeName(context_, tid_, &typename_); if (registrar) { registrar_ = registrar; parameter_storage_ = registrar_->getParameterStorage(); parameter_registrar_ = registrar_->getParameterRegistrar(); } } // query value of component parameter "key" template Expected getParameter(const char* key) { return parameter_storage_->get(cid_, key); } // set the parameter "key" and of type T with value template Expected setParameter(const char* key, T value) { if (!parameter_storage_) { return Unexpected{GXF_ARGUMENT_NULL}; } return parameter_storage_->set(cid_, key, std::move(value)); } // set a parameter "key" of handle type with value template Expected setParameter(const char* key, Handle& value) { if (!parameter_storage_) { return Unexpected{GXF_ARGUMENT_NULL}; } return parameter_storage_->setHandle(cid_, key, value->cid()); } // set the parameter "key" with the value in yaml node Expected parseParameter(const char* key, const YAML::Node& node, std::string prefix = "") { return parameter_storage_->parse(cid_, key, node, prefix); } // wrap the current value of the parameter "key" in a yaml node Expected wrapParameter(const char* key) { return parameter_storage_->wrap(cid_, key); } // query all parameters in the component of type T and return their ComponentParameterInfo struct template Expected> getParametersOfType() { gxf_tid_t tid = GxfTidNull(); auto result = GxfComponentType(context_, cid_, &tid); if (!isSuccessful(result)) { GXF_LOG_ERROR("Failed to find component type for cid [%ld]", cid_); return Unexpected{result}; } return parameter_registrar_->getParametersOfType(tid); } // query componentParameterInfo of parameter "key" Expected getParameterInfo(const char* key) { gxf_tid_t tid = GxfTidNull(); auto result = GxfComponentType(context_, cid_, &tid); if (!isSuccessful(result)) { GXF_LOG_ERROR("Failed to find component type for cid [%ld]", cid_); return Unexpected{result}; } ParameterRegistrar::ComponentParameterInfo info = *(GXF_UNWRAP_OR_RETURN(parameter_registrar_->getComponentParameterInfoPtr(tid, key))); return info; } protected: Component() = default; gxf_context_t context_ = kNullContext; gxf_uid_t eid_ = kNullUid; gxf_uid_t cid_ = kNullUid; gxf_tid_t tid_ = GxfTidNull(); const char* typename_ = "UNKNOWN"; Registrar* registrar_ = nullptr; ParameterRegistrar* parameter_registrar_ = nullptr; ParameterStorage* parameter_storage_ = nullptr; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/entity.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_ENTITY_HPP_ #define NVIDIA_GXF_CORE_ENTITY_HPP_ #include #include "common/assert.hpp" #include "common/fixed_vector.hpp" #include "common/type_name.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/expected_macro.hpp" #include "gxf/core/gxf.h" #include "gxf/core/handle.hpp" namespace nvidia { namespace gxf { /** * @brief All GXF objects are entities. An entity owns multiple components which define the functionality * of the entity. Entities themselves are nothing more than a unique identifier. Entities created using the * C++ type is ref counted. The ref count is automatically decreased when the entity object is destructed or * goes out of scope. * */ class Entity { public: /** * @brief Creates a new entity using the given context and optionally set the given name. The * caller of this api own's the object. The reference count is set to 1 and it is automatically * reduced when this object is destroyed or goes out of scope. * * @param context A valid GXF context * @param name Name for the entity object to be created * @return Expected Entity object wrapped in an expected type to capture error on failure */ static Expected New(gxf_context_t context, const char* name = nullptr) { gxf_uid_t eid; const GxfEntityCreateInfo info = {0}; void* item_ptr = nullptr; gxf_result_t code = GxfCreateEntityAndGetItem(context, &info, &eid, &item_ptr); if (code != GXF_SUCCESS) { return Unexpected{code}; } return Shared(context, eid, item_ptr); } /** * @brief Creates an entity handle based on an existing ID and takes ownership. * Reference count is not increased. * * @param context A valid GXF context * @param eid The unique object ID (UID) of a valid entity * @param item_ptr An optional entity item pointer * @return Expected Entity object wrapped in an expected type to capture error on failure */ static Expected Own(gxf_context_t context, gxf_uid_t eid, void* item_ptr = nullptr) { Entity result; result.context_ = context; result.eid_ = eid; result.entity_item_ptr_ = item_ptr; return result; } /** * @brief Creates an entity handle based on an existing ID and shares ownership. * Reference count is increased by one. * * @param context A valid GXF context * @param eid The unique object ID (UID) of a valid entity * @param item_ptr An optional entity item pointer * @return Expected Entity object wrapped in an expected type to capture error on failure */ static Expected Shared(gxf_context_t context, gxf_uid_t eid, void* ptr = nullptr) { Entity result; result.context_ = context; result.eid_ = eid; result.entity_item_ptr_ = ptr; const gxf_result_t code = GxfEntityRefCountInc(context, eid); if (code != GXF_SUCCESS) { return Unexpected{code}; } else { return result; } } /** * @brief Construct a new entity object using default constructor. * This is a null entity without a valid context of entity ID. * */ Entity() = default; /** * @brief Construct a new entity object by copying from another entity object. * * @param other A valid Entity object */ Entity(const Entity& other) { eid_ = other.eid(); context_ = other.context(); entity_item_ptr_ = other.entity_item_ptr(); if (eid_ != kNullUid) { // FIXME(dweikersdorf) How do we deal with failure? GxfEntityRefCountInc(context_, eid_); } } /** * @brief Construct a new entity object by moving the contents from an existing entity object. * * @param other A valid Entity object */ Entity(Entity&& other) { context_ = other.context_; eid_ = other.eid_; entity_item_ptr_ = other.entity_item_ptr_; other.context_ = kNullContext; other.eid_ = kNullUid; other.entity_item_ptr_ = kNullUid; } /** * @brief Operator overload for copy assignment operation * * @param other A valid Entity object * @return Entity& The resulting copied entity object */ Entity& operator=(const Entity& other) { // In case other point to the same entity, nothing needs to be done. if (eid_ == other.eid() && context_ == other.context()) { return *this; } if (eid_ != kNullUid) { release(); } context_ = other.context(); eid_ = other.eid(); entity_item_ptr_ = other.entity_item_ptr(); if (eid_ != kNullUid) { // FIXME(dweikersdorf) How do we deal with failure? GxfEntityRefCountInc(context_, eid_); } return *this; } /** * @brief Operator overload for move assignment operation * * @param other A valid Entity object * @return Entity& The resulting moved entity object */ Entity& operator=(Entity&& other) { // In case other is this, then nothing should be done. if (&other == this) { return *this; } if (eid_ != kNullUid) { release(); } context_ = other.context_; eid_ = other.eid_; entity_item_ptr_ = other.entity_item_ptr_; other.entity_item_ptr_ = nullptr; other.context_ = kNullContext; other.eid_ = kNullUid; return *this; } /** * @brief Destroy the Entity object. Reduces the reference count by 1. * */ ~Entity() { if (eid_ != kNullUid) { release(); } } /** * @brief Activates the entity. See GxfEntityActivate in gxf.h * * @return Expected */ Expected activate() { return ExpectedOrCode(GxfEntityActivate(context(), eid())); } /** * @brief Deactivates the entity. See GxfEntityDectivate in gxf.h * * @return Expected */ Expected deactivate() { return ExpectedOrCode(GxfEntityDeactivate(context(), eid())); } /** * @brief Clone an entity from an existing entity object. The returned entity shares the * ownership with the entity being cloned from. Reference count is increased by one. * * @return Expected */ Expected clone() const { return Shared(context(), eid(), entity_item_ptr()); } /** * @brief Returns the GXF context of the entity. * * @return gxf_context_t */ gxf_context_t context() const { return context_; } /** * @brief Returns the unique object ID (UID) of the entity * * @return gxf_uid_t */ gxf_uid_t eid() const { return eid_; } /** * @brief Checks if an entity object is null (empty) or not * * @return true If entity is not null (empty) entity object * @return false If the entity is a valid object */ bool is_null() const { return eid_ == kNullUid; } /** * @brief The name of the entity or empty string if no name has been given to the entity. * * @return const char* pointer to name of the entity */ const char* name() const { const char* ptr; const gxf_result_t result = GxfEntityGetName(context_, eid_, &ptr); return (result == GXF_SUCCESS) ? ptr : ""; } /** * @brief Adds a component with given type ID. * * @param tid A valid type ID of a registered component * @param name Name to be given to the newly created component instance * @return Expected An untyped handle to component or error on failure */ Expected add(gxf_tid_t tid, const char* name = nullptr) { gxf_uid_t cid; void* comp_ptr = nullptr; GXF_RETURN_IF_ERROR(check_entity_item_ptr()); const auto result = GxfComponentAddAndGetPtr(context(), entity_item_ptr(), tid, name, &cid, &comp_ptr); if (result != GXF_SUCCESS) { return Unexpected{result}; } return UntypedHandle::Create(context(), cid, tid, comp_ptr); } /** * @brief Removes a component with given type ID. * * @param tid A valid type ID of a registered component * @param name Name to be given to the newly created component instance * @return Expected or error on failure */ Expected remove(gxf_tid_t tid, const char* name = nullptr) { // TODO(pshekdar): Add new API GxfComponentRemoveCpp const auto result = GxfComponentRemove(context(), eid(), tid, name); return ExpectedOrCode(result); } /** * @brief Adds a component with given template component type * * @tparam T A valid template type of a registered component * @param name Name to be given to the newly created component instance * @return Expected> Typed Handle to the component instance */ template Expected> add(const char* name = nullptr) { gxf_tid_t tid; const auto result_1 = GxfComponentTypeId(context(), TypenameAsString(), &tid); if (result_1 != GXF_SUCCESS) { return Unexpected{result_1}; } gxf_uid_t cid; void* comp_ptr = nullptr; GXF_RETURN_IF_ERROR(check_entity_item_ptr()); const auto result_2 = GxfComponentAddAndGetPtr(context(), entity_item_ptr(), tid, name, &cid, &comp_ptr); if (result_2 != GXF_SUCCESS) { return Unexpected{result_2}; } return Handle::Create(context(), cid, tid, comp_ptr); } /** * @brief Removes a component with given template component type * * @tparam T A valid template type of a registered component * @param name Name of the component * @return Expected or error on failure */ template Expected remove(const char* name = nullptr) { gxf_tid_t tid; // TODO(pshekdar): Add new API GxfComponentRemoveCpp const auto result_1 = GxfComponentTypeId(context(), TypenameAsString(), &tid); if (result_1 != GXF_SUCCESS) { return Unexpected{result_1}; } const auto result_2 = GxfComponentRemove(context(), eid(), tid, name); return ExpectedOrCode(result_2); } /** * @brief Removes a component with given uid * * @tparam cid A valid uid of the component * @return Expected or error on failure */ Expected remove(gxf_uid_t& cid) { const auto result = GxfComponentRemoveWithUID(context(), cid); return ExpectedOrCode(result); } /** * @brief Gets a component by type ID. Asserts if no such component. * * @param tid A valid type ID of a registered component * @param name Name of the component to lookup * @return Expected An untyped handle to component or error on failure */ Expected get(gxf_tid_t tid, const char* name = nullptr) const { gxf_uid_t cid; void* comp_ptr = nullptr; GXF_RETURN_IF_ERROR(check_entity_item_ptr()); const auto result = GxfComponentFindAndGetPtr(context(), eid(), static_cast(entity_item_ptr()), tid, name, nullptr, &cid, &comp_ptr); if (result != GXF_SUCCESS) { return Unexpected{result}; } return UntypedHandle::Create(context(), cid, tid, comp_ptr); } /** * @brief Gets a component by type. Asserts if no such component. * * @tparam T A valid template type of a registered component * @param name Name of the component to lookup * @return Expected> Typed Handle to the component instance or error on failure */ template Expected> get(const char* name = nullptr) const { gxf_tid_t tid; GXF_RETURN_IF_ERROR(check_entity_item_ptr()); const auto result_1 = GxfComponentTypeId(context(), TypenameAsString(), &tid); if (result_1 != GXF_SUCCESS) { return Unexpected{result_1}; } gxf_uid_t cid; void* comp_ptr = nullptr; const auto result_2 = GxfComponentFindAndGetPtr(context(), eid(), static_cast(entity_item_ptr()), tid, name, nullptr, &cid, &comp_ptr); if (result_2 != GXF_SUCCESS) { return Unexpected{result_2}; } return Handle::Create(context(), cid, tid, comp_ptr); } /** * @brief Finds all components in an entity. A fixed-size vector of untyped handles of all the * components are returned. * * @tparam N Capacity of the FixedVector * @return Expected> A fixed-size vector of untyped handles of all * the components allocated on stack */ template Expected> findAll() const { const gxf_context_t c_context = context(); const gxf_uid_t c_eid = eid(); gxf_uid_t cids[N]; uint64_t num_cids = N; const gxf_result_t code = GxfComponentFindAll(c_context, c_eid, &num_cids, cids); if (code != GXF_SUCCESS) { return Unexpected{code}; } /* coverity[stack_use_local_overflow] */ FixedVector components; for (size_t i = 0; i < num_cids; i++) { const auto result = UntypedHandle::Create(c_context, cids[i]) .map([&](UntypedHandle component) { return components.push_back(component) .substitute_error(GXF_EXCEEDING_PREALLOCATED_SIZE); }); if (!result) { return ForwardError(result); } } return components; } /** * @brief Finds all components of given type. * * @tparam T A valid template type of a registered component * @tparam N Capacity of the FixedVector * @return Expected, N>> A fixed-size vector of typed handles of given * component type allocated on stack */ template Expected, N>> findAll() const { const gxf_context_t c_context = context(); const gxf_uid_t c_eid = eid(); gxf_tid_t tid; const gxf_result_t code = GxfComponentTypeId(c_context, TypenameAsString(), &tid); if (code != GXF_SUCCESS) { return Unexpected{code}; } /* coverity[stack_use_local_overflow] */ FixedVector, N> components; for (int offset = 0; static_cast(offset) < N; offset++) { gxf_uid_t cid; const gxf_result_t code = GxfComponentFind(c_context, c_eid, tid, nullptr, &offset, &cid); if (code != GXF_SUCCESS) { break; } const auto result = Handle::Create(c_context, cid) .map([&](Handle component) { return components.push_back(component) .substitute_error(GXF_EXCEEDING_PREALLOCATED_SIZE); }); if (!result) { return ForwardError(result); } } return components; } /** * @brief Finds all components in an entity. A fixed-size vector of untyped handles of all the * components are returned. * * @tparam N Capacity of the FixedVector * @return Expected> A fixed-size vector of untyped handles of all * the components allocated on heap */ template Expected> findAllHeap() const { const gxf_context_t c_context = context(); const gxf_uid_t c_eid = eid(); gxf_uid_t cids[N]; uint64_t num_cids = N; const gxf_result_t code = GxfComponentFindAll(c_context, c_eid, &num_cids, cids); if (code != GXF_SUCCESS) { return Unexpected{code}; } FixedVector components; components.reserve(num_cids); for (size_t i = 0; i < num_cids; i++) { const auto result = UntypedHandle::Create(c_context, cids[i]) .map([&](UntypedHandle component) { return components.push_back(component) .substitute_error(GXF_EXCEEDING_PREALLOCATED_SIZE); }); if (!result) { return ForwardError(result); } } return components; } /** * @brief Finds all components of given type. * * @tparam T A valid template type of a registered component * @tparam N Capacity of the FixedVector * @return Expected>> A fixed-size vector of typed handles of given * component type allocated on heap */ template Expected>> findAllHeap() const { const gxf_context_t c_context = context(); const gxf_uid_t c_eid = eid(); gxf_tid_t tid; const gxf_result_t code = GxfComponentTypeId(c_context, TypenameAsString(), &tid); if (code != GXF_SUCCESS) { return Unexpected{code}; } FixedVector> components; components.reserve(N); for (int offset = 0; static_cast(offset) < N; offset++) { gxf_uid_t cid; const gxf_result_t code = GxfComponentFind(c_context, c_eid, tid, nullptr, &offset, &cid); if (code != GXF_SUCCESS) { break; } const auto result = Handle::Create(c_context, cid) .map([&](Handle component) { return components.push_back(component) .substitute_error(GXF_EXCEEDING_PREALLOCATED_SIZE); }); if (!result) { return ForwardError(result); } } return components; } /** * @brief Returns the pointer to Entity Item for the entity * * @return void * entity item ptr */ void* entity_item_ptr() const { check_entity_item_ptr(); return entity_item_ptr_; } private: /** * @brief Set the entity item ptr if its not set already * * @return Expected Success or error code */ Expected check_entity_item_ptr() const { if (entity_item_ptr_ != nullptr) { return Success; } auto code = GxfEntityGetItemPtr(context(), eid(), reinterpret_cast(&(entity_item_ptr_))); return code == GXF_SUCCESS ? Success : Unexpected(code); } void release() { GxfEntityRefCountDec(context_, eid_); // TODO(v2) We should use the error code, but we can't // do anything about it.. eid_ = kNullUid; entity_item_ptr_ = nullptr; } gxf_context_t context_ = kNullContext; gxf_uid_t eid_ = kNullUid; mutable void* entity_item_ptr_ = nullptr; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CORE_ENTITY_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/expected.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_EXPECTED_HPP #define NVIDIA_GXF_CORE_EXPECTED_HPP #include #include #include "common/expected.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { // Expected type for GXF which uses gxf_result_t as error code. template using Expected = Expected; // Unexpected type for GXF which uses gxf_result_t as error code. using Unexpected = Unexpected; // Special value which can be used instead of {} to return from a function which returns an // Expected. const Expected Success{}; // Extracts the error code as an unexpected. template Unexpected ForwardError(const Expected& expected) { return Unexpected{expected.error()}; } // Extracts the error code as an unexpected. template Unexpected ForwardError(Expected&& expected) { return Unexpected{std::move(expected.error())}; } // Interprets an expected as a result code. Returns GXF_SUCESS if the result has a value and the // result's error code otherwise. template gxf_result_t ToResultCode(const Expected& result) { return result ? GXF_SUCCESS : result.error(); } // If the result code is GXF_SUCCESS the function returns Success, otherwise it returns an // unexpected with the given error code. inline Expected ExpectedOrCode(gxf_result_t code) { if (code == GXF_SUCCESS) { return Success; } else { return Unexpected{code}; } } // If the result code is GXF_SUCCESS the function returns the given value, otherwise it returns an // unexpected with the given error code. template Expected>> ExpectedOrCode(gxf_result_t code, T&& value) { if (code == GXF_SUCCESS) { return std::forward(value); } else { return Unexpected{code}; } } template Expected>> ExpectedOrError(const Expected& code, T&& value) { if (code) { return std::forward(value); } else { return ForwardError(code); } } inline gxf_result_t AccumulateError(gxf_result_t previous, gxf_result_t current) { return current != GXF_SUCCESS ? current : previous; } inline Expected AccumulateError(Expected previous, Expected current) { return !current ? current : previous; } } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/expected_macro.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gxf/core/common_expected_macro.hpp" #include "gxf/core/expected.hpp" #include "magic_enum.hpp" // NOLINT(build/include) ////////////////////////////////////////// // Configuration for using bool as status: ////////////////////////////////////////// namespace nvidia::expected_macro { // This section contains the configuration to use the expected macro with // different return types like bool, int, std::optional (and in the future std::expected). template <> struct IsStatus : std::true_type {}; template <> constexpr bool DefaultError() { return false; } template <> struct StatusName { static std::string Get(bool status) { return status ? "Success" : "Failure"; } }; ///////////////////////////////////////// // Configuration for using int as status: ///////////////////////////////////////// template <> struct IsStatus : std::true_type {}; template <> constexpr bool IsValid(const int& status) { return status == 0; } template <> constexpr int DefaultError() { return 1; } template <> struct StatusName { static std::string Get(int status) { return std::to_string(status); } }; ////////////////////////////////////////// // Configuration for using enum as status: ////////////////////////////////////////// template struct StatusName>> { static std::string Get(EnumStatus status) { return std::string(magic_enum::enum_name(status)); } }; //////////////////////////////////////////////////////// // Configuration for using std::optional as unwrappable: //////////////////////////////////////////////////////// template struct IsUnwrappable> : std::true_type {}; template struct StatusType> { using Type = bool; }; template struct StatusValue> { static constexpr bool Get(const std::optional& optional) { return optional.has_value(); } }; template struct InvalidUnwrappable, bool> { static std::optional Get(bool status) { return std::nullopt; } }; /////////////////////////////////////////////////////////// // Configuration for using nvidia::Expected as unwrappable: /////////////////////////////////////////////////////////// template struct IsUnwrappable<::nvidia::Expected> : std::true_type {}; template struct StatusType<::nvidia::Expected> { using Type = Status; }; template struct StatusValue<::nvidia::Expected> { static constexpr Status Get(const ::nvidia::Expected& expected) { return expected.error(); } }; template struct InvalidUnwrappable<::nvidia::Expected, Status> { static ::nvidia::Expected Get(Status status) { return ::nvidia::Unexpected(status); } }; // This customizes the expected macro, s.t. it can be used with gxf_result_t. template <> struct IsStatus : std::true_type {}; template <> constexpr bool IsValid(const gxf_result_t& status) { return status == GXF_SUCCESS; } template <> constexpr gxf_result_t DefaultError() { return GXF_FAILURE; } template <> struct StatusName { static std::string Get(gxf_result_t status) { return GxfResultStr(status); } }; // For back-compatibility we define an alias to the original name of the macro when it was gxf // specific. #define GXF_RETURN_IF_ERROR RETURN_IF_ERROR #define GXF_UNWRAP_OR_RETURN UNWRAP_OR_RETURN } // namespace nvidia::expected_macro ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/filepath.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_FILEPATH_HPP_ #define NVIDIA_GXF_CORE_FILEPATH_HPP_ #include #include "yaml-cpp/yaml.h" namespace nvidia { namespace gxf { // Specialization of ParameterParser for a file parameter type to identify parameters that are file // system paths struct FilePath : public std::string { FilePath() : std::string() {} FilePath(const char* s) : std::string(s) {} FilePath(const std::string& str) : std::string(str) {} }; } // namespace gxf } // namespace nvidia template<> struct YAML::convert { static Node encode(const nvidia::gxf::FilePath& data) { Node node = YAML::Load(data); return node; } static bool decode(const Node& node, nvidia::gxf::FilePath& data) { if (!node.IsScalar()) { return false; } data = node.as(); return true; } }; #endif // NVIDIA_GXF_CORE_FILEPATH_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/gxf.h ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_GXF_H_ #define NVIDIA_GXF_CORE_GXF_H_ #ifdef __cplusplus #include #include #else #include #endif #ifdef __cplusplus extern "C" { #endif // -- Result type -------------------------------------------------------------------------------- /// @brief GXF error and result codes which are used by almost all GXF functions. typedef enum { GXF_SUCCESS = 0, GXF_FAILURE = 1, GXF_NOT_IMPLEMENTED, GXF_FILE_NOT_FOUND, GXF_INVALID_ENUM, GXF_NULL_POINTER, GXF_UNINITIALIZED_VALUE, GXF_ARGUMENT_NULL, GXF_ARGUMENT_OUT_OF_RANGE, GXF_ARGUMENT_INVALID, GXF_OUT_OF_MEMORY, GXF_MEMORY_INVALID_STORAGE_MODE, GXF_CONTEXT_INVALID, GXF_EXTENSION_NOT_FOUND, GXF_EXTENSION_FILE_NOT_FOUND, GXF_EXTENSION_NO_FACTORY, GXF_FACTORY_TOO_MANY_COMPONENTS, GXF_FACTORY_DUPLICATE_TID, GXF_FACTORY_UNKNOWN_TID, GXF_FACTORY_ABSTRACT_CLASS, GXF_FACTORY_UNKNOWN_CLASS_NAME, GXF_FACTORY_INVALID_INFO, GXF_FACTORY_INCOMPATIBLE, GXF_ENTITY_NOT_FOUND, GXF_ENTITY_NAME_EXCEEDS_LIMIT, GXF_ENTITY_COMPONENT_NOT_FOUND, GXF_ENTITY_COMPONENT_NAME_EXCEEDS_LIMIT, GXF_ENTITY_CAN_NOT_ADD_COMPONENT_AFTER_INITIALIZATION, GXF_ENTITY_CAN_NOT_REMOVE_COMPONENT_AFTER_INITIALIZATION, GXF_ENTITY_MAX_COMPONENTS_LIMIT_EXCEEDED, GXF_PARAMETER_NOT_FOUND, GXF_PARAMETER_ALREADY_REGISTERED, GXF_PARAMETER_INVALID_TYPE, GXF_PARAMETER_OUT_OF_RANGE, GXF_PARAMETER_NOT_INITIALIZED, GXF_PARAMETER_CAN_NOT_MODIFY_CONSTANT, GXF_PARAMETER_PARSER_ERROR, GXF_PARAMETER_NOT_NUMERIC, GXF_PARAMETER_MANDATORY_NOT_SET, GXF_CONTRACT_INVALID_SEQUENCE, GXF_CONTRACT_PARAMETER_NOT_SET, GXF_CONTRACT_MESSAGE_NOT_AVAILABLE, GXF_INVALID_LIFECYCLE_STAGE, GXF_INVALID_EXECUTION_SEQUENCE, GXF_REF_COUNT_NEGATIVE, GXF_RESULT_ARRAY_TOO_SMALL, GXF_INVALID_DATA_FORMAT, GXF_EXCEEDING_PREALLOCATED_SIZE, GXF_QUERY_NOT_ENOUGH_CAPACITY, GXF_QUERY_NOT_APPLICABLE, GXF_QUERY_NOT_FOUND, GXF_NOT_FINISHED, GXF_HTTP_GET_FAILURE, GXF_HTTP_POST_FAILURE, GXF_ENTITY_GROUP_NOT_FOUND, GXF_RESOURCE_NOT_INITIALIZED, GXF_RESOURCE_NOT_FOUND, GXF_CONNECTION_BROKEN, GXF_CONNECTION_ATTEMPTS_EXCEEDED, GXF_IPC_CONNECTION_FAILURE, GXF_IPC_CALL_FAILURE, GXF_IPC_SERVICE_NOT_FOUND, } gxf_result_t; /// @brief Checks if a result code is GXF_SUCCESS or not /// /// @param result A GXF result code /// @return A boolean value indicating if the result code is GXF_SUCCESS bool isSuccessful(gxf_result_t result); /// @brief Gets a string describing an GXF error code. /// /// The caller does not get ownership of the return C string and must not delete it. /// /// @param result A GXF error code /// @return A pointer to a C string with the error code description. const char* GxfResultStr(gxf_result_t result); // -- Unique identifiers ------------------------------------------------------------------------- /// @brief Type of unique GXF object identifiers (UID/uid) /// /// Uids are used to reference entities and components throughout the GXF API. typedef int64_t gxf_uid_t; /// @brief A GXF UID which can be used to indicate an invalid or unused GXF UID. #define kNullUid 0L /// @brief A GXF UID which can be used to indicate an unspecified component during /// graph load operation. This component should be updated in a subsequent /// graph/parameters file. Failing to do so will result in an error during graph activation #define kUnspecifiedUid -1L /// @brief Type of unique GXF type identifier (TID/tid) /// /// Tids are used to uniquely identify the type of a component, instead of for example using /// a string with the type name. typedef struct { uint64_t hash1; uint64_t hash2; } gxf_tid_t; /// @brief Gives the null value of a GXF tid /// /// The null tid is used to mark a tid as invalid or to indicate that a tid is not set. /// /// @return The null tid inline gxf_tid_t GxfTidNull() { gxf_tid_t result; result.hash1 = 0UL; result.hash2 = 0UL; return result; } /// @brief Determines if a GXF tid is null /// /// @param tid A GXF tid /// @return Returns 1 if 'tid' is the null tid; and 0 otherwise. inline uint32_t GxfTidIsNull(gxf_tid_t tid) { return (tid.hash1 == 0UL && tid.hash2 == 0UL) ? 1 : 0; } // -- Context ------------------------------------------------------------------------------------ /// @brief Type for context handle typedef void* gxf_context_t; /// @brief An invalid context #define kNullContext nullptr /// @brief GXF Core Version #define kGxfCoreVersion "5.1.0" /// @brief Creates a new GXF context /// /// A GXF context is required for all almost all GXF operations. The context must be destroyed with /// 'GxfContextDestroy'. Multiple contexts can be created in the same process, however they can not /// communicate with each other. /// /// @param context The new GXF context is written to the given pointer. /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfContextCreate(gxf_context_t* context); /// @brief Creates a new runtime context from shared context. /// /// A shared runtime context is used for sharing entities between graphs running /// within the same process. /// /// @param shared A valid GXF shared context. /// @param context The new GXF context is written to the given pointer. gxf_result_t GxfContextCreateShared(gxf_context_t shared, gxf_context_t* context); /// @brief Gets a GXF shared context. /// /// A GXF context is required for all almost all GXF operations. The context /// must be destroyed with 'GxfContextDestroy'. A shared runtime context is used /// for sharing entities between graphs running within the same process. /// /// @param shared The shared GXF context is written to this pointer. /// @param context A valid GXF context /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the /// GXF error codes. gxf_result_t GxfGetSharedContext(gxf_context_t context, gxf_context_t* shared); /// @brief Destroys a GXF context /// /// Every GXF context must be destroyed by calling this function. The context must have been /// previously created with 'GxfContextCreate'. This will also destroy all entities and components /// which were created as part of the context. /// /// @param context A valid GXF context. /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfContextDestroy(gxf_context_t context); // -- Extensions --------------------------------------------------------------------------------- /// @brief Maximum number of extensions in a context #define kMaxExtensions 1024 /// @brief Loads an extension from a pointer to the Extension object. /// /// `extension_ptr` must be a pointer to a valid object with `Extension` type. /// @param context A valid GXF context /// @param extension_ptr A pointer to Extension /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfLoadExtensionFromPointer(gxf_context_t context, void* extension_ptr); /// @brief Registers a component with a GXF extension /// /// A GXF extension need to register all of its components in the extension factory function. For /// convenience the helper macros in gxf/std/extension_factory_helper.hpp can be used. /// /// The developer must choose a unique GXF tid with two random 64-bit integers. The developer /// must ensure that every GXF component has a unique tid. The name of the component must be /// the fully qualified C++ type name of the component. A component may only have a single base /// class and that base class must be specified with its fully qualified C++ type name as the /// parameter 'base_name'. /// /// @see gxf/std/extension_factory_helper.hpp /// @see core/type_name.hpp /// /// @param context A valid GXF context /// @param tid The chosen GXF tid /// @param name The type name of the component /// @param base_name The type name of the base class of the component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfRegisterComponent(gxf_context_t context, gxf_tid_t tid, const char* name, const char* base_name); /// @brief Registers a new component from an extension during runtime /// /// Once an extension is loaded any newly added components to that extension can be registered /// with the context using this function /// /// @param context A valid GXF context /// @param component_tid The valid GXF tid of a unregistered new component /// @param extension_tid The valid GXF tid of an extension which has already been loaded /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfRegisterComponentInExtension(gxf_context_t context, gxf_tid_t component_tid, gxf_tid_t extension_tid); // -- Entities ----------------------------------------------------------------------------------- /// @brief Maximum number of entities in a context #define kMaxEntities 1024 /// @brief various lifecycle states of an entity typedef enum { GXF_ENTITY_STATUS_NOT_STARTED = 0, GXF_ENTITY_STATUS_START_PENDING, GXF_ENTITY_STATUS_STARTED, GXF_ENTITY_STATUS_TICK_PENDING, GXF_ENTITY_STATUS_TICKING, GXF_ENTITY_STATUS_IDLE, GXF_ENTITY_STATUS_STOP_PENDING, GXF_ENTITY_MAX } gxf_entity_status_t; /// @brief Gets a string describing an GXF entity status. /// /// The caller does not get ownership of the return C string and must not delete it. /// /// @param status A GXF entity status /// @return A pointer to a C string with the entity status description. const char* GxfEntityStatusStr(gxf_entity_status_t status); /// @brief Used by behavior parent codelet in Behavior Tree denoting the result /// of codelet::tick() /// - GXF_BEHAVIOR_INIT is for codelet that have not yet started running. /// - GXF_BEHAVIOR_SUCCESS is for codelet that terminates with success after /// ticking /// - GXF_BEHAVIOR_RUNNING is for codelet that needs multiple ticks to complete /// - GXF_BEHAVIOR_FAILURE is for codelet that terminates with failure after /// ticking /// - GXF_BEHAVIOR_UNKNOWN is for non-behavior-tree codelet because we don't /// care about the behavior status returned by controller if it is not a BT /// codelet typedef enum { GXF_BEHAVIOR_INIT = 0, GXF_BEHAVIOR_SUCCESS = 1, GXF_BEHAVIOR_RUNNING = 2, GXF_BEHAVIOR_FAILURE = 3, GXF_BEHAVIOR_UNKNOWN = 4, } entity_state_t; /// @brief Activates a previously created and inactive entity /// /// Activating an entity generally marks the official start of its lifetime and has multiple /// implications: /// - If mandatory parameters, i.e. parameter which do not have the flag "optional", are not set /// the operation will fail. /// - All components on the entity are initialized. /// - All codelets on the entity are scheduled for execution. The scheduler will start calling /// start, tick and stop functions as specified by scheduling terms. /// - After activation trying to change a dynamic parameters will result in a failure. /// - Adding or removing components of an entity after activation will result in a failure. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @return GXF error code gxf_result_t GxfEntityActivate(gxf_context_t context, gxf_uid_t eid); /// @brief Deactivates a previously activated entity /// /// Deactivating an entity generally marks the official end of its lifetime and has multiple /// implications: /// - All codelets are removed from the schedule. Already running entities are run to completion. /// - All components on the entity are deinitialized. /// - Components can be added or removed again once the entity was deactivated. /// - Mandatory and non-dynamic parameters can be changed again. /// /// Note: In case that the entity is currently executing this function will wait and block until /// the current execution is finished. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @return GXF error code gxf_result_t GxfEntityDeactivate(gxf_context_t context, gxf_uid_t eid); /// @brief Destroys a previously created entity /// /// Destroys an entity immediately. The entity is destroyed even if the reference count has not /// yet reached 0. If the entity is active it is deactivated first. /// /// Note: This function can block for the same reasons as 'GxfEntityDeactivate'. /// /// @param context A valid GXF context /// @param eid The returned UID of the created entity /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityDestroy(gxf_context_t context, gxf_uid_t eid); /// @brief Finds an entity by its name /// /// @param context A valid GXF context /// @param name A C string with the name of the entity. Ownership is not transferred. /// @param eid The returned UID of the entity /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityFind(gxf_context_t context, const char* name, gxf_uid_t* eid); /// @brief Finds all entities in the current application /// /// Finds and returns all entity ids for the current application. If more than `max_entities` exist /// only `max_entities` will be returned. The order and selection of entities returned is arbitrary. /// /// @param context A valid GXF context /// @param num_entities In/Out: the max number of entities that can fit in the buffer/the number of /// entities that exist in the application /// @param entities A buffer allocated by the caller for returned UIDs of all entities, with /// capacity for `num_entities`. /// @return GXF_SUCCESS if the operation was successful, GXF_QUERY_NOT_ENOUGH_CAPACITY if more /// entities exist in the application than `max_entities`, or otherwise one of the GXF error codes. gxf_result_t GxfEntityFindAll(gxf_context_t context, uint64_t* num_entities, gxf_uid_t* entities); /// @brief Increases the reference count for an entity by 1. /// /// By default reference counting is disabled for an entity. This means that entities created with /// 'GxfCreateEntity' are not automatically destroyed. If this function is called for an entity /// with disabled reference count, reference counting is enabled and the reference count is set to /// 1. Once reference counting is enabled an entity will be automatically destroyed if the reference /// count reaches zero, or if 'GxfEntityDestroy' is called explicitly. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityRefCountInc(gxf_context_t context, gxf_uid_t eid); /// @brief Decreases the reference count for an entity by 1. /// /// See 'GxfEntityRefCountInc' for more details on reference counting. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityRefCountDec(gxf_context_t context, gxf_uid_t eid); /// @brief Provides the reference count for an entity. /// /// See 'GxfEntityRefCountInc' for more details on reference counting. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @param count The reference count of a valid entity /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityGetRefCount(gxf_context_t context, gxf_uid_t eid, int64_t* count); /// @brief Gets the status of the entity. /// /// See 'gxf_entity_status_t' for the various status. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @param entity_status output; status of an entity eid /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityGetStatus(gxf_context_t context, gxf_uid_t eid, gxf_entity_status_t* entity_status); /// @brief Gets the name of the entity. /// /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @param entity_name output; name of the entity /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityGetName(gxf_context_t context, gxf_uid_t eid, const char** entity_name); /// @brief Gets the state of the entity. /// /// See 'entity_state_t' for the various status. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @param entity_state output; behavior status of an entity eid used by the /// behavior tree parent codelet /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the /// GXF error codes gxf_result_t GxfEntityGetState(gxf_context_t context, gxf_uid_t eid, entity_state_t* entity_state); /// @brief Notifies the occurrence of an event and inform the scheduler to check /// the status of the entity /// /// The entity must have an 'AsynchronousSchedulingTerm' scheduling term /// component and it must be in "EVENT_WAITING" state for the notification to be /// acknowledged. /// /// See 'AsynchronousEventState' for various states /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the /// GXF error codes. gxf_result_t GxfEntityEventNotify(gxf_context_t context, gxf_uid_t eid); /// @brief Various type of events used to communicate with a GXF scheduler /// /// GXF_EVENT_EXTERNAL is supported by all GXF schedulers and the rest of the event types /// are supported by event based scheduler only. GXF_EVENT_EXTERNAL is typically intended /// to be used by events originating outside of the GXF framework by threads which are not /// owned by GXF. All other event types occur within GXF and each of them describe a specific /// event trigger scenario typedef enum { GXF_EVENT_CUSTOM = 0, GXF_EVENT_EXTERNAL = 1, GXF_EVENT_MEMORY_FREE = 2, GXF_EVENT_MESSAGE_SYNC = 3, GXF_EVENT_TIME_UPDATE = 4, GXF_EVENT_STATE_UPDATE = 5, } gxf_event_t; gxf_result_t GxfEntityNotifyEventType(gxf_context_t context, gxf_uid_t eid, gxf_event_t event); /// @brief Gets a string describing an GXF event type /// /// The caller does not get ownership of the return C string and must not delete it. /// /// @param result A GXF error code /// @return A pointer to a C string with the error code description. const char* GxfEventStr(gxf_event_t event); // -- Components --------------------------------------------------------------------------------- /// @brief Maximum number of components in an entity or extension #define kMaxComponents 1024 /// @brief Maximum number of characters in the name of an entity #define kMaxEntityNameSize 2048 /// @brief Maximum number of characters in the name of a component #define kMaxComponentNameSize 256 /// @brief Gets the GXF unique type ID (TID) of a component /// /// Get the unique type ID which was used to register the component with GXF. The function expects /// the fully qualified C++ type name of the component including namespaces. /// /// Example of a valid component type name: "nvidia::gxf::PingTx" /// /// @param context A valid GXF context /// @param name The fully qualified C++ type name of the component /// @param tid The returned TID of the component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentTypeId(gxf_context_t context, const char* name, gxf_tid_t* tid); /// @brief Gets the fully qualified C++ type name GXF component typename from a TID /// /// Get the unique typename of the component with which it was registered using one of /// the GXF_EXT_FACTORY_ADD*() macros /// /// @param context A valid GXF context /// @param tid The unique type ID (TID) of the component with which the component was registered /// @param name The returned name of the component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentTypeName(gxf_context_t context, gxf_tid_t tid, const char** name); /// @brief Gets the fully qualified C++ type name GXF component typename from a UID /// /// Get the unique typename of the component with which it was registered using one of /// the GXF_EXT_FACTORY_ADD*() macros /// /// @param context A valid GXF context /// @param cid The UID of a valid component /// @param name The returned typename of the component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentTypeNameFromUID(gxf_context_t context, gxf_uid_t cid, const char** name); /// @brief Gets the name of a component /// /// Each component has a user-defined name which was used in the call to 'GxfComponentAdd'. /// Usually the name is specified in the GXF application file. /// /// @param context A valid GXF context /// @param cid The unique object ID (UID) of the component /// @param name The returned name of the component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentName(gxf_context_t context, gxf_uid_t cid, const char** name); /// @brief Gets the unique object ID of the entity of a component /// /// Each component has a unique ID with respect to the context and is stored in one entity. This /// function can be used to retrieve the ID of the entity to which a given component belongs. /// /// @param context A valid GXF context /// @param cid The unique object ID (UID) of the component /// @param eid The returned unique object ID (UID) of the entity /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentEntity(gxf_context_t context, gxf_uid_t cid, gxf_uid_t* eid); /// @brief Gets the pointer to an entity item /// /// Each entity has a unique ID with respect to the context and is stored in the entity warden. This /// function can be used to retrieve the pointer to entity item stored in the entity warden for a /// given entity id. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of the entity /// @param ptr The returned pointer to the entity item /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityGetItemPtr(gxf_context_t context, gxf_uid_t eid, void** ptr); /// @brief Adds a new component to an entity /// /// An entity can contain multiple components and this function can be used to add a new component /// to an entity. A component must be added before an entity is activated, or after it was /// deactivated. Components must not be added to active entities. The order of components is stable /// and identical to the order in which components are added (see 'GxfComponentFind'). /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of the entity to which the component is added. /// @param tid The unique type ID (TID) of the component to be added to the entity. /// @param name The name of the new component. Ownership is not transferred. /// @param cid The returned UID of the created component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentAdd(gxf_context_t context, gxf_uid_t eid, gxf_tid_t tid, const char* name, gxf_uid_t* cid); /// @brief Adds a new component to an entity /// /// An entity can contain multiple components and this function can be used to add a new component /// to an Entity. A component must be added before an entity is activated, or after it was /// deactivated. Components must not be added to active entities. The order of components is stable /// and identical to the order in which components are added (see 'GxfComponentFind'). /// /// @param context A valid GXF context /// @param item_ptr The pointer to entity item /// @param tid The unique type ID (TID) of the component to be added to the entity. /// @param name The name of the new component. Ownership is not transferred. /// @param cid The returned UID of the created component /// @param comp_ptr The returned pointer to the created component object /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentAddAndGetPtr(gxf_context_t context, void* item_ptr, gxf_tid_t tid, const char* name, gxf_uid_t* cid, void ** comp_ptr); /// @brief Removes a component from an entity /// /// An entity can contain multiple components and this function can be used to remove a component /// from an entity. A component must be removed before an entity is activated, or after it was /// deactivated. Components must not be removed from active entities. /// /// @param context A valid GXF context /// @param cid The UID of the component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentRemoveWithUID(gxf_context_t context, gxf_uid_t cid); /// @brief Removes a component from an entity /// /// An entity can contain multiple components and this function can be used to remove a component /// from an entity. A component must be removed before an entity is activated, or after it was /// deactivated. Components must not be removed from active entities. /// /// @brief Adds an existing component to the interface of an entity /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of the entity to which the component is added. /// @param tid The unique type ID (TID) of the component to be added to the entity. /// @param name The name of the new component. Ownership is not transferred. /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentRemove(gxf_context_t context, gxf_uid_t eid, gxf_tid_t tid, const char * name); /// An entity can holds references to other components in its interface, so that when finding a /// component in an entity, both the component this entity holds and those it refers to will be /// returned. /// This supports the case when an entity contains a subgraph, then those components that has been /// declared in the subgraph interface will be put to the interface of the parent entity. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of the entity to which the component is added. /// @param cid The unique object ID of the component /// @param name The name of the new component. Ownership is not transferred. /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentAddToInterface(gxf_context_t context, gxf_uid_t eid, gxf_uid_t cid, const char* name); /// @brief Finds a component in an entity /// /// Searches components in an entity which satisfy certain criteria: component type, component /// name, and component min index. All three criteria are optional; in case no criteria is given /// the first component is returned. The main use case for "component min index" is a repeated /// search which continues at the index which was returned by a previous search. /// /// In case no entity with the given criteria was found GXF_ENTITY_NOT_FOUND is returned. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of the entity which is searched. /// @param tid The component type ID (TID) of the component to find (optional) /// @param name The component name of the component to find (optional). Ownership not transferred. /// @param offset The index of the first component in the entity to search. Also contains the index /// of the component which was found. /// @param cid The returned UID of the searched component /// @return GXF_SUCCESS if a component matching the criteria was found, GXF_ENTITY_NOT_FOUND if no /// component matching the criteria was found, or otherwise one of the GXF error codes. gxf_result_t GxfComponentFind(gxf_context_t context, gxf_uid_t eid, gxf_tid_t tid, const char* name, int32_t* offset, gxf_uid_t* cid); /// @brief Finds a component in an entity and returns pointer to component /// /// Searches components in an entity which satisfy certain criteria: component type, component name /// . All two criteria are optional; in case no criteria is given the first component is returned /// The main use case for "component min index" is a repeated search which continues at the index /// which was returned by a previous search. /// /// In case no entity with the given criteria was found GXF_ENTITY_NOT_FOUND is returned. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of the entity which is searched. /// @param item_ptr The pointer to entity item /// @param tid The component type ID (TID) of the component to find (optional) /// @param name The component name of the component to find (optional). Ownership not transferred. /// @param offset The index of the first component in the entity to search. Also contains the index /// of the component which was found. /// @param cid The returned UID of the searched component /// @param ptr The returned pointer of the searched component /// @return GXF_SUCCESS if a component matching the criteria was found, GXF_ENTITY_NOT_FOUND if no /// component matching the criteria was found, or otherwise one of the GXF error codes. gxf_result_t GxfComponentFindAndGetPtr(gxf_context_t context, gxf_uid_t eid, void* item_ptr, gxf_tid_t tid, const char* name, int32_t* offset, gxf_uid_t* cid, void** ptr); /// @brief Finds all components in an entity /// /// Finds and returns all component ids for the given entity. If more than `num_cids` exist /// GXF_QUERY_NOT_ENOUGH_CAPACITY will be returned and `num_cids` will be updated to the actual /// number of components in the entity. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of the entity which is searched. /// @param num_cids In/Out: the max number of components that can fit in the buffer/the number of /// components that exist in the entity /// @param cids A buffer allocated by the caller for returned UIDs of all components, with /// capacity for `num_cids`. /// @return GXF_SUCCESS if the operation was successful, GXF_QUERY_NOT_ENOUGH_CAPACITY if more /// components exist in the entity than `num_cids`, or otherwise one of the GXF error codes. gxf_result_t GxfComponentFindAll(gxf_context_t context, gxf_uid_t eid, uint64_t* num_cids, gxf_uid_t* cids); /// @brief Gets the component type ID (TID) of a component /// /// @param context A valid GXF context /// @param cid The component object ID (UID) for which the component type is requested. /// @param tid The returned TID of the component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentType(gxf_context_t context, gxf_uid_t cid, gxf_tid_t* tid); /// @brief Verifies that a component exists, has the given type, gets a pointer to it. /// /// @param context A valid GXF context /// @param tid The expected component type ID (TID) of the component /// @param pointer The returned pointer to the component object. /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentPointer(gxf_context_t context, gxf_uid_t uid, gxf_tid_t tid, void** pointer); /// @brief Check if a registered type in an extension is derived from another registered type /// from the same or any other extension. This is useful query the component hierarchies using /// their type id's. Both the derived and base types have to be registered in an extension via /// one of the registered via GXF_EXT_FACTORY_ADD* macros. /// /// @param context A valid GXF context /// @param derived The type ID (TID) of a derived type /// @param base The type ID (TID) of a base type /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfComponentIsBase(gxf_context_t context, gxf_tid_t derived, gxf_tid_t base, bool* result); // -- Parameter ---------------------------------------------------------------------------------- /// @brief Maximum number of parameters in a component #define kMaxParameters 1024 /// @brief [experimental] The name of the parameter which stores the name of a component #define kInternalNameParameterKey "__name" /// @brief Flags describing the behavior of parameter /// /// Parameter flags are specified when a parameter is registered as part of the component interface. /// Multiple flags can be OR combined. enum gxf_parameter_flags_t_ { /// No additional flags are set (the default). This means the parameter is mandatory and static. /// The parameter must be set before entity activation and can not be changed after entity /// activation. GXF_PARAMETER_FLAGS_NONE = 0, /// The parameter value is optional and might not be available after entity activation. /// This implies that it is not allowed to access the parameter with 'get()' in the C++ API. /// Instead 'try_get' must be used. GXF_PARAMETER_FLAGS_OPTIONAL = 1, /// The parameter is dynamic an might change after entity activation. However it is still /// guaranteed that parameters do not change during the initialize, deinitialize, start, tick, /// or stop functions. GXF_PARAMETER_FLAGS_DYNAMIC = 2 }; /// @brief Type used for parameter flags. /// /// @see gxf_parameter_flags_t_ typedef uint32_t gxf_parameter_flags_t; // Sets a 8-bit signed integer parameter gxf_result_t GxfParameterSetInt8(gxf_context_t context, gxf_uid_t uid, const char* key, int8_t value); // Sets a 16-bit signed integer parameter gxf_result_t GxfParameterSetInt16(gxf_context_t context, gxf_uid_t uid, const char* key, int16_t value); // Sets a 32-bit signed integer parameter gxf_result_t GxfParameterSetInt32(gxf_context_t context, gxf_uid_t uid, const char* key, int32_t value); // Sets a 64-bit signed integer parameter gxf_result_t GxfParameterSetInt64(gxf_context_t context, gxf_uid_t uid, const char* key, int64_t value); // Sets a 8-bit unsigned integer parameter gxf_result_t GxfParameterSetUInt8(gxf_context_t context, gxf_uid_t uid, const char* key, uint8_t value); // Sets a 16-bit unsigned integer parameter gxf_result_t GxfParameterSetUInt16(gxf_context_t context, gxf_uid_t uid, const char* key, uint16_t value); // Sets a 32-bit unsigned integer parameter gxf_result_t GxfParameterSetUInt32(gxf_context_t context, gxf_uid_t uid, const char* key, uint32_t value); // Sets a 64-bit unsigned integer parameter gxf_result_t GxfParameterSetUInt64(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t value); // Sets a 32-bit floating point parameter gxf_result_t GxfParameterSetFloat32(gxf_context_t context, gxf_uid_t uid, const char* key, float value); // Sets a 64-bit floating point parameter gxf_result_t GxfParameterSetFloat64(gxf_context_t context, gxf_uid_t uid, const char* key, double value); // Sets a string parameter gxf_result_t GxfParameterSetStr(gxf_context_t context, gxf_uid_t uid, const char* key, const char* value); // Sets a handle parameter gxf_result_t GxfParameterSetHandle(gxf_context_t context, gxf_uid_t uid, const char* key, gxf_uid_t cid); // Sets a boolean parameter gxf_result_t GxfParameterSetBool(gxf_context_t context, gxf_uid_t uid, const char* key, bool value); // Sets a String 1D-Vector parameter. Internally the data is stored in // a std::vector. The length of the vector should match the length of the registered parameter. gxf_result_t GxfParameterSet1DStrVector(gxf_context_t context, gxf_uid_t uid, const char* key, const char* value[], uint64_t length); // Sets a Float 64 1D-Vector parameter. Internally the data is stored in // a std::vector. The length of the vector should match the length of the registered parameter. gxf_result_t GxfParameterSet1DFloat64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, double* value, uint64_t length); // Sets a Float 64 2D-Vector parameter. Internally the data is stored in a // std::vector. The height should match the length of the outer std::vector // and the width should match the length of all the inner std::vectors. Also, these height and // width should match the shape of the registered parameters. gxf_result_t GxfParameterSet2DFloat64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, double** value, uint64_t height, uint64_t width); // Sets a signed 64-bit int 1D-Vector parameter. Internally the data is stored in // a std::vector. The length of the vector should match the length of the registered parameter. gxf_result_t GxfParameterSet1DInt64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, int64_t* value, uint64_t length); // Sets a signed 64-bit int 2D-Vector parameter. Internally the data is stored in a // std::vector. The height should match the length of the outer std::vector // and the width should match the length of all the inner std::vectors. Also, these height and // width should match the shape of the registered parameters. gxf_result_t GxfParameterSet2DInt64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, int64_t** value, uint64_t height, uint64_t width); // Sets a unsigned 64-bit unsigned int 1D-Vector parameter. Internally the data is stored in // a std::vector. The length of the vector should match the length of the registered parameter. gxf_result_t GxfParameterSet1DUInt64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* value, uint64_t length); // Sets a unsigned 64-bit unsigned int 2D-Vector parameter. Internally the data is stored in a // std::vector. The height should match the length of the outer std::vector // and the width should match the length of all the inner std::vectors. Also, these height and // width should match the shape of the registered parameters. gxf_result_t GxfParameterSet2DUInt64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t** value, uint64_t height, uint64_t width); // Sets a signed 32-bit int 1-D Vector parameter. Internally the data is stored in // a std::vector. The length of the vector should match the length of the registered parameter. gxf_result_t GxfParameterSet1DInt32Vector(gxf_context_t context, gxf_uid_t uid, const char* key, int32_t* value, uint64_t length); // Sets a signed 32-bit int 2-D Vector parameter. Internally the data is stored in a // std::vector. The height should match the length of the outer std::vector // and the width should match the length of all the inner std::vectors. Also, these height and // width should match the shape of the registered parameters. gxf_result_t GxfParameterSet2DInt32Vector(gxf_context_t context, gxf_uid_t uid, const char* key, int32_t** value, uint64_t height, uint64_t width); // Sets a parameter from YAML. The YAML node pointer should be a type of 'YAML::Node*'. gxf_result_t GxfParameterSetFromYamlNode(gxf_context_t context, gxf_uid_t uid, const char* key, void* yaml_node, const char* prefix); // Sets a FilePath parameter gxf_result_t GxfParameterSetPath(gxf_context_t context, gxf_uid_t uid, const char* key, const char* value); // Gets a parameter as a YAML node. The YAML node pointer should be a type of 'YAML::Node*'. gxf_result_t GxfParameterGetAsYamlNode(gxf_context_t context, gxf_uid_t uid, const char* key, void* yaml_node); // Gets a 64-bit floating point parameter gxf_result_t GxfParameterGetFloat64(gxf_context_t context, gxf_uid_t uid, const char* key, double* value); // Gets a 32-bit floating point parameter gxf_result_t GxfParameterGetFloat32(gxf_context_t context, gxf_uid_t uid, const char* key, float* value); // Gets a 64-bit signed integer parameter gxf_result_t GxfParameterGetInt64(gxf_context_t context, gxf_uid_t uid, const char* key, int64_t* value); // Gets a 64-bit unsigned integer parameter gxf_result_t GxfParameterGetUInt64(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* value); // Gets a 32-bit unsigned integer parameter gxf_result_t GxfParameterGetUInt32(gxf_context_t context, gxf_uid_t uid, const char* key, uint32_t* value); // Gets a 16-bit unsigned integer parameter gxf_result_t GxfParameterGetUInt16(gxf_context_t context, gxf_uid_t uid, const char* key, uint16_t* value); // Gets a string parameter gxf_result_t GxfParameterGetStr(gxf_context_t context, gxf_uid_t uid, const char* key, const char** value); // Gets a file path parameter gxf_result_t GxfParameterGetPath(gxf_context_t context, gxf_uid_t uid, const char* key, const char** value); // Gets a handle parameter gxf_result_t GxfParameterGetHandle(gxf_context_t context, gxf_uid_t uid, const char* key, gxf_uid_t* cid); // Gets a bool parameter gxf_result_t GxfParameterGetBool(gxf_context_t context, gxf_uid_t uid, const char* key, bool* value); // Gets a 32-bit signed integer parameter gxf_result_t GxfParameterGetInt32(gxf_context_t context, gxf_uid_t uid, const char* key, int32_t* value); // Gets the length of the 1D vector. // For 1D: rank = 1; shape = [length, ...] gxf_result_t GxfParameterGet1DFloat64VectorInfo(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* length); // Gets the height/width of the 2D vector. // For 2D: rank = 2; shape = [height, width, ...] gxf_result_t GxfParameterGet2DFloat64VectorInfo(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* height, uint64_t* width); // Gets the length of the 1D vector. // For 1D: rank = 1; shape = [length, ...] gxf_result_t GxfParameterGet1DInt64VectorInfo(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* length); // Gets the height/width of the 2D vector. // For 2D: rank = 2; shape = [height, width, ...] gxf_result_t GxfParameterGet2DInt64VectorInfo(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* height, uint64_t* width); // Gets the length of the 1D vector. // For 1D: rank = 1; shape = [length, ...] gxf_result_t GxfParameterGet1DUInt64VectorInfo(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* length); // Gets the height/width of the 2D vector. // For 2D: rank = 2; shape = [height, width, ...] gxf_result_t GxfParameterGet2DUInt64VectorInfo(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* height, uint64_t* width); // Gets the length of the 1D vector. // For 1D: rank = 1; shape = [length, ...] gxf_result_t GxfParameterGet1DInt32VectorInfo(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* length); // Gets the height/width of the 2D vector. // For 2D: rank = 2; shape = [height, width, ...] gxf_result_t GxfParameterGet2DInt32VectorInfo(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* height, uint64_t* width); // Gets a 1D-Vector of 64-bit floating point. // For 1D: rank = 1; shape = [length, ...] // The rank and shape should match with the internal registered std::vector parameter. // The length can be queried using GxfGetParameterInfo() gxf_result_t GxfParameterGet1DFloat64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, double* value, uint64_t* length); // Gets a 1D-Vector of strings. // The length can be queried using GxfGetParameterInfo() gxf_result_t GxfParameterGet1DStrVector(gxf_context_t context, gxf_uid_t uid, const char* key, char* value[], uint64_t* count, uint64_t* min_length); // Gets a 2D-Vector of 64-bit floating point. // For 2D: rank = 2; shape = [height, width, ...] // The rank and shape should match with the internal registered std::vector parameter. // The height and width can be obtained using GxfGetParameterInfo() gxf_result_t GxfParameterGet2DFloat64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, double** value, uint64_t* height, uint64_t* width); // Gets a 1D-Vector of signed 64-bit integers. // For 1D: rank = 1; shape = [length, ...] // The rank and shape should match with the internal registered std::vector parameter. // The length can be queried using GxfGetParameterInfo() gxf_result_t GxfParameterGet1DInt64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, int64_t* value, uint64_t* length); // Gets a 2D-Vector of signed 64-bit integers. // For 2D: rank = 2; shape = [height, width, ...] // The rank and shape should match with the internal registered std::vector parameter. // The height and width can be obtained using GxfGetParameterInfo() gxf_result_t GxfParameterGet2DInt64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, int64_t** value, uint64_t* height, uint64_t* width); // Gets a 1D-Vector of unsigned 32-bit integers. // For 1D: rank = 1; shape = [length, ...] // The rank and shape should match with the internal registered std::vector parameter. // The length can be queried using GxfGetParameterInfo() gxf_result_t GxfParameterGet1DUInt64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t* value, uint64_t* length); // Gets a 2D-Vector of unsigned 32-bit integers. // For 2D: rank = 2; shape = [height, width, ...] // The rank and shape should match with the internal registered std::vector parameter. // The height and width can be obtained using GxfGetParameterInfo() gxf_result_t GxfParameterGet2DUInt64Vector(gxf_context_t context, gxf_uid_t uid, const char* key, uint64_t** value, uint64_t* height, uint64_t* width); // Gets a 1D-Vector of signed 32-bit integers. // For 1D: rank = 1; shape = [length, ...] // The rank and shape should match with the internal registered std::vector parameter. // The length can be queried using GxfGetParameterInfo() gxf_result_t GxfParameterGet1DInt32Vector(gxf_context_t context, gxf_uid_t uid, const char* key, int32_t* value, uint64_t* length); // Gets a 2D-Vector of signed 32-bit integers. // For 2D: rank = 2; shape = [height, width, ...] // The rank and shape should match with the internal registered std::vector parameter. // The height and width can be obtained using GxfGetParameterInfo() gxf_result_t GxfParameterGet2DInt32Vector(gxf_context_t context, gxf_uid_t uid, const char* key, int32_t** value, uint64_t* height, uint64_t* width); // -- Graph execution ---------------------------------------------------------------------------- // Loads a list of entities from a YAML file. gxf_result_t GxfGraphLoadFile(gxf_context_t context, const char* filename, const char* parameters_override[] = nullptr, const uint32_t num_overrides = 0); // Loads a list of entities from a YAML file. This API is used when shared context is created using // GxfGetSharedContext() and GxfContextCreateShared(). Separate instances of entities are created // for shared context by adding entity_prefix to the entity name. gxf_result_t GxfGraphLoadFileExtended(gxf_context_t context, const char* filename, const char* entity_prefix, const char* parameters_override[] = nullptr, const uint32_t num_overrides = 0, gxf_uid_t parent_eid = kNullUid, void* prerequisites = nullptr); // Saves a list of entities to a YAML file. gxf_result_t GxfGraphSaveToFile(gxf_context_t context, const char* filename); // Set the root folder for searching YAML files during loading gxf_result_t GxfGraphSetRootPath(gxf_context_t context, const char* path); // Loads a list of entities from a YAML file. gxf_result_t GxfGraphParseString(gxf_context_t context, const char* text, const char* parameters_override[] = nullptr, const uint32_t num_overrides = 0); // Activate all System components gxf_result_t GxfGraphActivate(gxf_context_t context); // Deactivate all System components gxf_result_t GxfGraphDeactivate(gxf_context_t context); // Starts the execution of the graph asynchronously gxf_result_t GxfGraphRunAsync(gxf_context_t context); // Interrupt the execution of the graph gxf_result_t GxfGraphInterrupt(gxf_context_t context); // Waits for the graph to complete execution gxf_result_t GxfGraphWait(gxf_context_t context); // Runs all System components and waits for their completion gxf_result_t GxfGraphRun(gxf_context_t context); // -- Info queries ------------------------------------------------------------------------------- // Type to represent version of GXF Runtime and list of loaded Extensions typedef struct { const char* version; // GXF Runtime Version uint64_t num_extensions; // in-out capacity of extensions/Number of extension types gxf_tid_t* extensions; // List of Extension IDs } gxf_runtime_info; // Gets Meta Data about the GXF Runtime gxf_result_t GxfRuntimeInfo(gxf_context_t context, gxf_runtime_info* info); // Type to represent description and list of components for loaded Extension typedef struct { gxf_tid_t id; // (UUID) Extension ID (registered via GXF_EXT_FACTORY_SET_INFO) const char* name; // (String) Extension Name (registered via GXF_EXT_FACTORY_SET_INFO) const char* description; // (String) Description (registered via GXF_EXT_FACTORY_SET_INFO) const char* version; // (String) Extension Version (registered via GXF_EXT_FACTORY_SET_INFO) const char* runtime_version; // (String) GXF Core version with which the extension was compiled with const char* license; // (String) Extension License (registered via GXF_EXT_FACTORY_SET_INFO) const char* author; // (String) Extension Author (registered via GXF_EXT_FACTORY_SET_INFO) const char* display_name; // (String) Extension Display Name (registered via // GXF_EXT_FACTORY_SET_DISPLAY_INFO, maximum 30 characters) const char* category; // (String) Extension Category (registered via // GXF_EXT_FACTORY_SET_DISPLAY_INFO, maximum 30 characters) const char* brief; // (String) Extension Brief (registered via // GXF_EXT_FACTORY_SET_DISPLAY_INFO, maximum 50 characters) uint64_t num_components; // in-out capacity of components/Number of components gxf_tid_t* components; // List of IDs of provided components } gxf_extension_info_t; // Gets description and list of components in loaded Extension gxf_result_t GxfExtensionInfo(gxf_context_t context, gxf_tid_t tid, gxf_extension_info_t* info); // Type to represent description and list of Parameter of Component typedef struct { gxf_tid_t cid; // (UUID) Component ID (registered via GXF_EXT_FACTORY_ADD) const char* base_name; // (String) Base Class Name (registered via GXF_EXT_FACTORY_ADD) int is_abstract; // (Bool) If the Component is abstract (Can not be instantiated) const char* type_name; // (String) Component Name (registered via GXF_EXT_FACTORY_ADD) const char* display_name; // (String) Extension Display Name (registered via // GXF_EXT_FACTORY_SET_DISPLAY_INFO, maximum 30 characters) const char* brief; // (String) Extension Brief (registered via // GXF_EXT_FACTORY_SET_DISPLAY_INFO, maximum 50 characters) const char* description; // (String) Description (registered via GXF_EXT_FACTORY_ADD) uint64_t num_parameters; // in-out capacity of parameters/Number of Parameters const char** parameters; // List of Names for Parameters } gxf_component_info_t; // Gets description and list of parameters of Component. Parameters are only available after // at least one instance is created for the Component. gxf_result_t GxfComponentInfo(gxf_context_t context, gxf_tid_t tid, gxf_component_info_t* info); /// @brief The type of a parameter typedef enum { GXF_PARAMETER_TYPE_CUSTOM = 0, // A custom type not natively supported by GXF. GXF_PARAMETER_TYPE_HANDLE = 1, // A GXF handle. The handle type is specified separately. GXF_PARAMETER_TYPE_STRING = 2, // A null-terminated character string (const char*) GXF_PARAMETER_TYPE_INT64 = 3, // A 64-bit signed integer (int64_t) GXF_PARAMETER_TYPE_UINT64 = 4, // A 64-bit unsigned integer (uint64_t) GXF_PARAMETER_TYPE_FLOAT64 = 5, // A 64-bit floating point (double) GXF_PARAMETER_TYPE_BOOL = 6, // A boolean type (bool) GXF_PARAMETER_TYPE_INT32 = 7, // A 32-bit signed integer (int32_t) GXF_PARAMETER_TYPE_FILE = 8, // a file system path (string) GXF_PARAMETER_TYPE_INT8 = 9, // A 8-bit signed integer (int8_t) GXF_PARAMETER_TYPE_INT16 = 10, // A 16-bit signed integer (int16_t) GXF_PARAMETER_TYPE_UINT8 = 11, // A 8-bit unsigned integer (uint8_t) GXF_PARAMETER_TYPE_UINT16 = 12, // A 16-bit unsigned integer (uint16_t) GXF_PARAMETER_TYPE_UINT32 = 13, // A 32-bit unsigned integer (uint32_t) GXF_PARAMETER_TYPE_FLOAT32 = 14, // A 32-bit floating point (float) GXF_PARAMETER_TYPE_COMPLEX64 = 15, // A 64-bit complex floating point (float) GXF_PARAMETER_TYPE_COMPLEX128 = 16, // A 128-bit complex floating point (double) } gxf_parameter_type_t; // Holds metadata information about a parameter which was registered as part of the component // interface. typedef struct { const char* key; // The name of the parameter as it appears in the GXF file. const char* headline; // A short headline used to display the parameter to a human. const char* description; // A longer text describing the usage of the parameter. gxf_parameter_flags_t flags; // Parameter flags for example to make a parameter optional. gxf_parameter_type_t type; // The type of the parameter gxf_tid_t handle_tid; // In case the parameter is a handle the TID of the component. const void* default_value; // Default value of parameter, N/A for handle and custom params const void* numeric_min; // Min value of range for numeric parameters, N/A for other types const void* numeric_max; // Max value of range for numeric parameters, N/A for other types const void* numeric_step; // Step value of range for numeric parameters, N/A for other types const char* platform_information; // (String) Platforms separated by comma. Empty means all platforms int32_t rank; // Rank of the parameter. 0-scalar, 1-list etc. Max rank is 8 int32_t shape[8]; // Sizes of multi dimensional parameters if it is of fixed // length(array). Shape of a dimension is -1 for scalar and // variable length arrays(vector) } gxf_parameter_info_t; // Gives a string describing the parameter type const char* GxfParameterTypeStr(gxf_parameter_type_t param_type); // Gives a string describing the flag type const char* GxfParameterFlagTypeStr(gxf_parameter_flags_t_ flag_type); // Gets description of specific parameter. Fail if the component is not instantiated yet. gxf_result_t GxfParameterInfo(gxf_context_t context, gxf_tid_t cid, const char* key, gxf_parameter_info_t* info); gxf_result_t GxfGetParameterInfo(gxf_context_t context, gxf_tid_t cid, const char* key, gxf_parameter_info_t* info); gxf_result_t GxfRedirectLog(gxf_context_t context, FILE* fp); // ------------------------------------------------------------------------------------------------- #ifdef __cplusplus } // extern "C" #endif #ifdef __cplusplus inline bool operator==(const gxf_tid_t& lhs, const gxf_tid_t& rhs) noexcept { return lhs.hash1 == rhs.hash1 && lhs.hash2 == rhs.hash2; } inline bool operator!=(const gxf_tid_t& lhs, const gxf_tid_t& rhs) noexcept { return lhs.hash1 != rhs.hash1 || lhs.hash2 != rhs.hash2; } inline bool operator<(const gxf_tid_t& lhs, const gxf_tid_t& rhs) noexcept { return lhs.hash1 < rhs.hash1 || (lhs.hash1 == rhs.hash1 && lhs.hash2 < rhs.hash2); } #endif #endif // NVIDIA_GXF_CORE_GXF_H_ // Include the extended API functions. #include "gxf_ext.h" ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/gxf_ext.h ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_GXF_EXT_H_ #define NVIDIA_GXF_CORE_GXF_EXT_H_ #ifdef __cplusplus #include #else #include #endif #ifdef __cplusplus extern "C" { #endif // ------------------------------------------------------------------------------------------------- /// @brief GXF bitmasks typedef uint32_t GxfFlags; // ------------------------------------------------------------------------------------------------- /// @brief Structure specifying parameters for loading extensions typedef struct { // Optional list of extension filenames to load const char* const* extension_filenames; // The number of extensions to load uint32_t extension_filenames_count; // Optional list of manifest filenames to load const char* const* manifest_filenames; // The number of manifests to load uint32_t manifest_filenames_count; // An optional base directory which is prepended to all extensions filenames, including those // loaded via manifests. const char* base_directory; } GxfLoadExtensionsInfo; /// @brief Loads GXF extension libraries /// /// Loads one or more extensions either directly by their filename or indirectly by loading /// manifest files. Before a component can be added to a GXF entity the GXF extension shared /// library providing the component must be loaded. An extensions must only be loaded once. /// /// To simplify loading multiple extensions at once the developer can create a manifest file which /// lists all extensions he needs. This function will then load all extensions listed in the /// manifest file. Multiple manifest may be loaded, however each extensions may still be loaded /// only a single time. /// /// A manifest file is a YAML file with a single top-level entry 'extensions' followed by a /// list of filenames of GXF extension shared libraries. /// /// Example: /// ----- START OF FILE ----- /// extensions: /// - gxf/std/libgxf_std.so /// - gxf/npp/libgxf_npp.so /// ----- END OF FILE ----- /// /// @param context is the GXF context in which to load extensions /// @param info is a pointer to a GxfLoadExtensionsInfo structure describing parameters for loading /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfLoadExtensions(gxf_context_t context, const GxfLoadExtensionsInfo* info); /// @brief Loads a metadata file generated by the GXF registry /// /// The GXF registry tool generates a metadata file of the contents of an extension during /// registration. These metadata files can be used to resolve typename and TID's of components for /// other extensions which depend on them. metadata files do not contain the actual implementation /// of the extension and must be loaded only to run the extension query API's on extension /// libraries which have the actual implementation and only depend on the metadata for type /// resolution. /// /// If some components of extension B depend on some components in extension A: /// - Load metadata file for extension A /// - Load extension library for extension B using 'GxfLoadExtensions' /// - Run extension query api's on extension B and it's components. /// /// @param context A valid GXF context /// @param filenames absolute paths of metadata files generated by the registry during /// extension registration /// @param count The number of metadata files to be loaded /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfLoadExtensionMetadataFiles(gxf_context_t context, const char* const* filenames, uint32_t count); // ------------------------------------------------------------------------------------------------- /// @brief Bitmask specifying storage mode for an entity typedef enum GxfEntityCreateFlagBits { // 'GXF_ENTITY_CREATE_PROGRAM_BIT' specifies that the entity will be added to the program // entities. Program entities are kept alive for the duration of the program. They are activated // automatically when the program is activated and deactivated when the program is deactivated. // If the program was already activated when the entity is created the entity must still be // activated manually. GXF_ENTITY_CREATE_PROGRAM_BIT = 0x00000001 } GxfEntityCreateFlagBits; /// @brief Bitmask of GxfEntityCreateFlagBits typedef GxfFlags GxfEntityCreateFlags; /// @brief Structure specifying parameters for creating entities typedef struct { // 'entity_name' is the name of the entity which is created. If this is a nullptr an undefined // unique name is chosen. The name must not start with a double underscore. const char* entity_name; // 'flags' is a bitmask of GxfEntityCreateFlagsBits indicating storage method and usage behavior // for the created entity. GxfEntityCreateFlags flags; } GxfEntityCreateInfo; /// @brief Create a new GXF entity /// /// Entities are light-weight containers to hold components and form the basic building blocks /// of a GXF application. Entities are created when a GXF file is loaded, or they can be created /// manually using this function. Entities created with this function must be destroyed using /// 'GxfEntityDestroy'. After the entity was created components can be added to it with /// 'GxfComponentAdd'. To start execution of codelets on an entity the entity needs to be /// activated first. This can happen automatically using 'GXF_ENTITY_CREATE_PROGRAM_BIT' or /// manually using 'GxfEntityActivate'. /// /// @param context is the GXF context that creates the entity. /// @param info is a pointer to a GxfEntityCreateInfo structure containing parameters affecting /// the creation of the entity. /// @param eid is a pointer to a gxf_uid_t handle in which the resulting entity is returned. /// @return On success the function returns GXF_SUCCESS. gxf_result_t GxfCreateEntity(gxf_context_t context, const GxfEntityCreateInfo* info, gxf_uid_t* eid); /// @brief Create a new GXF entity and return the entity item ptr /// /// Entities are light-weight containers to hold components and form the basic building blocks /// of a GXF application. Entities are created when a GXF file is loaded, or they can be created /// manually using this function. Entities created with this function must be destroyed using /// 'GxfEntityDestroy'. After the entity was created components can be added to it with /// 'GxfComponentAdd'. To start execution of codelets on an entity the entity needs to be /// activated first. This can happen automatically using 'GXF_ENTITY_CREATE_PROGRAM_BIT' or /// manually using 'GxfEntityActivate'. This function also returns the pointer entity item /// which can be used to create C++ nvidia::gxf::Entity type objects. /// /// @param context is the GXF context that creates the entity. /// @param info is a pointer to a GxfEntityCreateInfo structure containing parameters affecting /// the creation of the entity. /// @param eid is a pointer to a gxf_uid_t handle in which the resulting entity is returned. /// @param item_ptr is a pointer to pointer to entity item which is created /// @return On success the function returns GXF_SUCCESS. gxf_result_t GxfCreateEntityAndGetItem(gxf_context_t context, const GxfEntityCreateInfo* info, gxf_uid_t* eid, void** item_ptr); // ------------------------------------------------------------------------------------------------- /// @brief Name of default EntityGroup #define kDefaultEntityGroupName "default_entity_group" /// @brief Create a new GXF EntityGroup /// /// EntityGroup is a group of EntityItems, such that these entities are bonded to some /// common properties. For now the common property is all kinds of resources. /// /// @param context A valid GXF context /// @param name name to create the EntityGroup /// @param gid returned uid for the created EntityGroup, abbreviation for group id. /// @return GXF error code gxf_result_t GxfCreateEntityGroup(gxf_context_t context, const char* name, gxf_uid_t* gid); /// @brief Add an entity eid into an EntityGroup by EntityGroup uid /// /// Each EntityItem is created with default EntityGroup uid, this API /// 1. updates EntityGroup uid in current EntityItem, to new group id gid; /// 2. Remove eid from its previous EntityGroup; /// 3. add eid to its new EntityGroup /// /// @param context A valid GXF context /// @param gid UID of an existing (new) EntityGroup /// @param eid The unique object ID (UID) of a valid entity /// @return GXF error code gxf_result_t GxfUpdateEntityGroup(gxf_context_t context, gxf_uid_t gid, gxf_uid_t eid); /// @brief Check if an entity id is valid currently in GXF runtime /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity to check /// @param valid returned boolean indicating if the entity is valid in Gxf runtime(warden) /// @return GXF error code gxf_result_t GxfEntityIsValid(gxf_context_t context, gxf_uid_t eid, bool* valid); /// @brief Finds and returns all resource component cids for EntityGroup pointed by eid /// /// Finds and returns all resource component cids for EntityGroup pointed by eid. /// If more than `max_entities` exist only `max_entities` will be returned. /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @param num_resource_cids In/Out: the max number of components that can fit in /// the buffer/the number of resources in eid's EntityGroup /// @param resource_cids A buffer allocated by the caller for returned UIDs of all resources, with /// capacity for `num_resource_cids`. /// @return GXF_SUCCESS if the operation was successful, GXF_QUERY_NOT_ENOUGH_CAPACITY if more /// resources exist in eid's EntityGroup, or otherwise one of the GXF error codes. gxf_result_t GxfEntityGroupFindResources(gxf_context_t context, gxf_uid_t eid, uint64_t* num_resource_cids, gxf_uid_t* resource_cids); /// @brief Find the EntityGroup gid that the entity belongs to /// /// EntityGroup is a group of EntityItems, such that these entities are bonded to some /// common properties. For now the common property is all kinds of resources. Through /// life time of each entity, it always corresponds to an EntityGroup. Eg, newly created /// EntityItem points to Default EntityGroup, and user can update its EntityGroup to valid /// one only. /// /// @param context A valid GXF context /// @param eid eid of an EntityItem, whose EntityGroup id field is used find EntityGroup name /// @param gid The returned id of the entity group. /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityGroupId(gxf_context_t context, gxf_uid_t eid, gxf_uid_t* gid); /// @brief Find name of EntityGroup that holds the entity /// /// EntityGroup is a group of EntityItems, such that these entities are bonded to some /// common properties. For now the common property is all kinds of resources. Through /// life time of each entity, it always corresponds to an EntityGroup. Eg, newly created /// EntityItem points to Default EntityGroup, and user can update its EntityGroup to valid /// one only. /// /// @param context A valid GXF context /// @param eid eid of an EntityItem, whose EntityGroup id field is used find EntityGroup name /// @param name The returned name of the EntityGroup /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityGroupName(gxf_context_t context, gxf_uid_t eid, const char** name); /// @brief Gets cid of a resource component that is grouped with the given entity /// /// @param context A valid GXF context /// @param eid The unique object ID (UID) of a valid entity /// @param type The fully qualified C++ type name of the component /// @param resource_key the key or name of the resource /// @param resource_cid The returned cid of the resource component /// @return GXF_SUCCESS if the operation was successful, or otherwise one of the GXF error codes. gxf_result_t GxfEntityResourceGetHandle(gxf_context_t context, gxf_uid_t eid, const char* type, const char* resource_key, gxf_uid_t* resource_cid); // ------------------------------------------------------------------------------------------------- /// @brief Severity levels for GXF_LOG_* logging macros typedef enum { GXF_SEVERITY_NONE = 0, GXF_SEVERITY_ERROR = 1, GXF_SEVERITY_WARNING = 2, GXF_SEVERITY_INFO = 3, GXF_SEVERITY_DEBUG = 4, GXF_SEVERITY_VERBOSE = 5, } gxf_severity_t; /// @brief Sets the severity level of the logs (corresponding to GXF_LOG_* logging macros) for the /// entire application /// /// @param context a valid GXF context /// @param severity a valid severity level as defined in `gxf_severity_t`. Logs corresponding to /// any level <= severity will be logged. /// @return On success the function returns GXF_SUCCESS. /// gxf_result_t GxfSetSeverity(gxf_context_t context, gxf_severity_t severity); /// @brief Returns the current severity level of the logs. /// /// @param context a valid GXF context /// @param severity a pointer to a gxf_severity_t in which the resulting severity is returned. /// @return On success the function returns GXF_SUCCESS. /// gxf_result_t GxfGetSeverity(gxf_context_t context, gxf_severity_t* severity); // ------------------------------------------------------------------------------------------------- /// @brief Simple macro to convert enum values to their string representations which can be /// useful for logging enum types #define GXF_ENUM_TO_STR(X, Y) \ case X: \ return #Y; #ifdef __cplusplus } // extern "C" #endif #endif // NVIDIA_GXF_CORE_GXF_EXT_H_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/handle.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_HANDLE_HPP #define NVIDIA_GXF_CORE_HANDLE_HPP #include #include #include "common/assert.hpp" #include "common/type_name.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { // A handle which gives access to a component without specifying its type. class UntypedHandle { public: UntypedHandle(const UntypedHandle& component) = default; UntypedHandle(UntypedHandle&& component) = default; UntypedHandle& operator=(const UntypedHandle& component) = default; UntypedHandle& operator=(UntypedHandle&& component) = default; // Creates a null untyped handle static UntypedHandle Null() { return UntypedHandle{kNullContext, kNullUid}; } // Creates a new untyped handle static Expected Create(gxf_context_t context, gxf_uid_t cid) { UntypedHandle untyped_handle{context, cid}; gxf_tid_t tid; gxf_result_t code = GxfComponentType(context, cid, &tid); if (code != GXF_SUCCESS) { return Unexpected{code}; } const auto result = untyped_handle.initialize(tid); if (!result) { return ForwardError(result); } return untyped_handle; } // Creates a new untyped handle with component pointer static Expected Create(gxf_context_t context, gxf_uid_t cid, gxf_tid_t tid, void* ptr) { return UntypedHandle{context, cid, tid, ptr}; } // The context to which the component belongs gxf_context_t context() const { return context_; } // The ID of the component. gxf_uid_t cid() const { return cid_; } // The type ID describing the component type. gxf_tid_t tid() const { return tid_; } // Get the pointer to underlying component object void* get_ptr() const {return pointer_;} // Returns null if the handle is equivalent to a nullptr. bool is_null() const { return context_ == kNullContext || cid_ == kNullUid || pointer_ == nullptr; } // Same as 'is_null'. explicit operator bool() const { return !is_null(); } // The component name const char* name() const { const char* result; const gxf_result_t code = GxfComponentName(context(), cid(), &result); return (code == GXF_SUCCESS) ? result : ""; } protected: UntypedHandle(gxf_context_t context, gxf_uid_t cid) : context_{context}, cid_{cid}, tid_{GxfTidNull()}, pointer_{nullptr} { } UntypedHandle(gxf_context_t context, gxf_uid_t cid, gxf_tid_t tid, void* pointer) : context_{context}, cid_{cid}, tid_{tid}, pointer_{pointer} {} Expected initialize(gxf_tid_t tid) { tid_ = tid; if (pointer_ == nullptr) { return ExpectedOrCode(GxfComponentPointer(context_, cid_, tid_, &pointer_)); } return Success; } Expected initialize(const char* type_name) { gxf_tid_t tid; gxf_result_t code = GxfComponentTypeId(context_, type_name, &tid); if (code != GXF_SUCCESS) { return Unexpected{code}; } return initialize(tid); } Expected verifyPointer() const { if (pointer_ == nullptr) { GXF_LOG_ERROR("Handle pointer is null for component %s - id %ld", name(), cid()); return Unexpected{GXF_FAILURE}; } void* raw_pointer; auto result = GxfComponentPointer(context(), cid(), tid_, &raw_pointer); if (result != GXF_SUCCESS) { return Unexpected{result}; } if (raw_pointer != pointer_) { GXF_LOG_ERROR("Handle pointers do not match for component %s: %p vs %p", name(), raw_pointer, pointer_); return Unexpected{GXF_FAILURE}; } return Success; } gxf_context_t context_; gxf_uid_t cid_; gxf_tid_t tid_; void* pointer_; }; // A handle which gives access to a component with a specific type. template class Handle : public UntypedHandle { public: // Creates a null handle static Handle Null() { return Handle{}; } // An unspecified handle is a unique handle used to denote a component which // will be created in the future. A parameter of Handle to a type does not consider // "Unspecified" as a valid parameter value and hence this handle must only be used // when defining a graph application across different files and the parameters are set // in a delayed fashion (sub-graphs and parameter yaml files for example) // Entity activation will fail if any of the mandatory parameters are "Unspecified" static Handle Unspecified() { return Handle(kNullContext, kUnspecifiedUid); } // Creates a new handle static Expected Create(gxf_context_t context, gxf_uid_t cid) { Handle handle{context, cid}; const auto result = handle.initialize(TypenameAsString()); if (!result) { return ForwardError(result); } return handle; } static Expected Create(gxf_context_t context, gxf_uid_t cid, gxf_tid_t tid, void * ptr) { if (GxfTidIsNull(tid) || ptr == nullptr) { return Create(context, cid); } Handle handle{context, cid, tid, ptr}; return handle; } // Creates a new handle from an untyped handle static Expected Create(const UntypedHandle& untyped_handle) { return Create(untyped_handle.context(), untyped_handle.cid(), untyped_handle.tid(), untyped_handle.get_ptr()); } friend bool operator==(const Handle& lhs, const Handle& rhs) { return lhs.context() == rhs.context() && lhs.cid() == rhs.cid(); } friend bool operator!=(const Handle& lhs, const Handle& rhs) { return lhs.context() != rhs.context() || lhs.cid() != rhs.cid(); } friend bool operator<(const Handle& lhs, const Handle& rhs) { return lhs.cid() < rhs.cid(); } Handle(gxf_context_t context = kNullContext, gxf_uid_t uid = kNullUid) : UntypedHandle{context, uid} {} Handle(gxf_context_t context , gxf_uid_t uid , gxf_tid_t tid, void* ptr) : UntypedHandle{context, uid, tid, ptr} {} ~Handle() = default; Handle(const Handle& component) = default; Handle(Handle&& component) = default; Handle& operator=(const Handle& component) = default; Handle& operator=(Handle&& component) = default; template Handle(const Handle& derived) : UntypedHandle(derived) { static_assert(std::is_base_of::value, "Handle conversion is only allowed from derived class to base class"); } // Allow conversion from handle to pointer operator T*() const { return get(); } T* operator->() const { return get(); } T* get() const { // Verifying the pointer every time the handle is accessed causes a // significant bottle neck in perf. This should be removed in a future // release. Uncomment below line if there is any problem. // GXF_ASSERT(verifyPointer(), "Invalid Component Pointer."); GXF_ASSERT_FALSE(pointer_ == nullptr); return reinterpret_cast(pointer_); } Expected try_get() const { // Verifying the pointer every time the handle is accessed causes a // significant bottle neck in perf. This should be removed in a future // release. Uncomment below line if there is any problem. // if (!verifyPointer()) { return Unexpected{GXF_FAILURE}; } if (pointer_ == nullptr) { return Unexpected{GXF_FAILURE}; } return reinterpret_cast(pointer_); } private: using UntypedHandle::UntypedHandle; }; // Creates a new handle given the string representation of the handle in a yaml blob // If the value is of format / then cid is ignored. // If the entity name is not specified, the value indicates just the component name, then // 'cid' is used to query the entity name to create the handle template static Expected> CreateHandleFromString(gxf_context_t context, gxf_uid_t cid, const char* value) { gxf_uid_t eid; std::string component_name; const std::string tag{value}; const size_t pos = tag.find('/'); if (pos == std::string::npos) { // Get the entity of this component auto result = GxfComponentEntity(context, cid, &eid); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Failed to find entity for component [C%05" PRId64 "] with name [%s] with" " error %s", cid, value, GxfResultStr(result)); return Unexpected{result}; } component_name = tag; } else { // Split the tag into entity and component name const std::string entity_name = tag.substr(0, pos); component_name = tag.substr(pos + 1); // Search for the entity auto result = GxfEntityFind(context, entity_name.c_str(), &eid); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Failed to find entity [E%05" PRId64 "] with name [%s] while parsing '%s'", eid, entity_name.c_str(), tag.c_str()); return Unexpected{result}; } } // Get the type id of the component we are are looking for. gxf_tid_t tid; auto result = GxfComponentTypeId(context, TypenameAsString(), &tid); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Failed to find type ID of component type [%s] with error %s", TypenameAsString(), GxfResultStr(result)); return Unexpected{result}; } gxf_uid_t cid2; // Find the component in the indicated entity result = GxfComponentFind(context, eid, tid, component_name.c_str(), nullptr, &cid2); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Failed to find component in entity [E%05" PRId64 "] with name [%s]", eid, component_name.c_str()); return Unexpected{result}; } return Handle::Create(context, cid2); } } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/parameter.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_PARAMETER_HPP_ #define NVIDIA_GXF_CORE_PARAMETER_HPP_ #include #include #include #include #include "common/assert.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" #include "gxf/core/handle.hpp" #include "gxf/core/parameter_parser.hpp" #include "gxf/core/parameter_wrapper.hpp" namespace nvidia { namespace gxf { // Base class for parameters stored in ParameterStorage class ParameterBackendBase { public: virtual ~ParameterBackendBase() = default; // The context to which this parameter backend belongs gxf_context_t context() const { return context_; } // The object to which this parameter is attached. gxf_uid_t uid() const { return uid_; } // The name of the parameter const char* key() const { return key_; } // Returns true if the parameter is guaranteed to always have a value set. Only mandatory // parameters can be accessed directly with 'get' instead of using 'try_get'. bool isMandatory() const { return (flags_ & GXF_PARAMETER_FLAGS_OPTIONAL) == 0; } // Returns true if the parameter can not be changed after the component has been activated. bool isConstant() const { return (flags_ & GXF_PARAMETER_FLAGS_DYNAMIC) == 0; } // Sets the latest value from the backend to the frontend. virtual void writeToFrontend() = 0; // Parses the parameter from the given YAML object. virtual Expected parse(const YAML::Node& node, const std::string& prefix) = 0; // Wrap the parameter as a YAML node. virtual Expected wrap() = 0; // Returns true if the parameter is set virtual bool isAvailable() const = 0; // Returns true if it is possible to change this parameter bool isImmutable() const { if (isConstant()) { const bool is_active = false; // FIXME(v1) Check that component is not active. if (is_active) { return true; } } return false; } // FIXME(v1) make private gxf_context_t context_{nullptr}; gxf_uid_t uid_{kNullUid}; gxf_parameter_flags_t flags_{0}; bool is_dynamic_{false}; const char* key_{nullptr}; const char* headline_{nullptr}; const char* description_{nullptr}; }; template class Parameter; // This class stores a parameter of a specific type in the backend. template class ParameterBackend : public ParameterBackendBase { public: void writeToFrontend() override; Expected parse(const YAML::Node& node, const std::string& prefix) override; bool isAvailable() const override { return value_.has_value(); } // Sets the parameter to the given value. Expected set(T value) { // Make sure that the new value passes the validator if (validator_&& !validator_(value)) { return Unexpected{GXF_PARAMETER_OUT_OF_RANGE}; } // Don't allow modification of a parameter which is currently immutable if (isImmutable()) { return Unexpected{GXF_PARAMETER_CAN_NOT_MODIFY_CONSTANT}; } // Update the parameter value value_ = std::move(value); return Success; } Expected wrap() { if (!value_) { return Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; } return ParameterWrapper::Wrap(context(), value_.value()); } // Gets the current value of the parameter. const Expected& try_get() const { return value_; } // FIXME(v1) make private nvidia::gxf::Parameter* frontend_ = nullptr; std::function validator_; Expected value_ = Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; }; // An intermediate base class for parameters which store a handle. class HandleParameterBackend : public ParameterBackendBase { public: virtual ~HandleParameterBackend() = default; // Gets the component ID of the handle. virtual Expected get() const = 0; // Sets the handle using just a component ID virtual Expected set(gxf_uid_t cid) = 0; }; // A specialization of ParameterBackend for handle types. It derives from the intermediate base // class HandleParameterBackend so that parameter backends of handle types all have a common base // class. template class ParameterBackend> : public HandleParameterBackend { public: void writeToFrontend() override; Expected parse(const YAML::Node& node, const std::string& prefix) override; bool isAvailable() const override { return (value_.has_value()) && (value_ != Handle::Unspecified()); } Expected wrap() { if (!value_ || value_ == Handle::Unspecified()) { return Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; } return ParameterWrapper>::Wrap(context(), value_.value()); } // Sets the handle using just a component ID Expected set(gxf_uid_t cid) override { auto expected = Handle::Create(context(), cid); if (expected) { value_ = expected.value(); return Success; } else { return ForwardError(expected); } } // Gets the component ID of the handle. Expected get() const override { if (!value_) { GXF_LOG_VERBOSE("Handle parameter with name '%s' is not initialized", key()); return Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; } else if (value_ == Handle::Unspecified()) { GXF_LOG_VERBOSE("Handle parameter with name '%s' is unspecified", key()); return Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; } return value_->cid(); } // Sets the parameter to the given value. Expected set(Handle value) { if (isImmutable()) { return Unexpected{GXF_PARAMETER_CAN_NOT_MODIFY_CONSTANT}; } value_ = std::move(value); return Success; } // Gets the current value of the parameter, return Unexpected if not // set or if it's set to Handle::Unspecified() const Expected>& try_get() const { if (value_ == Handle::Unspecified()) { return unspecified_handle_; } return value_; } // FIXME(v1) make private const Expected> unspecified_handle_ = Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; nvidia::gxf::Parameter>* frontend_ = nullptr; Expected> value_ = Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; }; // Common base class for specializations of Parameter. class ParameterBase { public: virtual ~ParameterBase() = default; }; // This type represents a parameter of a component and can be used in custom components. It // communicates with the backend to set and get parameters as configured. template class Parameter : public ParameterBase { public: Parameter() = default; // enable copying Parameter(const Parameter& other) : mutex_() { std::unique_lock lock(other.mutex_); value_ = other.value_; backend_ = other.backend_; } // Gets the current parameter value. Only valid if the parameter is marked as 'mandatory' in the // parameter interface. Otherwise an assert will be raised. const T& get() const { std::unique_lock lock(mutex_); GXF_ASSERT(backend_ != nullptr, "A parameter with type '%s' was not registered.", TypenameAsString()); GXF_ASSERT(backend_->isMandatory(), "Only mandatory parameters can be accessed with get(). " "'%s' is not marked as mandatory", backend_->key()); GXF_ASSERT(value_, "Mandatory parameter '%s' was not set.", backend_->key()); return value_.value(); } // Convenience function for accessing a mandatory parameter. operator const T&() const { return get(); } // Tries to get the parameter value. If the parameter is not set Unexpected is returned. const Expected& try_get() const { std::unique_lock lock(mutex_); return value_; } // Sets the parameter to the given value. Expected set(T value) { GXF_ASSERT(backend_ != nullptr, "Parameter of type '%s' was not registered.", TypenameAsString()); const auto result = backend_->set(value); if (!result) { return result; } value_ = std::move(value); return Success; } // Sets the parameter to the given value, but does not notify the backend about the change. // This function shall only be used by the ParameterBackend class. void setWithoutPropagate(const T& value) { std::unique_lock lock(mutex_); value_ = value; } // Connects this parameter frontend to the corresponding backend. void connect(ParameterBackend* backend) { backend_ = backend; } const char* key() { return backend_ == nullptr ? nullptr : backend_->key(); } private: Expected value_ = Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; ParameterBackend* backend_ = nullptr; mutable std::mutex mutex_; }; // A specialization of Parameter for handle types. template class Parameter> : public ParameterBase { public: // Gets the current parameter value. Only valid if the parameter is marked as 'mandatory' in the // parameter interface. Otherwise an assert will be raised. const Handle& get() const { GXF_ASSERT(backend_ != nullptr, "A handle parameter with type '%s' was not registered.", TypenameAsString()); GXF_ASSERT(backend_->isMandatory(), "Only mandatory parameters can be accessed with get(). " "'%s' is not marked as mandatory", backend_->key()); GXF_ASSERT(value_, "Mandatory parameter '%s' was not set.", backend_->key()); GXF_ASSERT(value_ != Handle::Unspecified(), "Handle was created but not assigned." "Unspecified handles cannot be accessed."); return value_.value(); } // Convenience function for accessing a mandatory parameter. operator const Handle&() const { return get(); } // Tries to get the parameter value. If the parameter is not set or set to // Handle::Unspecified() is returned. const Expected>& try_get() const { if (value_ == Handle::Unspecified()) { return unspecified_handle_; } return value_; } // Only if T = Handle S* operator->() const { return get().get(); } // Sets the parameter to the given value. Expected set(Handle value) { GXF_ASSERT(backend_ != nullptr, "Parameter corresponding to Handle of `%s' was not registered.", TypenameAsString()); const auto result = backend_->set(value); if (!result) { return result; } value_ = std::move(value); return Success; } // Sets the parameter to the given value, but does not notify the backend about the change. // This function shall only be used by the ParameterBackend class. void setWithoutPropagate(const Handle& value) { value_ = value; } // Connects this parameter frontend to the corresponding backend. void connect(ParameterBackend>* backend) { backend_ = backend; } const char* key() { return backend_ == nullptr ? nullptr : backend_->key(); } private: // Used to return an Unexpected when the handle is not specified const Expected> unspecified_handle_ = Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; Expected> value_ = Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; ParameterBackend>* backend_ = nullptr; }; // ------------------------------------------------------------------------------------------------- template void ParameterBackend::writeToFrontend() { if (frontend_ && value_) { frontend_->setWithoutPropagate(*value_); } } template Expected ParameterBackend::parse(const YAML::Node& node, const std::string& prefix) { return ParameterParser::Parse(context(), uid(), key(), node, prefix) .map([this] (const T& value) { return set(value); }) .and_then([this] { writeToFrontend(); }); } template void ParameterBackend>::writeToFrontend() { if (frontend_ && value_) { frontend_->setWithoutPropagate(*value_); } } template Expected ParameterBackend>::parse(const YAML::Node& node, const std::string& prefix) { return ParameterParser>::Parse(context(), uid(), key(), node, prefix) .map([this] (const Handle& value) { return set(value); }) .and_then([this] { writeToFrontend(); }); } } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CORE_PARAMETER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/parameter_parser.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_PARAMETER_PARSER_HPP_ #define NVIDIA_GXF_STD_PARAMETER_PARSER_HPP_ #include #include #include #include #include "common/assert.hpp" #include "common/fixed_string.hpp" #include "common/fixed_vector.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/filepath.hpp" #include "gxf/core/gxf.h" #include "gxf/core/handle.hpp" #include "yaml-cpp/yaml.h" namespace nvidia { namespace gxf { template struct ParameterParser; // Parses a parameter from YAML using the default YAML parser. This class can be specialized to // support custom types. template struct ParameterParser { static Expected Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!strcmp(key, "int8") || !strcmp(key, "vector_int8") || !strcmp(key, "vector_2d_int8")) { GXF_LOG_WARNING("type %s is not supported", key); return Unexpected{GXF_PARAMETER_INVALID_TYPE}; } else { try { return node.as(); } catch (...) { std::stringstream ss; ss << node; GXF_LOG_ERROR("Could not parse parameter '%s' from '%s'", key, ss.str().c_str()); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } } } }; // Specialization of ParameterParser for std::string. The full node is serialized to a string, even // though it might contain sub children. template <> struct ParameterParser { static Expected Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { try { std::stringstream ss; ss << node; return ss.str(); } catch (...) { std::stringstream ss; ss << node; GXF_LOG_ERROR("Could not parse parameter '%s' from '%s'", key, ss.str().c_str()); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } } }; template <> struct ParameterParser { static Expected Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { try { FilePath path; std::stringstream ss; ss << node; path.assign(ss.str()); return path; } catch (...) { std::stringstream ss; ss << node; GXF_LOG_ERROR("Could not parse parameter '%s' from '%s'", key, ss.str().c_str()); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } } }; // Specialization of ParameterParser for uint8_t because it is not supported natively by yaml-cpp template <> struct ParameterParser { static Expected Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { try { return static_cast(node.as()); } catch (...) { std::stringstream ss; ss << node; GXF_LOG_ERROR("Could not parse parameter '%s' from '%s'", key, ss.str().c_str()); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } } }; // Specialization of ParameterParser for FixedString. // Substitutes std::string for safety-critical components. template struct ParameterParser> { static Expected> Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { return ParameterParser::Parse(context, component_uid, key, node, prefix) .map([&](std::string str) { FixedString string; return string.copy(str.data(), str.size()) .substitute_error(GXF_EXCEEDING_PREALLOCATED_SIZE) .substitute(string); }); } }; // Specialization of ParameterParser for FixedVector with stack allocation. // Substitutes std::array for safety-critical components. // TODO(ayusmans): parsing support for FixedVector with heap allocation template struct ParameterParser> { static Expected> Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!node.IsSequence()) { return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } if (node.size() > N) { GXF_LOG_ERROR("Parameter size (%zu) exceeds vector capacity (%zu)", node.size(), N); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } FixedVector vector; for (size_t i = 0; i < node.size(); i++) { const auto maybe = ParameterParser::Parse(context, component_uid, key, node[i], prefix); if (!maybe) { return ForwardError(maybe); } vector.push_back(std::move(maybe.value())); } return vector; } }; // Specialization of ParameterParser for gxf::Handle. It parses the parameter as a string and // interprets it as either a component name in the current entity, or as a composed string of the // form 'entity_name/component_name'. template struct ParameterParser> { static Expected> Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { const char* component_name = "UNKNOWN"; auto code = GxfParameterGetStr(context, component_uid, kInternalNameParameterKey, &component_name); if (code != GXF_SUCCESS) { return Unexpected{code}; } gxf_uid_t owner_eid, param_eid; const char* owner_entity_name = "UNKNOWN"; std::string param_entity_name; // Get the entity of this component const gxf_result_t result_1 = GxfComponentEntity(context, component_uid, &owner_eid); if (result_1 != GXF_SUCCESS) { return Unexpected{result_1}; } code = GxfEntityGetName(context, owner_eid, &owner_entity_name); if (code != GXF_SUCCESS) { return Unexpected{code}; } // Parse string from node std::string tag; try { tag = node.as(); } catch (...) { std::stringstream ss; ss << node; GXF_LOG_ERROR("Could not parse parameter '%s' from '%s'", key, ss.str().c_str()); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } std::string handle_component_name; const size_t pos = tag.find('/'); if (pos == std::string::npos) { handle_component_name = tag; // target param component and owner component reside in the same entity param_eid = owner_eid; } else { handle_component_name = tag.substr(pos + 1); // Get the entity gxf_result_t result_1_with_prefix = GXF_FAILURE; // Try using entity name with prefix if (!prefix.empty()) { param_entity_name = prefix + tag.substr(0, pos); // param eid result_1_with_prefix = GxfEntityFind(context, param_entity_name.c_str(), ¶m_eid); if (result_1_with_prefix != GXF_SUCCESS) { GXF_LOG_WARNING("Could not find entity (with prefix) '%s' while parsing parameter '%s' " "of component %s with id %zu", param_entity_name.c_str(), key, component_name, component_uid); } } // Try using entity name without prefix, if lookup with prefix failed if (result_1_with_prefix != GXF_SUCCESS) { param_entity_name = tag.substr(0, pos); // param eid const gxf_result_t result_1_no_prefix = GxfEntityFind(context, param_entity_name.c_str(), ¶m_eid); if (result_1_no_prefix != GXF_SUCCESS) { GXF_LOG_ERROR("Could not find entity '%s' while parsing parameter '%s' of component %s" " with id %zu", param_entity_name.c_str(), key, component_name, component_uid); return Unexpected{result_1_no_prefix}; } else if (!prefix.empty()) { GXF_LOG_WARNING("Found entity (without prefix) '%s' while parsing parameter '%s' " "of component '%s' with id %zu in a subgraph, however the approach is" " deprecated, please use prerequisites instead", param_entity_name.c_str(), key, component_name, component_uid); } } } // Get the type id of the component we are are looking for. gxf_tid_t tid; const gxf_result_t result_2 = GxfComponentTypeId(context, TypenameAsString(), &tid); if (result_2 != GXF_SUCCESS) { return Unexpected{result_2}; } // Find the component in the indicated entity // param eid gxf_uid_t cid; const gxf_result_t result_3 = GxfComponentFind(context, param_eid, tid, handle_component_name.c_str(), nullptr, &cid); if (result_3 != GXF_SUCCESS) { if (handle_component_name == "") { GXF_LOG_DEBUG("Using an handle in entity '%s' with id %zu while parsing " "parameter '%s' of component '%s' with id %zu. This handle must be set to a valid component" " before graph activation", owner_entity_name, owner_eid, key, component_name, component_uid); return Handle::Unspecified(); } else { GXF_LOG_WARNING("Cannot find target paramter component[entity name: %s, component name: %s]" " in type[%s] " "for owner component[entity name: %s, component name: %s, cid: %ld], " "during parsing its parameter[key: %s, value: %s]", param_entity_name.c_str(), handle_component_name.c_str(), // param component info TypenameAsString(), // expected param component type owner_entity_name, component_name, component_uid, // owner component info key, tag.c_str()); // param key:value string presentation // print help info for (int offset = 0; ; offset++) { auto code1 = GxfComponentFind(context, param_eid, GxfTidNull(), handle_component_name.c_str(), &offset, &cid); if (code1 == GXF_ENTITY_COMPONENT_NOT_FOUND) { GXF_LOG_DEBUG("No more component instance found as entity/component: %s", tag.c_str()); break; } else if (code1 != GXF_SUCCESS) { GXF_LOG_ERROR("Failed to execute component cid find with eid: %ld, " "component name: %s, offset: %d", param_eid, handle_component_name.c_str(), offset); return Unexpected{code1}; } const char* component_type_name = nullptr; auto code2 = GxfComponentTypeNameFromUID(context, cid, &component_type_name); if (code2 != GXF_SUCCESS) { GXF_LOG_ERROR("Failed to find component type name from cid [%ld]", cid); return Unexpected{code2}; } GXF_LOG_WARNING("Found component[%s] in type[%s]; " "however type[%s] is expected for " "component[entity name: %s, component name: %s, key: %s]", tag.c_str(), component_type_name, TypenameAsString(), owner_entity_name, component_name, key); } // end help info print } return Unexpected{result_3}; } return Handle::Create(context, cid); } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_PARAMETER_PARSER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/parameter_parser_std.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_PARAMETER_PARSER_STD_HPP_ #define NVIDIA_GXF_STD_PARAMETER_PARSER_STD_HPP_ #include #include #include #include #include #include #include "yaml-cpp/yaml.h" #include "common/assert.hpp" #include "common/yaml_parser.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" #include "gxf/core/handle.hpp" #include "gxf/core/parameter_parser.hpp" #include "gxf/core/parameter_registrar.hpp" namespace nvidia { namespace gxf { // Parses unknown many of known types. template struct ParameterParser> { static Expected> Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!node.IsSequence()) { const char* component_name = "UNKNOWN"; GxfParameterGetStr(context, component_uid, kInternalNameParameterKey, &component_name); GXF_LOG_ERROR("Parameter '%s' in component '%s' must be a vector", key, component_name); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } std::vector result(node.size()); for (size_t i = 0; i < node.size(); i++) { const auto maybe = ParameterParser::Parse(context, component_uid, key, node[i], prefix); if (!maybe) { return ForwardError(maybe); } result[i] = std::move(maybe.value()); } return result; } }; // Parses known many of known types. template struct ParameterParser> { static Expected> Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!node.IsSequence()) { const char* component_name = "UNKNOWN"; GxfParameterGetStr(context, component_uid, kInternalNameParameterKey, &component_name); GXF_LOG_ERROR("Parameter '%s' in component '%s' must be an array", key, component_name); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } if (node.size() != N) { GXF_LOG_ERROR("Length of parameter array (%zu) does not match required length (%zu)", node.size(), N); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } std::array result; for (size_t i = 0; i < result.size(); i++) { const auto maybe = ParameterParser::Parse(context, component_uid, key, node[i], prefix); if (!maybe) { return ForwardError(maybe); } result[i] = std::move(maybe.value()); } return result; } }; // Parameter support for std::unordered_map template struct ParameterParser> { static Expected> Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!node.IsMap()) { const char* component_name = "UNKNOWN"; GxfParameterGetStr(context, component_uid, kInternalNameParameterKey, &component_name); GXF_LOG_ERROR("Parameter '%s' in component '%s' must be a map", key, component_name); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } std::unordered_map map; for (const auto& iter : node) { const std::string& key = iter.first.as(); const YAML::Node& value = iter.second; auto maybe = ParameterParser::Parse(context, component_uid, key.c_str(), value, prefix); if (!maybe) { return ForwardError(maybe); } map[key] = std::move(maybe.value()); } return map; } }; template struct ParameterParser> { static Expected> Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { try { return static_cast>(node.as>()); } catch (...) { std::stringstream ss; ss << node; GXF_LOG_ERROR("Could not parse parameter '%s' from '%s'", key, ss.str().c_str()); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } } }; // Template specializations for ParameterInfo to be used during // parameter registration in the extension // Specialized ParameterInfoOverride for parameters of type std::vector template struct ParameterInfoOverride> { Expected apply(ParameterRegistrar* registrar, ParameterRegistrar::ComponentParameterInfo& info) { // Get the element info ParameterInfoOverride override; ParameterRegistrar::ComponentParameterInfo element_info; const auto result = override.apply(registrar, element_info); if (!result) { return ForwardError(result); } info.type = element_info.type; info.is_arithmetic = element_info.is_arithmetic; info.handle_tid = element_info.handle_tid; // Fetch the shape of and update it to the current ComponentParameterInfo for (int32_t i = 0; i < element_info.rank; ++i) { info.shape[i] = element_info.shape[i]; } // A vector increases the rank by 1 and adds shape [-1] to . info.shape[element_info.rank] = -1; info.rank = element_info.rank + 1; return Success; } }; // Specialized ParameterInfoOverride for parameters of type std::array template struct ParameterInfoOverride> { Expected apply(ParameterRegistrar* registrar, ParameterRegistrar::ComponentParameterInfo& info) { // Get the element info ParameterInfoOverride override; ParameterRegistrar::ComponentParameterInfo element_info; const auto result = override.apply(registrar, element_info); if (!result) { return ForwardError(result); } info.type = element_info.type; info.is_arithmetic = element_info.is_arithmetic; info.handle_tid = element_info.handle_tid; // Fetch the shape of and update it to the current ComponentParameterInfo for (int32_t i = 0; i < element_info.rank; ++i) { info.shape[i] = element_info.shape[i]; } // An increases the rank by 1 and adds shape [N] to . info.shape[element_info.rank] = N; info.rank = element_info.rank + 1; return Success; } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_PARAMETER_PARSER_STD_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/parameter_registrar.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_PARAMETER_REGISTRAR_HPP_ #define NVIDIA_GXF_STD_PARAMETER_REGISTRAR_HPP_ #include #include #include #include // NOLINT #include #include #include #include #include "common/memory_utils.hpp" #include "common/type_utils.hpp" #include "gxf/core/expected_macro.hpp" #include "gxf/core/gxf.h" #include "gxf/core/handle.hpp" #include "gxf/core/parameter.hpp" #include "gxf/core/type_registry.hpp" namespace nvidia { namespace gxf { // @brief Struct specifying parameters for registering parameter template struct ParameterInfo { // Key used to access the parameter. Required. const char* key = nullptr; // Brief description. Optional. const char* headline = nullptr; // Detailed description. Optional. const char* description = nullptr; // Applicable platform list separated by comma. Optional. const char* platform_information = nullptr; // Default value if not provided otherwise. Not applicable to Handle parameter. Optional. Expected value_default = Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; // Minimal value, Maximum value and Minimal step for arithmetic types. Optional. Expected> value_range = Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; // Bit flags about properties like if it is required etc. gxf_parameter_flags_t flags = GXF_PARAMETER_FLAGS_NONE; // Max allowed is rank 8 static constexpr const int32_t kMaxRank = 8; // Parameters can be tensors and this value indicates its rank. For a "scalar" rank is 0. int32_t rank = 0; // Parameters can be tensors and this is its shape. Only values up to rank must be set. If rank // is 0 no value must be set. -1 can be used to indicate a dynamic size which is not fixed at // compile time. int32_t shape[kMaxRank] = {1}; }; class Component; template struct ParameterTypeTrait { static constexpr const char* type_name = "(custom)"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_CUSTOM; static constexpr const bool is_arithmetic = false; }; template struct ParameterTypeTrait> { static constexpr const char* type_name = "(handle)"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_HANDLE; static constexpr const bool is_arithmetic = false; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "Int8"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_INT8; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "Int16"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_INT16; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "Int32"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_INT32; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "Int64"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_INT64; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "UInt8"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_UINT8; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "UInt16"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_UINT16; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "UInt32"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_UINT32; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "UInt64"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_UINT64; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "Float32"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_FLOAT32; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "Float64"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_FLOAT64; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "String"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_STRING; static constexpr const bool is_arithmetic = false; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "String"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_STRING; static constexpr const bool is_arithmetic = false; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "Boolean"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_BOOL; static constexpr const bool is_arithmetic = false; }; template <> struct ParameterTypeTrait { static constexpr const char* type_name = "File"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_FILE; static constexpr const bool is_arithmetic = false; }; template <> struct ParameterTypeTrait> { static constexpr const char* type_name = "Complex64"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_COMPLEX64; static constexpr const bool is_arithmetic = true; }; template <> struct ParameterTypeTrait> { static constexpr const char* type_name = "Complex128"; static constexpr const gxf_parameter_type_t type = GXF_PARAMETER_TYPE_COMPLEX128; static constexpr const bool is_arithmetic = true; }; // Stores parameters for an GXF application class ParameterRegistrar { public: // Container for a single object of any type // Contained object is dynamically allocated on the heap and properly destructed when finished class TypeEraser { public: TypeEraser() = default; TypeEraser(const TypeEraser& other) { *this = other; } TypeEraser(TypeEraser&& other) { *this = std::move(other); } template , TypeEraser>, TypeEraser*> = nullptr> TypeEraser(T&& value) { *this = std::forward(value); } ~TypeEraser() { reset(); } TypeEraser& operator=(const TypeEraser& other) { if (other.instance_) { instance_ = other.instance_->clone(); } return *this; } TypeEraser& operator=(TypeEraser&& other) { instance_ = std::move(other.instance_); return *this; } template EnableIf_t, TypeEraser>, TypeEraser&> operator=(T&& value) { instance_ = MakeUniqueNoThrow>>(std::forward(value)); return *this; } bool has_value() const { return static_cast(instance_); } const void* get() const { return has_value() ? instance_->get() : nullptr; } void reset() { instance_.reset(); } private: struct storage_base { virtual ~storage_base() = default; virtual const void* get() const = 0; virtual std::unique_ptr clone() const = 0; }; template struct storage_impl final : public storage_base { template storage_impl(Args&&... args) : value(std::forward(args)...) {} // FIXME: return c_str() directly for string types to avoid reinterpret_cast const void* get() const override { return &value; } std::unique_ptr clone() const override { return MakeUniqueNoThrow>(value); } T value; }; std::unique_ptr instance_; }; // Struct to hold information about a single parameter struct ComponentParameterInfo { std::string key; std::string headline; std::string description; std::string platform_information; gxf_parameter_type_t type; gxf_tid_t handle_tid = GxfTidNull(); bool is_arithmetic; gxf_parameter_flags_t flags; // params to be accessed only via getDefaultValue(...) // and getNumericRange(...) apis TypeEraser default_value; // Range info as [min, max, step] std::array value_range; int32_t rank = 0; int32_t shape[ParameterInfo::kMaxRank] = {0}; }; // Struct to hold information about all the parameters in a component struct ComponentInfo { std::string type_name; std::vector parameter_keys; std::unordered_map parameters; }; ParameterRegistrar() = default; template Expected registerComponentParameter(gxf_tid_t tid, const std::string& type_name, const ParameterInfo& parameter_info); template Expected> getParametersOfType(gxf_tid_t tid); // Add's a parameterless component to parameter registrar. These are useful to lookup component // tid using component type name when parameters of type Handle are being registered void addParameterlessType(const gxf_tid_t tid, std::string type_name); // Check if parameter registrar has a component bool hasComponent(const gxf_tid_t tid) const; // Get the number of parameters in a component size_t componentParameterCount(const gxf_tid_t tid) const; // Get the list of parameter keys in a component Expected getParameterKeys(const gxf_tid_t tid, const char** keys, size_t& count) const; // Check if a component has a parameter Expected componentHasParameter(const gxf_tid_t tid, const char* key) const; // Get the default value of a component // Depending on the data type of the parameter, default value has to be // casted into the data type specified in gxf_parameter_type_t in gxf.h Expected getDefaultValue(const gxf_tid_t tid, const char* key) const; // Load the numeric range of a parameter into gxf_parameter_info_t // Depending on the data type of the parameter, numeric ranges value have to be // casted into the data type specified in gxf_parameter_type_t in gxf.h Expected getNumericRange(const gxf_tid_t tid, const char* key, gxf_parameter_info_t* info) const; // fills the gxf_parameter_info_t struct with the info stored in the parameter registrar // for that specific component and parameter key Expected getParameterInfo(const gxf_tid_t tid, const char* key, gxf_parameter_info_t* info) const; // Returns the pointer to ComponentParameterInfo object in ComponentInfo Expected getComponentParameterInfoPtr(const gxf_tid_t tid, const char* key) const; // Get the tid of a component which has already been registered with the type registry, // returns Unexpected if component not found Expected tidFromTypename(std::string type_name) { for (const auto& cparam : component_parameters) { if (cparam.second->type_name == type_name) { return cparam.first; } } GXF_LOG_ERROR("Component type not found %s", type_name.c_str()); return Unexpected{GXF_ENTITY_COMPONENT_NOT_FOUND}; } private: // Verifies the info of a new parameter being registered and fills the info // in the ComponentParameterInfo struct which is returned Expected registerComponentParameterImpl(gxf_tid_t tid, const std::string& type_name, ComponentParameterInfo& info); // Maintains a map of {tid : ComponentInfo} // component type name in ComponentInfo is used to look up the corresponding tid when a parameter // of handle is used for that component std::map> component_parameters; }; // loads numeric range info from ComponentParameterInfo to gxf_parameter_info_t template static bool getNumericRangeImpl(ParameterRegistrar::ComponentParameterInfo* ptr, gxf_parameter_info_t* info) { static_assert(ParameterTypeTrait::is_arithmetic); if (!ptr || !info) { return false; } info->numeric_min = nullptr; info->numeric_max = nullptr; info->numeric_step = nullptr; if (std::get<0>(ptr->value_range).has_value()) { info->numeric_min = std::get<0>(ptr->value_range).get(); } if (std::get<1>(ptr->value_range).has_value()) { info->numeric_max = std::get<1>(ptr->value_range).get(); } if (std::get<2>(ptr->value_range).has_value()) { info->numeric_step = std::get<2>(ptr->value_range).get(); } return true; } // Provides a customizable step which can be used during parameter registration to modify // parameter info given to registry before it is written to the parameter info storage. template struct ParameterInfoOverride { Expected apply(ParameterRegistrar* /*registrar*/, ParameterRegistrar::ComponentParameterInfo& info) { info.type = ParameterTypeTrait::type; info.is_arithmetic = ParameterTypeTrait::is_arithmetic; info.handle_tid = GxfTidNull(); return Success; } }; // Specialized ParameterInfoOverride for parameters of type handle template struct ParameterInfoOverride> { Expected apply(ParameterRegistrar* registrar, ParameterRegistrar::ComponentParameterInfo& info) { info.type = GXF_PARAMETER_TYPE_HANDLE; info.is_arithmetic = false; auto handle = registrar->tidFromTypename(TypenameAsString()); if (!handle) { return ForwardError(handle); } info.handle_tid = handle.value(); return Success; } }; template Expected ParameterRegistrar::registerComponentParameter( gxf_tid_t tid, const std::string& type_name, const ParameterInfo& registrar_info) { ComponentParameterInfo info; if (registrar_info.key == nullptr) { return Unexpected{GXF_ARGUMENT_NULL}; } info.key = std::string{registrar_info.key}; if (registrar_info.headline == nullptr) { return Unexpected{GXF_ARGUMENT_NULL}; } info.headline = std::string{registrar_info.headline}; if (registrar_info.description == nullptr) { return Unexpected{GXF_ARGUMENT_NULL}; } info.description = std::string{registrar_info.description}; // Handles platform information if present if (registrar_info.platform_information != nullptr) { info.platform_information = std::string{registrar_info.platform_information}; } if (registrar_info.value_default) { info.default_value = *registrar_info.value_default; } else { info.default_value.reset(); } if (registrar_info.value_range) { std::get<0>(info.value_range) = std::get<0>(*registrar_info.value_range); std::get<1>(info.value_range) = std::get<1>(*registrar_info.value_range); std::get<2>(info.value_range) = std::get<2>(*registrar_info.value_range); } else { std::get<0>(info.value_range).reset(); std::get<1>(info.value_range).reset(); std::get<2>(info.value_range).reset(); } info.flags = registrar_info.flags; // Set the rank and make sure the shape is correct. info.rank = registrar_info.rank; if (info.rank > ParameterInfo::kMaxRank) { return Unexpected{GXF_ARGUMENT_OUT_OF_RANGE}; } for (int32_t i = 0; i < info.rank; i++) { info.shape[i] = registrar_info.shape[i]; } for (int32_t i = info.rank; i < ParameterInfo::kMaxRank; i++) { info.shape[i] = 1; } // Apply custom overrides ParameterInfoOverride custom_override; const auto result = custom_override.apply(this, info); if (!result) { GXF_LOG_ERROR("Parameter Override failed for Component \"%s\" and Parameter \"%s\"", type_name.c_str(), registrar_info.key); return result; } // register the parameter return registerComponentParameterImpl(tid, type_name, info); } // Provides a customizable step which can be used to query parameter info template struct ParameterQueryOverride { Expected> query( ParameterRegistrar* registrar, gxf_tid_t tid) { std::string type_name{TypenameAsString()}; size_t count = registrar->componentParameterCount(tid); const char* keys[count]; GXF_RETURN_IF_ERROR(registrar->getParameterKeys(tid, keys, count)); std::vector result; for (size_t i = 0; i < count; ++i) { auto info = GXF_UNWRAP_OR_RETURN(registrar->getComponentParameterInfoPtr(tid, keys[i])); if (info->type == ParameterTypeTrait::type) { result.push_back(*info); } } return result; } }; // Specialized ParameterInfoOverride for parameters of type handle template struct ParameterQueryOverride> { Expected> query( ParameterRegistrar* registrar, gxf_tid_t tid) { std::string type_name{TypenameAsString()}; auto query_tid = GXF_UNWRAP_OR_RETURN(registrar->tidFromTypename(type_name)); size_t count = registrar->componentParameterCount(tid); const char* keys[count]; GXF_RETURN_IF_ERROR(registrar->getParameterKeys(tid, keys, count)); std::vector result; for (size_t i = 0; i < count; ++i) { auto info = GXF_UNWRAP_OR_RETURN(registrar->getComponentParameterInfoPtr(tid, keys[i])); if (info->type != GXF_PARAMETER_TYPE_HANDLE ) {continue;} if (info->handle_tid == query_tid) { result.push_back(*info); } } return result; } }; template Expected> ParameterRegistrar::getParametersOfType(gxf_tid_t tid) { ParameterQueryOverride override; return override.query(this, tid); } } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_PARAMETER_REGISTRAR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/parameter_storage.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_PARAMETER_STORAGE_HPP_ #define NVIDIA_GXF_STD_PARAMETER_STORAGE_HPP_ #include #include #include #include #include // NOLINT #include #include #include "gxf/core/parameter.hpp" namespace nvidia { namespace gxf { // Stores all parameters for an GXF application // // Parameters are stored in a dictionary style class. For each parameter the actual parameter value // and various helper classes to query and set parameters are provided. class ParameterStorage { public: ParameterStorage(gxf_context_t context); // Registers a parameter with the backend. This is used by components when they register their // parameter interface to connect parameters in components to the backend. template Expected registerParameter(nvidia::gxf::Parameter* frontend, gxf_uid_t uid, const char* key, const char* headline, const char* description, Expected default_value, gxf_parameter_flags_t flags) { if (frontend == nullptr) { return Unexpected{GXF_ARGUMENT_NULL}; } if (key == nullptr) { return Unexpected{GXF_ARGUMENT_NULL}; } if (headline == nullptr) { return Unexpected{GXF_ARGUMENT_NULL}; } if (description == nullptr) { return Unexpected{GXF_ARGUMENT_NULL}; } std::unique_lock lock(mutex_); auto it = parameters_.find(uid); if (it == parameters_.end()) { std::map> tmp; it = parameters_.insert({uid, std::move(tmp)}).first; } const auto jt = it->second.find(key); if (jt != it->second.end()) { return Unexpected{GXF_PARAMETER_ALREADY_REGISTERED}; } auto backend = std::make_unique>(); backend->context_ = context_; backend->uid_ = uid; backend->flags_ = flags; backend->is_dynamic_ = false; backend->key_ = key; backend->headline_ = headline; backend->description_ = description; backend->frontend_ = frontend; // FIXME(v1) validator frontend->connect(backend.get()); if (default_value) { const auto code = backend->set(std::move(*default_value)); if (!code) { return ForwardError(code); } backend->writeToFrontend(); } it->second.insert({key, std::move(backend)}).first; return Success; } Expected parse(gxf_uid_t uid, const char* key, const YAML::Node& node, const std::string& prefix); Expected wrap(gxf_uid_t uid, const char* key); // Sets a parameter. If the parameter is not yet present a new dynamic parameter will be created. // This function fails if a parameter already exists, but with the wrong type. template Expected set(gxf_uid_t uid, const char* key, T value) { std::unique_lock lock(mutex_); GXF_LOG_VERBOSE("Setting parameter [%s] of type [%s] on uid [%" PRId64 "]", key, TypenameAsString(), uid); auto it = parameters_.find(uid); if (it == parameters_.end()) { std::map> tmp; it = parameters_.insert({uid, std::move(tmp)}).first; } auto jt = it->second.find(key); if (jt == it->second.end()) { auto ptr = std::make_unique>(); ptr->context_ = context_; ptr->uid_ = uid; ptr->flags_ = GXF_PARAMETER_FLAGS_OPTIONAL | GXF_PARAMETER_FLAGS_DYNAMIC; ptr->is_dynamic_ = true; ptr->key_ = key; ptr->headline_ = key; ptr->description_ = "N/A"; jt = it->second.insert({key, std::move(ptr)}).first; } auto* ptr = dynamic_cast*>(jt->second.get()); if (ptr == nullptr) { GXF_LOG_ERROR("Attempting to set invalid parameter type for [%s] with type [%s]", key, TypenameAsString()); return Unexpected{GXF_PARAMETER_INVALID_TYPE}; } const auto code = ptr->set(std::move(value)); if (!code) { return ForwardError(code); } ptr->writeToFrontend(); // FIXME(v1) Special treatment for codelet parameters return Success; } // Gets a parameter template Expected get(gxf_uid_t uid, const char* key) const { std::shared_lock lock(mutex_); return getValuePointer(uid, key).map([](const T* pointer) { return *pointer; }); } // Sets a string parameter. The storage creates it's own internal copy and does not take ownership // of the given pointer. Expected setStr(gxf_uid_t uid, const char* key, const char* value); // Gets a string parameter. A pointer to the internal storage is returned whose contents may // change if a call to setStr happens in the meantime. Expected getStr(gxf_uid_t uid, const char* key) const; // Sets a file path parameter. Expected setPath(gxf_uid_t, const char* key, const char* value); // Gets a file path parameter. A pointer to the internal storage is returned whose contents may // change if a call to setPath happens in the meantime. Expected getPath(gxf_uid_t uid, const char* key) const; // Sets a handle parameter. Expected setHandle(gxf_uid_t, const char* key, gxf_uid_t value); // Gets a handle parameter. Expected getHandle(gxf_uid_t uid, const char* key) const; // Sets a vector of string parameter. The storage creates it's own internal copy and does not take // ownership of the given pointer. Expected setStrVector(gxf_uid_t uid, const char* key, const char** value, uint64_t length); // Adds the given value to a parameter and returns the result. The parameter is initialized to // 0 in case it does not exist. Expected addGetInt64(gxf_uid_t uid, const char* key, int64_t delta); // Returns true if all mandatory parameters are available Expected isAvailable() const; // Returns true if all mandatory parameters of a component are available Expected isAvailable(gxf_uid_t uid) const; // Clean up data for specific Entity upon Entity destruction Expected clearEntityParameters(gxf_uid_t eid); private: friend class Runtime; // Finds a parameter and returns a pointer to its value. template Expected getValuePointer(gxf_uid_t uid, const char* key) const { std::shared_lock lock(mutex_); auto backend = getBackendPointerImpl>(uid, key); if (!backend) { return ForwardError(backend); } const auto& maybe = backend.value()->try_get(); if (!maybe) { return Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; } return &(*maybe); } // Finds a parameter backend and returns a pointer to it. template Expected getBackendPointerImpl(gxf_uid_t uid, const char* key) const { const auto it = parameters_.find(uid); if (it == parameters_.end()) { return Unexpected{GXF_PARAMETER_NOT_FOUND}; } const auto jt = it->second.find(key); if (jt == it->second.end()) { return Unexpected{GXF_PARAMETER_NOT_FOUND}; } const T* ptr = dynamic_cast(jt->second.get()); if (ptr == nullptr) { return Unexpected{GXF_PARAMETER_INVALID_TYPE}; } return ptr; } // Finds a parameter backend and returns a pointer to it. template Expected getBackendPointerImpl(gxf_uid_t uid, const char* key) { const auto it = parameters_.find(uid); if (it == parameters_.end()) { return Unexpected{GXF_PARAMETER_NOT_FOUND}; } const auto jt = it->second.find(key); if (jt == it->second.end()) { return Unexpected{GXF_PARAMETER_NOT_FOUND}; } T* ptr = dynamic_cast(jt->second.get()); if (ptr == nullptr) { return Unexpected{GXF_PARAMETER_INVALID_TYPE}; } return ptr; } mutable std::shared_timed_mutex mutex_; gxf_context_t context_; std::map>> parameters_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_PARAMETER_STORAGE_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/parameter_wrapper.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_PARAMETER_WRAPPER_HPP_ #define NVIDIA_GXF_STD_PARAMETER_WRAPPER_HPP_ #include #include #include #include #include #include "common/yaml_parser.hpp" #include "gxf/core/gxf.h" #include "gxf/core/handle.hpp" #include "yaml-cpp/yaml.h" namespace nvidia { namespace gxf { template struct ParameterWrapper; template struct ParameterWrapper { // Wrap the value to a YAML::Node instance static Expected Wrap(gxf_context_t context, const T& value) { return YAML::Node(value); } }; template struct ParameterWrapper> { static Expected Wrap(gxf_context_t context, const Handle& value) { std::string c_name = value.name(); const char *entity_name; gxf_uid_t eid = kNullUid; auto result = GxfComponentEntity(context, value.cid(), &eid); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Unable to find the entity for %s", c_name.c_str()); return Unexpected{result}; } result = GxfEntityGetName(context, eid, &entity_name); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("Unable to get the entity name"); return Unexpected{result}; } std::string full_name = std::string(entity_name) + "/" + c_name; return YAML::Node(full_name); } }; template struct ParameterWrapper>> { static Expected Wrap( gxf_context_t context, const std::vector>& value) { YAML::Node node(YAML::NodeType::Sequence); for (auto &h : value) { auto maybe = ParameterWrapper>::Wrap(context, h); if (!maybe) { return Unexpected{maybe.error()}; } node.push_back(maybe.value()); } return node; } }; template struct ParameterWrapper, N>> { static Expected Wrap( gxf_context_t context, const std::array, N>& value) { YAML::Node node(YAML::NodeType::Sequence); for (auto &h : value) { auto maybe = ParameterWrapper>::Wrap(context, h); if (!maybe) { return Unexpected{maybe.error()}; } node.push_back(maybe.value()); } return node; } }; template struct ParameterWrapper> { static Expected Wrap( gxf_context_t context, const std::unordered_map& map) { YAML::Node node(YAML::NodeType::Map); for (const auto& iter : map) { const std::string& key = iter.first; const T& value = iter.second; auto maybe = ParameterWrapper::Wrap(context, value); if (!maybe) { return ForwardError(maybe); } node[key] = std::move(maybe.value()); } return node; } }; template struct ParameterWrapper> { static Expected Wrap( gxf_context_t context, const nvidia::FixedVector& value) { YAML::Node node(YAML::NodeType::Sequence); for (size_t i = 0; i < value.size(); i++) { auto v = value.at(i).value(); auto maybe = ParameterWrapper::Wrap(context, v); if (!maybe) { return Unexpected{maybe.error()}; } node.push_back(maybe.value()); } return node; } }; template struct ParameterWrapper> { static Expected Wrap( gxf_context_t context, const nvidia::FixedString& value) { return ParameterWrapper::Wrap(context, std::string(value.c_str())); } }; template struct ParameterWrapper, N>> { static Expected Wrap( gxf_context_t context, const nvidia::FixedVector, N>& value) { YAML::Node node(YAML::NodeType::Sequence); for (size_t i = 0; i < value.size(); i++) { auto h = value.at(i).value(); auto maybe = ParameterWrapper>::Wrap(context, h); if (!maybe) { return Unexpected{maybe.error()}; } node.push_back(maybe.value()); } return node; } }; template<> struct ParameterWrapper { static Expected Wrap( gxf_context_t context, const nvidia::gxf::FilePath& value) { return ParameterWrapper::Wrap(context, value); } }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/registrar.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_REGISTRAR_HPP_ #define NVIDIA_GXF_CORE_REGISTRAR_HPP_ #include #include #include // NOLINT #include #include #include #include "gxf/core/parameter.hpp" #include "gxf/core/parameter_registrar.hpp" #include "gxf/core/parameter_storage.hpp" #include "gxf/core/resource.hpp" #include "gxf/core/resource_manager.hpp" #include "gxf/core/resource_registrar.hpp" namespace nvidia { namespace gxf { // Registers parameters and other information of components class Registrar { public: // Constant for registering an optional parameter with no default value static constexpr Unexpected NoDefaultParameter() { return Unexpected{GXF_PARAMETER_NOT_INITIALIZED}; } Registrar() = default; // Simplified version of 'parameter'. template Expected parameter(Parameter& parameter, const char* key) { return parameterImpl(parameter, {key, key, "N/A"}); } // Simplified version of 'parameter'. template Expected parameter(Parameter& parameter, const char* key, const char* headline) { return parameterImpl(parameter, {key, headline, "N/A"}); } // Simplified version of 'parameter'. template Expected parameter(Parameter& parameter, const char* key, const char* headline, const char* description) { return parameterImpl(parameter, {key, headline, description}); } // Simplified version of 'parameter'. template Expected parameter(Parameter& parameter, const char* key, const char* headline, const char* description, const T& default_value) { ParameterInfo info; info.key = key; info.headline = headline; info.description = description; info.value_default = default_value; return parameterImpl(parameter, info); } // Register a component parameter. Every parameter must be registered in the function // 'registerInterface'. template Expected parameter(Parameter& parameter, const char* key, const char* headline, const char* description, const T& default_value, gxf_parameter_flags_t flags) { ParameterInfo info; info.key = key; info.headline = headline; info.description = description; info.value_default = default_value; info.flags = flags; return parameterImpl(parameter, info); } // Register a component parameter. Every parameter must be registered in the function // 'registerInterface'. template Expected parameter(Parameter& parameter, const char* key, const char* headline, const char* description, Unexpected, gxf_parameter_flags_t flags) { ParameterInfo info; info.key = key; info.headline = headline; info.description = description; info.flags = flags; return parameterImpl(parameter, info); } // Registers with a struct of all info. template Expected parameter(nvidia::gxf::Parameter& parameter, const ParameterInfo& parameter_info) { return parameterImpl(parameter, parameter_info); } // Implementation for parameter() above that registers parameter in ParameterRegistrar and // ParameterStorage. // register component's Parameter class members. Two usages: // 1. Register, maintain a map { comp_tid : parameter_info{tid} } // when Runtime call Component::registerInterface() in GxfRegisterComponent() // set parameter_registrar != nullptr && a mock parameter_storage // 2. Populate ParameterStorage, maintain a map { comp_cid : backend_parameters } // create each backend_parameter, connect corresponding frontend_parameter // when Runtime call Component::registerInterface() in GxfComponentAdd() // set parameter_registrar == nullptr && parameter_storage != nullptr template Expected parameterImpl(nvidia::gxf::Parameter& parameter, const ParameterInfo& parameter_info) { if (parameter_registrar != nullptr) { Expected result = parameter_registrar->registerComponentParameter(tid, type_name, parameter_info); if (!result) { return ForwardError(result); } } if (parameter_storage == nullptr) { return Unexpected{GXF_CONTEXT_INVALID}; } return parameter_storage->registerParameter( ¶meter, cid, parameter_info.key, parameter_info.headline, parameter_info.description, parameter_info.value_default, parameter_info.flags); } // Registers a component with no parameters Expected registerParameterlessComponent() { if (parameter_registrar != nullptr) parameter_registrar->addParameterlessType(tid, type_name); return Success; } // register component's Resource class members. Two usages: // 1. Register, maintain a map { comp_tid : resources_info{tid} } // when Runtime call Component::registerInterface() in GxfRegisterComponent() // set resource_registrar != nullptr && resource_manager = nullptr // 2. Connect, assign ResourceManager ptr to each resource class member // when Runtime call Component::registerInterface() in GxfComponentAdd() // set resource_registrar == nullptr && resource_manager != nullptr template Expected resource(Resource>& resource, const char* description) { // only for first time Runtime call Component::registerInterface(), // i.e. register by GxfRegisterComponent() if (resource_registrar != nullptr) { Expected result = resource_registrar->registerComponentResource(tid, type_name.c_str(), description); if (!result) { return ForwardError(result); } } // only for second time Runtime call Component::registerInterface(), // i.e. allocate by GxfComponentAdd() if (resource_manager != nullptr) { // resource_manager is empty at this stage, // but should be populated before resource value query Expected result1 = resource.connect(resource_manager, cid); if (!result1) { return ForwardError(result1); } } return Success; } // Sets the mandatory parameter storage where parameters loaded from YAML are stored. void setParameterStorage(std::shared_ptr param_storage) { parameter_storage = param_storage; } // Gets the mandatory parameter storage where parameters loaded from YAML are stored. ParameterStorage* getParameterStorage() { return parameter_storage.get(); } // Sets parameter registrar void setParameterRegistrar(ParameterRegistrar* param_registrar) { parameter_registrar = param_registrar; } // Gets the parameter registrar used to register the component interface ParameterRegistrar* getParameterRegistrar() { return parameter_registrar; } // Sets resource registrar void setResourceRegistrar(std::shared_ptr resource_registrar) { this->resource_registrar = resource_registrar; } // Sets resource manager void setResourceManager(std::shared_ptr resource_manager) { this->resource_manager = resource_manager; } std::shared_ptr parameter_storage = nullptr; // Stores information about parameter for query ParameterRegistrar* parameter_registrar = nullptr; std::shared_ptr resource_registrar = nullptr; // have to stick to shared_ptr to avoid nullptr dereferencing risk, // as Codelet's Resource try_get() are lazy call std::shared_ptr resource_manager; // The type id of registering component gxf_tid_t tid; // The instance uid of registering component gxf_uid_t cid = 0; // The typename of the registering component std::string type_name; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CORE_REGISTRAR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/resource.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_RESOURCE_HPP_ #define NVIDIA_GXF_CORE_RESOURCE_HPP_ #include #include "gxf/core/expected.hpp" #include "gxf/core/handle.hpp" #include "gxf/core/resource_manager.hpp" namespace nvidia { namespace gxf { template class Resource; template class Resource> { public: // Tries to get the Resource value. If first time call, query ResourceManager and save // the value for subsequent calls. // If invalid ResourceManager ptr, Handle::Unspecified() keeps returning every time // If ResourceManager cannot find the target, GXF_ENTITY_COMPONENT_NOT_FOUND // will be saved into value_. No repeat query. const Expected>& try_get(const char* name = nullptr) const { if (value_ == Handle::Unspecified()) { if (resource_manager_ == nullptr) { GXF_LOG_WARNING("Resource [type: %s] from component [cid: %ld] cannot get " "its value because of nullptr ResourceManager", TypenameAsString(), owner_cid_); return unspecified_handle_; } else { Expected> maybe_value = resource_manager_->findComponentResource(owner_cid_, name); if (!maybe_value) { GXF_LOG_DEBUG("Resource [type: %s] from component [cid: %ld] " "cannot find its value from ResourceManager", TypenameAsString(), owner_cid_); value_ = ForwardError(maybe_value); return value_; } value_ = maybe_value.value(); } } return value_; } Expected connect(std::shared_ptr resource_manager, gxf_uid_t owner_cid) { if (resource_manager == nullptr) { GXF_LOG_WARNING("nullptr ResourceManager ptr passed to connect Resource: %s from cid: %ld", TypenameAsString(), owner_cid); } resource_manager_ = resource_manager; owner_cid_ = owner_cid; return Success; } private: gxf_uid_t owner_cid_ = 0; std::shared_ptr resource_manager_; mutable Expected> value_ = Handle::Unspecified(); // Used to return an Unexpected when the handle is not specified const Expected> unspecified_handle_ = Unexpected{GXF_RESOURCE_NOT_INITIALIZED}; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CORE_RESOURCE_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/resource_manager.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GXF_STD_RESOURCE_MANAGER_HPP_ #define NVIDIA_GXF_GXF_STD_RESOURCE_MANAGER_HPP_ #include #include #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" #include "gxf/core/handle.hpp" namespace nvidia { namespace gxf { /// @brief Provide lookup from eid & resource type to resource_cids class ResourceManager { public: ResourceManager(gxf_context_t context); virtual ~ResourceManager() = default; // Static public interface static Expected findEntityResourceByTypeName(gxf_context_t context, gxf_uid_t eid, const char* type_name, const char* target_resource_name = nullptr); // Static public interface static Expected findComponentResourceByTypeName(gxf_context_t context, gxf_uid_t cid, const char* type_name, const char* target_resource_name = nullptr); // Static public interface // Find Resource of type Handle belong to entity eid template static Expected> findEntityResource(gxf_context_t context, gxf_uid_t eid, const char* target_resource_name = nullptr) { const char* type_name = TypenameAsString(); Expected maybe_cid = ResourceManager::findEntityResourceByTypeName(context, eid, type_name, target_resource_name); if (!maybe_cid) { return ForwardError(maybe_cid); } return Handle::Create(context, maybe_cid.value()); } // Find Resource of type Handle belong to entity eid template Expected> findEntityResource(gxf_uid_t eid, const char* target_resource_name = nullptr) { // object member function calls class static function return ResourceManager::findEntityResource(context_, eid, target_resource_name); } // Find Resource of type Handle belong to component cid template Expected> findComponentResource(gxf_uid_t cid, const char* target_resource_name = nullptr) { const char* type_name = TypenameAsString(); Expected maybe_cid = ResourceManager::findComponentResourceByTypeName(context_, cid, type_name, target_resource_name); if (!maybe_cid) { return ForwardError(maybe_cid); } return Handle::Create(context_, maybe_cid.value()); } private: gxf_context_t context_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GXF_STD_RESOURCE_MANAGER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/resource_registrar.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GXF_STD_RESOURCE_REGISTRAR_HPP_ #define NVIDIA_GXF_GXF_STD_RESOURCE_REGISTRAR_HPP_ #include #include #include #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { /// @brief Maintains a map of {component_tid : ComponentInfo(Resources)} class ResourceRegistrar { public: ResourceRegistrar(gxf_context_t context) : context_(context) {} // Struct to hold information about a single Resource struct ComponentResourceInfo { gxf_tid_t handle_tid = GxfTidNull(); std::string description; }; // Struct to hold information about all the Resources in a component struct ComponentInfo { std::string type_name; std::map resources; }; template Expected registerComponentResource(gxf_tid_t comp_tid, const char* comp_type_name, const char* resource_description) { auto it = component_resources_.find(comp_tid); if (it == component_resources_.end()) { component_resources_[comp_tid] = std::make_unique(); it = component_resources_.find(comp_tid); } gxf_tid_t resource_tid; gxf_result_t result = GxfComponentTypeId(context_, TypenameAsString(), &resource_tid); if (result != GXF_SUCCESS) { GXF_LOG_ERROR("ResourceRegistrar: Runtime cannot " "find tid of resource [type name: %s]", TypenameAsString()); return Unexpected { result }; } const auto jt = it->second->resources.find(resource_tid); if (jt != it->second->resources.end()) { return Unexpected{GXF_PARAMETER_ALREADY_REGISTERED}; } ComponentResourceInfo info; info.handle_tid = resource_tid; info.description = std::string(resource_description); it->second->type_name = comp_type_name; it->second->resources[info.handle_tid] = info; return Success; } private: gxf_context_t context_; std::map> component_resources_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GXF_STD_RESOURCE_REGISTRAR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/core/type_registry.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_TYPE_REGISTRY_HPP #define NVIDIA_GXF_STD_TYPE_REGISTRY_HPP #include #include #include // NOLINT #include #include "gxf/core/expected.hpp" namespace nvidia { namespace gxf { // A type registry which maps a C++ type to it's name and which can be used to // track base classes. class TypeRegistry { public: Expected add(gxf_tid_t tid, const char* component_type_name); Expected add_base(const char* component_type_name, const char* base_type_name); Expected id_from_name(const char* component_type_name) const; Expected is_base(gxf_tid_t derived, gxf_tid_t base) const; Expected name(gxf_tid_t tid) const; private: std::map names_; std::map tids_; std::map> bases_; mutable std::shared_timed_mutex mutex_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_ALLOCATOR_HPP #define NVIDIA_GXF_CUDA_ALLOCATOR_HPP #include #include #include "gxf/std/allocator.hpp" namespace nvidia { namespace gxf { /** * @brief Provides both synchronous and asynchronous allocation and deallocation of memory. */ class CudaAllocator : public Allocator { public: virtual Expected allocate_async(uint64_t size, cudaStream_t stream); virtual Expected free_async(byte* pointer, cudaStream_t stream); virtual gxf_result_t allocate_async_abi(uint64_t, void**, cudaStream_t) = 0; virtual gxf_result_t free_async_abi(void*, cudaStream_t) = 0; virtual Expected get_pool_size(MemoryStorageType type) const = 0; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_ALLOCATOR_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_buffer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_CUDA_BUFFER_HPP_ #define NVIDIA_GXF_CUDA_CUDA_BUFFER_HPP_ #include #include #include "common/byte.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/handle.hpp" #include "gxf/cuda/cuda_allocator.hpp" #include "gxf/cuda/cuda_common.hpp" #include "gxf/cuda/cuda_stream.hpp" #include "gxf/cuda/cuda_stream_pool.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/memory_buffer.hpp" namespace nvidia { namespace gxf { constexpr const char* kDefaultCudaBufferName = "gxf_cuda_buffer"; /** * @brief A container for a single block of cuda memory with support for async memory allocations. * * Each CudaBuffer is type of MemoryBuffer associated with a CudaAllocator, CudaStreamPool & * CudaStream. Memory is allocated by resizing the buffer. Both cuda memory and the cuda stream is * released back into the pool when a cuda buffer object is destroyed. */ class CudaBuffer : public MemoryBuffer { public: // state of the buffer enum class State : int8_t { UNSET = 0, // Initial state not waiting for any cuda event callback CALLBACK_REGISTERED, // Indicates a call back function is registered DATA_AVAILABLE, // Indicates data is ready to be consumed }; CudaBuffer() = default; CudaBuffer(const CudaBuffer&) = delete; CudaBuffer& operator=(const CudaBuffer&) = delete; CudaBuffer(CudaBuffer&& other) noexcept { *this = std::move(other); } CudaBuffer& operator=(CudaBuffer&& other) noexcept { if (this == &other) { return *this; } state_ = other.state_.load(); release_func_ = std::move(other.release_func_); stream_ = std::move(other.stream_); stream_owner_ = other.stream_owner_.load(); stream_pool_ = std::move(other.stream_pool_); other.state_ = State::UNSET; other.stream_owner_ = false; other.release_func_ = nullptr; return *this; } // callback function to release memory passed to the CudaBuffer using release_function_t = std::function (void* pointer)>; // Host callback function prototype using callback_function_t = void(*)(void*); static void CUDART_CB cudaHostCallback(void* buffer_ptr) { auto buffer = reinterpret_cast(buffer_ptr); GXF_LOG_VERBOSE("Received host callback from cuda stream for cuda buffer"); auto cb_registered = State::CALLBACK_REGISTERED; GXF_ASSERT_TRUE(buffer->state_.compare_exchange_strong(cb_registered, State::DATA_AVAILABLE)); } Expected freeBuffer() { auto state = state_.load(); // If another callback is already registered, buffer should not be freed GXF_ASSERT_NE(static_cast(state), static_cast(State::CALLBACK_REGISTERED)); state_ = State::UNSET; if (release_func_ && pointer_) { const Expected result = release_func_(pointer_); if (!result) { return ForwardError(result); } release_func_ = nullptr; } return Success; } ~CudaBuffer() { freeBuffer(); } // Resizes the cuda buffer to given size on custom cuda stream. A new stream is allocated // from the stream pool if a pre allocated stream is not provided. Expected resizeAsync(Handle allocator, Handle stream_pool, uint64_t size, Handle stream_handle = Handle::Null()) { if (!allocator) { GXF_LOG_ERROR("Invalid cuda allocator provided while resizing a cuda buffer"); return Unexpected{GXF_ARGUMENT_INVALID}; } if (!stream_pool) { GXF_LOG_ERROR("Invalid cuda stream pool provided while resizing a cuda buffer"); return Unexpected{GXF_ARGUMENT_INVALID}; } const auto code = freeBuffer(); if (!code) { GXF_LOG_ERROR("Failed to free memory. Error code: %s", GxfResultStr(code.error())); return ForwardError(code); } // Allocate new stream if its not pre-allocated if (!stream_handle) { stream_handle = GXF_UNWRAP_OR_RETURN(stream_pool->allocateStream()); } auto stream = GXF_UNWRAP_OR_RETURN(stream_handle->stream()); auto result = GXF_UNWRAP_OR_RETURN(allocator->allocate_async(size, stream)); GXF_LOG_VERBOSE("Registering callback for cuda buffer"); auto unset = State::UNSET; GXF_ASSERT_TRUE(state_.compare_exchange_strong(unset, State::CALLBACK_REGISTERED)); cudaError_t cuda_result = cudaLaunchHostFunc(stream, cudaHostCallback, this); CHECK_CUDA_ERROR(cuda_result, "Unable to register host function using cudaLaunchHostFunc"); storage_type_ = MemoryStorageType::kDevice; pointer_ = result; size_ = size; // TODO(chandrahasj) should allow custom stream to release the data ? release_func_ = [allocator, stream_pool, stream_handle, this] (void *data) { auto stream = stream_handle->stream().value(); allocator->free_async(reinterpret_cast(data), stream); if (this->stream_owner_.load()) { // synchronize the stream before releasing it back into the pool auto code = cudaStreamSynchronize(stream_handle->stream().value()); if (code != cudaSuccess) { GXF_LOG_ERROR("Failed to synchronize cuda stream"); return ExpectedOrCode(GXF_FAILURE); } return stream_pool->releaseStream(stream_handle); } return Success; }; stream_ = stream_handle; stream_pool_ = stream_pool; return Success; } // Retrieves cuda buffer state State state() const { return state_.load(); } // Retrieves CudaStream Handle stream() { return stream_; } // Retrieves CudaStreamPool Handle streamPool() { return stream_pool_; } // Ownership of CudaStream is transferred to the caller. // Stream will not be released when this object is destroyed. Handle transferStreamOwnership() { stream_owner_ = false; return stream_; } // Register a host function callback on the cuda stream associated with the buffer Expected registerCallbackOnStream(callback_function_t func, void* data) { if (!stream_) { GXF_LOG_ERROR("CudaStream is not set for the CudaBuffer"); return Unexpected{GXF_FAILURE}; } auto stream = GXF_UNWRAP_OR_RETURN(stream_->stream()); GXF_LOG_VERBOSE("Registering callback for cuda buffer"); cudaError_t cuda_result = cudaLaunchHostFunc(stream, func, data); CHECK_CUDA_ERROR(cuda_result, "Unable to register host function using cudaLaunchHostFunc"); return Success; } private: // State of the buffer std::atomic state_{State::UNSET}; // Flag to keep track of shared ownership of the cuda stream std::atomic stream_owner_{true}; // cuda host callback function on completion of all the queued work release_function_t release_func_ = nullptr; // CudaStream used to allocate memory for the cuda buffer Handle stream_ = Handle::Null(); // CudaStreamPool used to allocate the CudaStream used by the buffer Handle stream_pool_ = Handle::Null(); }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_CUDA_BUFFER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_common.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_CUDA_COMMON_HPP_ #define NVIDIA_GXF_CUDA_CUDA_COMMON_HPP_ #include #include "common/assert.hpp" #include "common/logger.hpp" #define CHECK_CUDA_ERROR(cu_result, fmt, ...) \ do { \ cudaError_t err = (cu_result); \ if (err != cudaSuccess) { \ GXF_LOG_ERROR(fmt ", cuda_error: %s, error_str: %s", ##__VA_ARGS__, \ cudaGetErrorName(err), cudaGetErrorString(err)); \ return Unexpected{GXF_FAILURE}; \ } \ } while (0) #define CHECK_CUDA_ERROR_RESULT(cu_result, fmt, ...) \ do { \ cudaError_t err = (cu_result); \ if (err != cudaSuccess) { \ GXF_LOG_ERROR(fmt ", cuda_error: %s, error_str: %s", ##__VA_ARGS__, \ cudaGetErrorName(err), cudaGetErrorString(err)); \ return GXF_FAILURE; \ } \ } while (0) #define CONTINUE_CUDA_ERROR(cu_result, fmt, ...) \ do { \ cudaError_t err = (cu_result); \ if (err != cudaSuccess) { \ GXF_LOG_ERROR(fmt ", cuda_error: %s, error_str: %s", ##__VA_ARGS__, \ cudaGetErrorName(err), cudaGetErrorString(err)); \ } \ } while (0) #endif // NVIDIA_GXF_CUDA_CUDA_COMMON_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_event.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_CUDA_EVENT_HPP_ #define NVIDIA_GXF_CUDA_CUDA_EVENT_HPP_ #include #include #include #include "gxf/core/component.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/handle.hpp" namespace nvidia { namespace gxf { class CudaStream; /** * @brief Holds and provides access to cudaEvent_t. The event could be set via initWithEvent() or * via created by init(flags, dev_id). */ class CudaEvent { public: CudaEvent() = default; ~CudaEvent(); CudaEvent(const CudaEvent&) = delete; void operator=(const CudaEvent&) = delete; CudaEvent(CudaEvent&& other) { resetInternal(); dev_id_ = other.dev_id_; other.dev_id_ = -1; event_ = std::move(other.event_); } void operator=(CudaEvent&& other) { resetInternal(); dev_id_ = other.dev_id_; other.dev_id_ = -1; event_ = std::move(other.event_); } friend class CudaStream; using EventDestroy = std::function; // Initialize an external event that shall be used Expected initWithEvent(cudaEvent_t event, int dev_id = -1, EventDestroy free_fnc = nullptr); // Initialize a new event internally Expected init(uint32_t flags = 0, int dev_id = -1); // Deinitialize cudaevent. In case that user does not called it explicitly, // cuda event could be freed in destructor. Expected deinit(); // Retrieves cuda event Expected event() const; // Get device id which owns this stream int dev_id() const { return dev_id_; } private: template using PtrT = std::unique_ptr>; using EventPtr = PtrT; void resetInternal(); static Expected createEventInternal(uint32_t flags, int gpuid); static Expected createEventInternal( cudaEvent_t event, EventDestroy free_event); int32_t dev_id_ = -1; EventPtr event_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_CUDA_EVENT_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_scheduling_terms.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_CUDA_SCHEDULING_TERMS_HPP_ #define NVIDIA_GXF_CUDA_CUDA_SCHEDULING_TERMS_HPP_ #include #include #include #include #include #include #include #include "gxf/core/parameter_registrar.hpp" #include "gxf/cuda/cuda_common.hpp" #include "gxf/cuda/cuda_event.hpp" #include "gxf/cuda/cuda_stream_id.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/scheduling_term.hpp" namespace nvidia { namespace gxf { /** * @brief Scheduling term to monitor activity on a cuda stream * * A component which specifies the availability of data at the receiver on completion of * the work on the provided cuda stream with the help of callback function to host. * This scheduling term will register a call back function which will be called once the work on the * specified cuda stream completes indicating that the data is available for consumption */ class CudaStreamSchedulingTerm : public SchedulingTerm { public: // state of the scheduling term enum class State : int8_t { UNSET = 0, // Initial state not waiting for any cuda host callback CALLBACK_REGISTERED, // Indicates a call back function is registered DATA_AVAILABLE, // Indicates data is ready to be consumed }; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; gxf_result_t update_state_abi(int64_t timestamp) override; private: // Receiver to monitor cuda stream activity Parameter> receiver_; // The current state of the scheduling term SchedulingConditionType current_state_; // Current message entity being monitored std::atomic message_eid_ = kNullUid; // State of the scheduling term std::atomic state_{State::UNSET}; // cuda host callback function on completion of all the queued work static void CUDART_CB cudaHostCallback(void* term_ptr); }; /** * @brief Scheduling term based on cuda event * * A component which specifies the availability of data at the receiver on completion of the * work on the provided cuda stream with the help of cuda event. * This scheduling term will keep polling on the event provided to check for data availability for * consumption. */ class CudaEventSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; gxf_result_t update_state_abi(int64_t timestamp) override; private: Parameter> receiver_; Parameter event_name_{}; SchedulingConditionType current_state_; // The current state of the scheduling term int64_t last_state_change_; // timestamp when the state changed the last time }; /** * @brief Scheduling term based on data availability in a cuda buffer * * A component which specifies the availability of data at the receiver based on * the cuda buffers present in incoming messages. */ class CudaBufferAvailableSchedulingTerm : public SchedulingTerm { public: // state of the scheduling term enum class State : int8_t { UNSET = 0, // Initial state not waiting for any cuda host callback CALLBACK_REGISTERED, // Indicates a call back function is registered DATA_AVAILABLE, // Indicates data is ready to be consumed }; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; gxf_result_t update_state_abi(int64_t timestamp) override; private: // Receiver to monitor cuda stream activity Parameter> receiver_; // The current state of the scheduling term SchedulingConditionType current_state_; // Current message entity being monitored std::atomic message_eid_ = kNullUid; // State of the scheduling term std::atomic state_{State::UNSET}; // timestamp when the state changed the last time int64_t last_state_change_; // cuda host callback function on completion of all the queued work static void CUDART_CB cudaHostCallback(void* term_ptr); }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_CUDA_SCHEDULING_TERMS_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_stream.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_CUDA_STREAM_HPP_ #define NVIDIA_GXF_CUDA_CUDA_STREAM_HPP_ #include "cuda.h" #include #include #include #include #include #include #include "gxf/core/component.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/handle.hpp" #include "gxf/cuda/cuda_event.hpp" namespace nvidia { namespace gxf { /** * @brief Holds and provides access to cudaStream_t. CudaStream is allocated and * recycled by CudaStreamPool */ class CudaStream { public: CudaStream() = default; ~CudaStream(); CudaStream(const CudaStream&) = delete; CudaStream(CudaStream&&) = delete; void operator=(const CudaStream&) = delete; using EventDestroy = std::function; using SyncedCallback = std::function; // Retrieves cudaSteam_t Expected stream() const; // Get device id which owns this stream int dev_id() const { return dev_id_; } // Record event to extend Entity life until event synchronized. Expected record(Handle event, Entity input_entity, SyncedCallback synced_cb = nullptr); // Record event on the stream for an async callback. // The callback would be delayed until CudaStreamSync ticks. // The Callback usually is used to recycle dependent resources. // If record failed, callback would not be called. User need to check return results. Expected record(cudaEvent_t event, EventDestroy cb); // Reset all events and callback all the hook functions to release resource. Expected resetEvents(); // Sync all streams, meanwhile clean all recorded events and callback recycle functions Expected syncStream(); private: friend class CudaStreamPool; // Initialize new cuda stream if was not set by external Expected initialize(const std::string& nvtxIdentifier, uint32_t flags = 0, int dev_id = -1, int32_t priority = 0, CUgreenCtx green_ctx = nullptr); Expected deinitialize(); Expected prepareResourceInternal(int dev_id); Expected recordEventInternal(cudaEvent_t e); Expected syncEventInternal(cudaEvent_t e); Expected resetEventsInternal(std::queue& q); gxf_result_t loadDriverFunctions(); mutable std::shared_timed_mutex mutex_; int dev_id_ = 0; cudaStream_t stream_ = 0; // store all recorded event with destroy functions. std::queue recorded_event_queue_; // event is defined for for synchronization of stream CudaEvent::EventPtr sync_event_; // Function to create green context stream CUresult (*fnCuGreenCtxStreamCreate)(CUstream*, CUgreenCtx, unsigned int, int32_t) = nullptr; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_CUDA_STREAM_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_stream_id.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_CUDA_STREAM_ID_HPP_ #define NVIDIA_GXF_CUDA_CUDA_STREAM_ID_HPP_ #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { /** * @brief The Structure indicates cuda stream component ID. * * Message entity carrying CudaStreamId indicates that Tensors will be or * has been processed by corresponding cuda stream. The handle could * be deduced by Handle::Create(context, stream_cid). */ struct CudaStreamId { // component id of CudaStream gxf_uid_t stream_cid; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_CUDA_STREAM_ID_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_stream_pool.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_CUDA_STREAM_POOL_HPP_ #define NVIDIA_GXF_CUDA_CUDA_STREAM_POOL_HPP_ #include #include #include #include #include #include #include #include #include "gxf/core/component.hpp" #include "gxf/core/expected.hpp" #include "gxf/cuda/cuda_stream.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/cuda_green_context.hpp" #include "gxf/std/resources.hpp" namespace nvidia { namespace gxf { /** * @brief A stream pool containing a specified number of CUDA streams on a single device. */ class CudaStreamPool : public Allocator { public: CudaStreamPool() = default; ~CudaStreamPool(); gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t is_available_abi(uint64_t size) override; gxf_result_t allocate_abi(uint64_t size, int32_t type, void** pointer) override; gxf_result_t free_abi(void* pointer) override; gxf_result_t deinitialize() override; // Allocate a cudastream for other components Expected> allocateStream(); // Free a cudastream Expected releaseStream(Handle stream); private: Expected createNewStreamEntity(const std::string& nvtx_identifier); Expected reserveStreams(); Resource> gpu_device_; Parameter stream_flags_; Parameter stream_priority_; Parameter reserved_size_; Parameter max_size_; Parameter nvtx_identifier_; Parameter> cuda_green_context_; std::mutex mutex_; // map of std::unordered_map> streams_; std::queue reserved_streams_; CUgreenCtx green_ctx_ = nullptr; std::atomic stage_{AllocatorStage::kUninitialized}; int32_t dev_id_ = -1; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_CUDA_STREAM_POOL_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/cuda_stream_sync.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_CUDA_STREAM_SYNC_HPP_ #define NVIDIA_GXF_CUDA_CUDA_STREAM_SYNC_HPP_ #include #include "gxf/cuda/cuda_stream.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { /** * @brief Get all cuda streams from messages of receiver, synchronize these streams, * and forward messages to transmitter. */ class CudaStreamSync : public Codelet { public: virtual ~CudaStreamSync() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t tick() override; private: Parameter> rx_; Parameter> tx_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_CUDA_STREAM_SYNC_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/stream_ordered_allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STREAM_ORDERED_ALLOCATOR_HPP_ #define NVIDIA_GXF_STREAM_ORDERED_ALLOCATOR_HPP_ #include #include #include #include #include #include "common/assert.hpp" #include "common/logger.hpp" #include "gxf/core/parameter.hpp" #include "gxf/cuda/cuda_allocator.hpp" #include "gxf/std/resources.hpp" namespace nvidia { namespace gxf { /** * @brief An allocator which allocates and frees device memory using a CUDA memory pool. * * It uses CUDA's Stream Ordered Memory Allocator (cudaMallocFromPoolAsync/cudaFreeAsync). * For synchronous allocate and free, it uses its own internally created CUDA stream. * For asynchronous allocate and free, the user provided stream is used. */ class StreamOrderedAllocator : public CudaAllocator { public: StreamOrderedAllocator() = default; ~StreamOrderedAllocator() = default; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t is_available_abi(uint64_t size) override; gxf_result_t allocate_abi(uint64_t size, int32_t storage_type, void** pointer) override; gxf_result_t allocate_async_abi(uint64_t size, void** pointer, cudaStream_t stream) override; gxf_result_t free_async_abi(void* pointer, cudaStream_t stream) override; gxf_result_t free_abi(void* pointer) override; Expected get_pool_size(MemoryStorageType type) const override; private: Resource> gpu_device_; Parameter release_threshold_; Parameter device_memory_initial_size_; Parameter device_memory_max_size_; mutable std::shared_mutex shared_mutex_; std::unordered_map pool_map_; AllocatorStage stage_{AllocatorStage::kUninitialized}; cudaStream_t stream_; cudaMemPool_t memory_pool_; cudaMemPoolProps pool_props_ = {}; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STREAM_ORDERED_ALLOCATOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/tests/convolution.h ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_TESTS_CONVOLUTION_HPP #define NVIDIA_GXF_CUDA_TESTS_CONVOLUTION_HPP #include #define THREADS_PER_BLOCK 32 #define THREADS_PER_BLOCK_1 (THREADS_PER_BLOCK - 1) // A simple GPU based 2d convolution operation extern "C" void convolveKernel(float *input, float *kernel, float *output, int width, int height, int kernelSize, cudaStream_t stream); #endif // NVIDIA_GXF_CUDA_TESTS_CONVOLUTION_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/tests/green_context_with_smid.h ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_TESTS_GREEN_CONTEXT_WITH_SMID_HPP #define NVIDIA_GXF_CUDA_TESTS_GREEN_CONTEXT_WITH_SMID_HPP #include #include #include #include #define THREADS_PER_BLOCK 32 #define THREADS_PER_BLOCK_1 (THREADS_PER_BLOCK - 1) // Structure to hold thread information including SMID struct SmidThreadInfo { int thread_id; // Global thread index int block_id; // Block index int thread_in_block; // Thread index within block uint32_t smid; // Streaming Multiprocessor ID int block_dim_x; // Block dimension x int grid_dim_x; // Grid dimension x }; // CUDA kernel function declarations extern "C" { // Main function to test SMID for every thread void test_every_thread_smid(int num_blocks, int threads_per_block, cudaStream_t stream, SmidThreadInfo* h_thread_info); // Function to analyze SMID results int32_t analyze_smid_results(std::vector ptr_thread_info, int threads_per_block, int num_blocks, int num_streams); // Function to test SMID with different configurations int32_t test_smid_with_different_configurations(cudaStream_t* streams, int num_streams); // Function to collect SM IDs from a single kernel launch int32_t collect_smid_from_kernel(int num_blocks, int threads_per_block, cudaStream_t stream, std::set& unique_smids); } #endif // NVIDIA_GXF_CUDA_TESTS_GREEN_CONTEXT_WITH_SMID_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/cuda/tests/test_cuda_helper.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CUDA_TESTS_TEST_CUDA_HELPER_HPP #define NVIDIA_GXF_CUDA_TESTS_TEST_CUDA_HELPER_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include "convolution.h" #include "green_context_with_smid.h" #include "common/assert.hpp" #include "gxf/cuda/cuda_buffer.hpp" #include "gxf/cuda/cuda_common.hpp" #include "gxf/cuda/cuda_event.hpp" #include "gxf/cuda/cuda_stream.hpp" #include "gxf/cuda/cuda_stream_id.hpp" #include "gxf/cuda/cuda_stream_pool.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/tensor.hpp" #include "gxf/std/transmitter.hpp" #define CHECK_CUBLUS_ERROR(cu_result, fmt, ...) \ do { \ cublasStatus_t err = (cu_result); \ if (err != CUBLAS_STATUS_SUCCESS) { \ GXF_LOG_ERROR(fmt ", cublas_error: %d", ##__VA_ARGS__, (int)err); \ return Unexpected{GXF_FAILURE}; \ } \ } while (0) namespace nvidia { namespace gxf { namespace test { namespace cuda { constexpr static const char* kStreamName0 = "CudaStream0"; constexpr static int kDefaultDevId = 0; static const Shape kInitTensorShape{1024, 2048}; // The base class with cuda stream utils class StreamBasedOps : public Codelet { public: static Expected> getStream(Entity& message) { auto stream_id = message.get(); GXF_ASSERT(stream_id, "failed to find cudastreamid"); auto stream = Handle::Create(stream_id.value().context(), stream_id.value()->stream_cid); GXF_ASSERT(stream, "create cudastream from cid failed"); GXF_ASSERT(stream.value(), "cudastream handle is null"); return stream; } static Expected addStream(Entity& message, Handle& stream, const char* name = nullptr) { auto stream_id = message.add(name); GXF_ASSERT(stream_id, "failed to add cudastreamid"); stream_id.value()->stream_cid = stream.cid(); GXF_ASSERT(stream_id.value()->stream_cid != kNullUid, "stream_cid is null"); return Success; } static Expected> addTensor(Entity& message, Handle pool, const TensorDescription& description) { GXF_ASSERT(pool, "pool is not set"); auto tensor = message.add(description.name.c_str()); GXF_ASSERT(tensor, "failed to add message tensor"); const uint64_t bytes_per_element = description.element_type == PrimitiveType::kCustom ? description.bytes_per_element : PrimitiveTypeSize(description.element_type); auto result = tensor.value()->reshapeCustom(description.shape, description.element_type, bytes_per_element, description.strides, description.storage_type, pool); GXF_ASSERT(result, "reshape tensor:%s failed", description.name.c_str()); return tensor; } Expected> addNewEvent(Entity& message, const char* name = nullptr) const { GXF_ASSERT(opsEvent(), "cuda stream ops event is not initialized"); auto mabe_event = message.add(name); GXF_ASSERT(mabe_event, "failed to add cudaevent"); auto& event = mabe_event.value(); auto ret = event->initWithEvent(ops_event_->event().value(), ops_event_->dev_id()); GXF_ASSERT(ret, "failed to init with event into message"); GXF_ASSERT(event->event(), "stream_cid is null"); return mabe_event; } Expected initOpsEvent() { if (ops_event_) { return Success; } auto ops_event_entity = Entity::New(context()); GXF_ASSERT(ops_event_entity, "New event entity failed"); ops_event_holder_ = ops_event_entity.value(); auto maybe_event = ops_event_holder_.add("ops_event"); GXF_ASSERT(maybe_event, "failed to init ops cudaevent"); ops_event_ = maybe_event.value(); auto ret = ops_event_->init(0, kDefaultDevId); if (!ret) { GXF_LOG_ERROR("failed to init Ops event"); return ForwardError(ret); } return ret; } const Handle& opsEvent() const { return ops_event_; } private: Handle ops_event_; Entity ops_event_holder_; }; // Generate cuda tensor map with cudastreams for transmitter cuda_tx, // Generate host tensor map for transmitter host_tx class StreamTensorGenerator : public StreamBasedOps { public: gxf_result_t initialize() override { GXF_ASSERT(stream_pool_.get(), "stream pool is not set"); auto stream = stream_pool_->allocateStream(); GXF_ASSERT(stream, "allocating stream failed"); stream_ = std::move(stream.value()); GXF_ASSERT(stream_->stream(), "allocated stream is not initialized."); return GXF_SUCCESS; } gxf_result_t deinitialize() override { auto result = stream_pool_->releaseStream(stream_); return ToResultCode(result); } gxf_result_t tick() override { Expected maybe_dev_msg = Entity::New(context()); GXF_ASSERT(maybe_dev_msg, "New dev message failed"); auto& dev_msg = maybe_dev_msg.value(); Expected maybe_host_msg = Entity::New(context()); GXF_ASSERT(maybe_host_msg, "New host message failed"); auto& host_msg = maybe_host_msg.value(); auto ret = createTensors(dev_msg, host_msg); GXF_ASSERT(ret, "creating tensors failed"); GXF_ASSERT(stream_, "stream is not allocated"); ret = addStream(dev_msg, stream_, kStreamName0); GXF_ASSERT(ret, "stream tensor generator adding stream failed"); ret = cuda_tx_->publish(dev_msg); if (!ret) { GXF_LOG_ERROR("stream tensor generator publishing cuda tensors failed"); return ToResultCode(ret); } if (host_tx_.get()) { ret = host_tx_->publish(host_msg); if (!ret) { GXF_LOG_ERROR("stream tensor generator publishing cuda tensors failed"); return ToResultCode(ret); } } return GXF_SUCCESS; } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(cuda_tx_, "cuda_tx", "transmitter of cuda tensors", ""); result &= registrar->parameter(host_tx_, "host_tx", "transmitter of host tensors", "", Handle()); result &= registrar->parameter(cuda_tensor_pool_, "cuda_tensor_pool", "Cuda Tensor Pool", ""); result &= registrar->parameter(host_tensor_pool_, "host_tensor_pool", "Host Tensor Pool", ""); result &= registrar->parameter(stream_pool_, "stream_pool", "Cuda Stream Pool", ""); return ToResultCode(result); } private: Expected createTensors(Entity& dev_msg, Entity& host_msg) { Shape shape = kInitTensorShape; for (size_t i = 0; i < 2; ++i) { TensorDescription dev_desc{"cuda_tensor", MemoryStorageType::kDevice, shape, PrimitiveType::kFloat32}; auto cuda_tensor_ret = addTensor(dev_msg, cuda_tensor_pool_, dev_desc); GXF_ASSERT(cuda_tensor_ret, "Generator dev message adding tensor failed."); auto& cuda_tensor = cuda_tensor_ret.value(); Expected cuda_data = cuda_tensor->data(); if (!cuda_data) { return ForwardError(cuda_data); } TensorDescription host_desc{"host_tensor", MemoryStorageType::kHost, shape, PrimitiveType::kFloat32}; auto host_tensor_ret = addTensor(host_msg, host_tensor_pool_, host_desc); GXF_ASSERT(host_tensor_ret, "Generator host message adding tensor failed."); auto& host_tensor = host_tensor_ret.value(); Expected host_data = host_tensor->data(); if (!host_data) { return ForwardError(host_data); } for (size_t j = 0; j < shape.size(); ++j) { host_data.value()[j] = (j % 100) + 1.0f; } cudaError_t error = cudaMemcpy(cuda_data.value(), host_data.value(), cuda_tensor->size(), cudaMemcpyHostToDevice); CHECK_CUDA_ERROR(error, "StreamTensorGenerator cuda memory cpy H2D failed."); } return Success; } Parameter> cuda_tx_; Parameter> host_tx_; Parameter> cuda_tensor_pool_; Parameter> host_tensor_pool_; Parameter> stream_pool_; Handle stream_; }; // Dot product execution base class class DotProductExe { private: Handle rx_; Handle tx_; Handle tensor_pool_; public: DotProductExe() = default; virtual ~DotProductExe() = default; void setEnv(const Handle& rx, const Handle& tx, const Handle& pool) { rx_ = rx; tx_ = tx; tensor_pool_ = pool; } virtual Expected dotproduct_i(float* in0, float* in1, float* out, int32_t row, int32_t column, Entity& in_msg, Entity& out_msg) = 0; Expected execute(const char* out_tensor_name = "") { GXF_ASSERT(rx_ && tx_ && tensor_pool_, "dotproduct received empty in_msg"); Expected in_msg = rx_->receive(); GXF_ASSERT(in_msg, "dotproduct received empty in_msg"); // get tensors auto in_tensors = in_msg->findAll(); GXF_ASSERT(in_tensors, "failed to find Tensors in in_msg"); GXF_ASSERT(in_tensors->size() == 2, "doesn't find Tensors in in_msg"); GXF_ASSERT(in_tensors->at(0).value()->rank() == 2, "Input tensor rank is not 2"); int32_t column = in_tensors->at(0).value()->shape().dimension(1); int32_t row = in_tensors->at(0).value()->shape().dimension(0); MemoryStorageType mem_type = in_tensors->at(0).value()->storage_type(); PrimitiveType data_type = in_tensors->at(0).value()->element_type(); float* in_data[2] = {nullptr}; for (size_t i = 0; i < in_tensors->size(); ++i) { GXF_ASSERT(in_tensors->at(i).value(), "Input Tensor Handle is empty"); GXF_ASSERT(in_tensors->at(i).value()->rank() == 2, "Input tensor rank is not 2"); in_data[i] = ValuePointer(in_tensors->at(i).value()->pointer()); } Expected output = Entity::New(in_msg->context()); GXF_ASSERT(output, "Creating dotproduct output tensor failed."); Shape out_shape{row}; GXF_ASSERT(out_shape.rank() == 1 && out_shape.size() == static_cast(row), "output_shape is not correct"); TensorDescription outDesc{out_tensor_name, mem_type, out_shape, data_type}; auto out_tensor = StreamBasedOps::addTensor(output.value(), tensor_pool_, outDesc); GXF_ASSERT(out_tensor && out_tensor.value(), "cuda dotproduct output tensor is not found"); float* out_data = ValuePointer(out_tensor.value()->pointer()); auto ret = dotproduct_i(in_data[0], in_data[1], out_data, row, column, in_msg.value(), output.value()); GXF_ASSERT(ret, "dotproduct execute with implementation failed"); ret = tx_->publish(output.value()); GXF_ASSERT(ret, "dotproduct publishing tensors failed"); return ret; } }; // Cublas Dot product Operators class CublasDotProduct : public StreamBasedOps { public: // Culblas dot production execution class class CublasDotProductExe : public DotProductExe { private: cublasHandle_t handle_ = nullptr; CublasDotProduct* codelet_ = nullptr; public: CublasDotProductExe(CublasDotProduct* codelet) : codelet_(codelet) {} ~CublasDotProductExe() { if (handle_) { cublasDestroy(handle_); } } Expected dotproduct_i(float* in0, float* in1, float* out, int32_t row, int32_t column, Entity& in_msg, Entity& out_msg) override { // locate stream auto maybe_stream = StreamBasedOps::getStream(in_msg); GXF_ASSERT(maybe_stream && maybe_stream.value(), "get stream from in_msg failed"); auto& stream = maybe_stream.value(); auto ret = StreamBasedOps::addStream(out_msg, stream); GXF_ASSERT(ret, "adding cudastream into dotproduct output message failed."); int gpu_id = stream->dev_id(); if (gpu_id >= 0) { CHECK_CUDA_ERROR(cudaSetDevice(gpu_id), "failed to set deviceid: %d", gpu_id); } if (!handle_) { CHECK_CUBLUS_ERROR(cublasCreate(&handle_), "failed to create cublas handle"); } auto custream_id = stream->stream(); GXF_ASSERT(custream_id, "cudastream id is invalid"); CHECK_CUBLUS_ERROR(cublasSetStream(handle_, custream_id.value()), "cublas set stream failed"); for (int i = 0; i < row; ++i) { CHECK_CUBLUS_ERROR( cublasSdot(handle_, column, in0 + column * i, 1, in1 + column * i, 1, out + i), "cublasSdot failed on row :%d", i); } auto maybe_event = codelet_->addNewEvent(out_msg, "cudotproduct_event"); GXF_ASSERT(maybe_event, "failed to add cublas dot product event"); // Recording this event here causes a leak // ret = stream->record(maybe_event.value(), in_msg, // []() { GXF_LOG_ERROR("cublas dotproduct event synced"); }); // GXF_ASSERT(ret, "cublas dotproduct record event failed"); return ret; } }; CublasDotProduct() : exec_(this) {} gxf_result_t initialize() override { GXF_ASSERT(tensor_pool_.get() && rx_.get() && tx_.get(), "params not set"); exec_.setEnv(rx_.get(), tx_.get(), tensor_pool_.get()); return GXF_SUCCESS; } gxf_result_t start() override { return ToResultCode(initOpsEvent()); } gxf_result_t tick() override { auto ret = exec_.execute("cublasdotproduct_tensor"); return ToResultCode(ret); } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(tx_, "tx", "transmitter of tensors", ""); result &= registrar->parameter(rx_, "rx", "receiver of tensors", ""); result &= registrar->parameter(tensor_pool_, "tensor_pool", "Tensor Pool", ""); return ToResultCode(result); } private: Parameter> tx_; Parameter> rx_; Parameter> tensor_pool_; CublasDotProductExe exec_; }; // CPU Dot product Operators class HostDotProduct : public Codelet { public: // CPU dot production execution class class HostDotProductExe : public DotProductExe { public: HostDotProductExe() = default; ~HostDotProductExe() = default; Expected dotproduct_i(float* in0, float* in1, float* out, int32_t row, int32_t column, Entity& in_msg, Entity& out_msg) override { for (int i = 0; i < row; ++i) { float sum = 0.0; float* x = in0 + column * i; float* y = in1 + column * i; for (int j = 0; j < column; ++j) { sum += x[j] * y[j]; } out[i] = sum; } return Success; } }; gxf_result_t initialize() override { GXF_ASSERT(tensor_pool_.get() && rx_.get() && tx_.get(), "params not set"); exec_.setEnv(rx_.get(), tx_.get(), tensor_pool_.get()); return GXF_SUCCESS; } gxf_result_t tick() override { auto ret = exec_.execute("host_dotproduct_tensor"); return ToResultCode(ret); } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(tx_, "tx", "transmitter of tensors", ""); result &= registrar->parameter(rx_, "rx", "receiver of tensors", ""); result &= registrar->parameter(tensor_pool_, "tensor_pool", "Tensor Pool", ""); return ToResultCode(result); } private: Parameter> tx_; Parameter> rx_; Parameter> tensor_pool_; HostDotProductExe exec_; }; // Stream based Memory copy from device to host class MemCpy2Host : public StreamBasedOps { public: gxf_result_t start() override { return ToResultCode(initOpsEvent()); } gxf_result_t tick() override { auto in = rx_->receive(); GXF_ASSERT(in, "rx received empty message"); auto maybe_tensor = in.value().get(); GXF_ASSERT(maybe_tensor, "tensor not found"); auto& in_tensor = maybe_tensor.value(); byte* in_data = in_tensor->pointer(); Expected out_msg = Entity::New(context()); TensorDescription out_desc{in_tensor.name(), MemoryStorageType::kHost, in_tensor->shape(), in_tensor->element_type()}; auto maybe_out_tensor = addTensor(out_msg.value(), tensor_pool_, out_desc); GXF_ASSERT(maybe_out_tensor, "Memcpy host message adding tensor failed."); auto& out_tensor = maybe_out_tensor.value(); byte* out_data = out_tensor->pointer(); auto maybe_stream = getStream(in.value()); GXF_ASSERT(maybe_stream && maybe_stream.value(), "get stream from in failed"); auto& stream = maybe_stream.value(); auto ret = addStream(out_msg.value(), stream); GXF_ASSERT(ret, "adding cudastream into memcpy output message failed."); // wrap cuda operations since CHECK_CUDA_ERROR return Expected ret = [&, this]() -> Expected { int gpu_id = stream->dev_id(); if (gpu_id >= 0) { CHECK_CUDA_ERROR(cudaSetDevice(gpu_id), "failed to set deviceid: %d", gpu_id); } cudaError_t error = cudaMemcpyAsync(out_data, in_data, in_tensor->size(), cudaMemcpyDeviceToHost, stream->stream().value()); CHECK_CUDA_ERROR(error, "CUDA memory cpy to host failed."); return Success; }(); GXF_ASSERT(ret, "CUDA memory cpy to host failed."); auto maybe_event = addNewEvent(out_msg.value(), "memcpy_event"); GXF_ASSERT(maybe_event, "failed to add memcpy_event"); // Recording this event here causes a leak // ret = stream->record(maybe_event.value(), in.value(), // []() { GXF_LOG_ERROR("memcpy_to_host event synced"); }); // GXF_ASSERT(ret, "memcpy_to_host record event failed"); ret = tx_->publish(out_msg.value()); GXF_ASSERT(ret, "memcpy_to_host publishing tensors failed"); return ToResultCode(ret); } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(tx_, "tx", "transmitter of tensors", ""); result &= registrar->parameter(rx_, "rx", "receiver of tensors", ""); result &= registrar->parameter(tensor_pool_, "tensor_pool", "Tensor output pool", ""); return ToResultCode(result); } private: Parameter> tx_; Parameter> rx_; Parameter> tensor_pool_; }; // Equal verification class VerifyEqual : public Codelet { public: gxf_result_t tick() override { GXF_LOG_DEBUG("verifying frame: %d", count_++); auto in0 = rx0_->receive(); GXF_ASSERT(in0, "rx0 received empty message"); auto in1 = rx1_->receive(); GXF_ASSERT(in1, "rx1 received empty message"); // get tensors auto maybe_tensor0 = in0.value().get(); GXF_ASSERT(maybe_tensor0, "tensor0 not found"); auto maybe_tensor1 = in1.value().get(); GXF_ASSERT(maybe_tensor1, "tensor1 not found"); auto& tensor0 = maybe_tensor0.value(); auto& tensor1 = maybe_tensor1.value(); GXF_ASSERT(std::string(tensor0.name()) != std::string(tensor1.name()), "2 tensor name should not same"); GXF_ASSERT(tensor0->shape() == tensor1->shape(), "2 tensors' shape not matched"); GXF_ASSERT(tensor0->element_type() == tensor1->element_type(), "2 tensor's element type not matched"); GXF_ASSERT(tensor0->storage_type() == tensor1->storage_type(), "2 tensor's storage_type not matched"); GXF_ASSERT(tensor0->storage_type() == MemoryStorageType::kHost, "very tensor storage_type is not from host"); float* data0 = tensor0->data().value(); float* data1 = tensor1->data().value(); uint64_t count = tensor0->element_count(); for (uint64_t i = 0; i < count; ++i) { // printf("i:%d, [%f], [%f]\n", static_cast(i), data0[i], data1[i]); GXF_ASSERT(fequal(data0[i], data1[i]), "data0[%d]: %f but data1: %f.", static_cast(i), data0[i], data1[i]); } return GXF_SUCCESS; } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(rx0_, "rx0", "receiver0 of tensors", ""); result &= registrar->parameter(rx1_, "rx1", "receiver1 of tensors", ""); return ToResultCode(result); } private: bool fequal(float a, float b) { if (fabs(a - b) <= std::numeric_limits::epsilon()) return true; return false; } Parameter> rx0_; Parameter> rx1_; int32_t count_ = 0; }; // Creates a CudaBuffer object on each iteration with memory allocated in an // asynchronous manner. Downstream receivers can either enqueue more work on to // CudaStream associated with the CudaBuffer or sync on the stream before accessing the memory class CudaAsyncBufferGenerator : public Codelet { public: virtual ~CudaAsyncBufferGenerator() = default; gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(signal_, "signal", "Signal", "Transmitter channel publishing messages to other graph entities"); result &= registrar->parameter(allocator_, "allocator", "Allocator", "A cuda allocator component that can serve device memory asynchronously"); result &= registrar->parameter(stream_pool_, "stream_pool", "StreamPool", "A cuda stream pool component"); result &= registrar->parameter(size_, "size", "Size", "Size of the CudaBuffer to be allocated", 1UL); return ToResultCode(result); } gxf_result_t tick() override { auto maybe_message = Entity::New(context()); if (!maybe_message) { GXF_LOG_ERROR("Failure creating message entity."); return maybe_message.error(); } auto message = maybe_message.value(); auto maybe_buffer = message.add(kDefaultCudaBufferName); if (!maybe_buffer) { GXF_LOG_ERROR("Failure creating cuda buffer"); return maybe_buffer.error(); } auto buffer = maybe_buffer.value(); auto code = buffer->resizeAsync(allocator_, stream_pool_, size_); auto min = std::numeric_limits::min(); auto max = std::numeric_limits::max(); std::uniform_real_distribution distribution(min, max); std::vector elements; auto element_count = size_ / sizeof(float); for (size_t idx = 0; idx < element_count; idx++) { elements.push_back(distribution(generator_)); } auto stream_component = buffer->stream(); auto stream = stream_component->stream().value(); const cudaError_t error = cudaMemcpyAsync(buffer->pointer(), elements.data(), size_, cudaMemcpyHostToDevice, stream); CHECK_CUDA_ERROR_RESULT(error, "cudaMemcpyAsync failed"); auto result = signal_->publish(message); GXF_LOG_INFO("Message Sent"); return GXF_SUCCESS; } private: Parameter> signal_; Parameter> allocator_; Parameter> stream_pool_; Parameter size_; std::default_random_engine generator_; }; // Performs a green context test with detection of different SMIDs class GreenContextWithSmid: public Codelet { public: virtual ~GreenContextWithSmid() = default; gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(stream_pools_, "stream_pools", "StreamPools", "A cuda stream pool component"); result &= registrar->parameter(num_stream_pools_, "num_stream_pools", "NumStreamPools", "Number of streams to allocate", 1); result &= registrar->parameter(input_, "input", "Input", "Receiver channel receiving messages from other graph entities"); return ToResultCode(result); } gxf_result_t start() override { cudaStream_t streams[10]; for (int i = 0; i < num_stream_pools_.get(); i++) { auto stream = stream_pools_.get()[i].value()->allocateStream(); streams_.push_back(stream.value()); streams[i] = stream.value()->stream().value(); } test_smid_with_different_configurations(&streams[0], num_stream_pools_.get()); return GXF_SUCCESS; } gxf_result_t stop() override { for (int i = 0; i < num_stream_pools_.get(); i++) { stream_pools_.get()[i].value()->releaseStream(streams_[i]); } return GXF_SUCCESS; } gxf_result_t tick() override { // This test is done in start() return GXF_SUCCESS; } private: Parameter, kMaxComponents> > stream_pools_; Parameter num_stream_pools_; Parameter> input_; std::vector> streams_; }; // Performs an async 2D convolution operation on // incoming CudaBuffer objects. class Convolve2D: public Codelet { public: virtual ~Convolve2D() = default; gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(kernel_, "kernel", "Kernel", "2d matrix of float values represented as a vector of vectors"); result &= registrar->parameter(output_, "output", "Output", "Transmitter channel publishing messages to other graph entities"); result &= registrar->parameter(input_, "input", "Input", "Receiver channel receiving messages from other graph entities"); result &= registrar->parameter(allocator_, "allocator", "Allocator", "A cuda allocator component that can serve device memory asynchronously"); return ToResultCode(result); } gxf_result_t start() override { auto& kernel = kernel_.get(); size_t kernel_size = kernel.size(); size_t index = 0; float kernel_flat_host[kernel_size * kernel_size]; // NOLINT for (const auto& k : kernel) { GXF_ASSERT_EQ(k.size(), kernel_size); for (const auto& value : k) { kernel_flat_host[index] = value; ++index; } } auto maybe_kernel = allocator_->allocate(kernel_size * kernel_size * sizeof(float), MemoryStorageType::kDevice); if (!maybe_kernel) { return maybe_kernel.error(); } kernel_flat_ = maybe_kernel.value(); const cudaError_t error = cudaMemcpy(kernel_flat_, kernel_flat_host, kernel_size * kernel_size * sizeof(float), cudaMemcpyHostToDevice); if (error != cudaSuccess) { GXF_LOG_ERROR("CUDA Mem copy Error: %s\n", cudaGetErrorString(error)); return GXF_FAILURE; } return GXF_SUCCESS; } gxf_result_t stop() override { entity_queue_map_.clear(); return ToResultCode(allocator_->free(kernel_flat_)); } gxf_result_t tick() override { return ToResultCode(_tick()); } // payload struct to access on the callback used to // dereference the underlying message entity typedef struct callBackData { Entity data; Convolve2D* ptr; } callBackData; static void CUDART_CB cudaEntityFreeCallback(void* data_ptr) { auto data = reinterpret_cast(data_ptr); auto convolve = data->ptr; GXF_LOG_VERBOSE("Received entity free callback from cuda stream for " "cuda buffer in message entity E[%05ld]", data->data.eid()); // Entities consumed until now cannot be freed just yet in the host callback function. // Host callback function gets executed from a cuda driver thread which cannot be used // to call another cuda runtime api like cudaFreeAsync. Hence keep track of the // entities to be freed the next time this codelet is executed. std::unique_lock lock(convolve->mutex_); convolve->entity_free_list_.push(data->data.eid()); } Expected _tick() { // Dequeue any previously consumed message entities { std::unique_lock lock(mutex_); while (!entity_free_list_.empty()) { auto element = entity_free_list_.front(); entity_queue_map_.erase(element); entity_free_list_.pop(); } } auto in_message = GXF_UNWRAP_OR_RETURN(input_->receive()); GXF_LOG_INFO("Message Received: %d", this->count_); this->count_ = this->count_ + 1; if (in_message.is_null()) { return Unexpected{GXF_CONTRACT_MESSAGE_NOT_AVAILABLE}; } auto in_buffer = GXF_UNWRAP_OR_RETURN(in_message.get()); auto out_message = GXF_UNWRAP_OR_RETURN(Entity::New(context())); auto out_buffer = GXF_UNWRAP_OR_RETURN(out_message.add(kDefaultCudaBufferName)); auto stream_pool = in_buffer->streamPool(); auto stream_handle = in_buffer->transferStreamOwnership(); auto code = out_buffer->resizeAsync(allocator_, stream_pool, in_buffer->size(), stream_handle); const int width = 32, height = 32; auto cu_stream = GXF_UNWRAP_OR_RETURN(stream_handle->stream()); convolveKernel(reinterpret_cast(in_buffer->pointer()), reinterpret_cast(kernel_flat_), reinterpret_cast(out_buffer->pointer()), width, height, kernel_.get().size(), cu_stream); cudaError_t err = cudaGetLastError(); if (err != cudaSuccess) { GXF_LOG_ERROR("CUDA convolveKernel Error: %s\n", cudaGetErrorString(err)); return Unexpected{GXF_FAILURE}; } // store the incoming message entity to prevent the cuda buffer getting released // before it is consumed. The in_message entity is only released once the kernel // has finished its execution auto eid = in_message.eid(); { std::unique_lock lock(mutex_); entity_queue_map_.insert({eid, callBackData{std::move(in_message), this}}); } auto it = entity_queue_map_.find(eid); GXF_RETURN_IF_ERROR(in_buffer->registerCallbackOnStream(cudaEntityFreeCallback, reinterpret_cast(&it->second))); auto stream_id = GXF_UNWRAP_OR_RETURN(out_message.add()); stream_id->stream_cid = stream_handle.cid(); return output_->publish(out_message); } private: Parameter> allocator_; Parameter>> kernel_; Parameter> output_; Parameter> input_; byte* kernel_flat_; std::unordered_map entity_queue_map_; std::queue entity_free_list_; std::shared_mutex mutex_; int count_ = 1; }; // Dequeue a message entity with a cuda buffer and ensures // the data is available class CudaBufferRx: public Codelet { public: virtual ~CudaBufferRx() = default; gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(signal_, "signal", "Signal", "Channel to receive messages from another graph entity"); return ToResultCode(result); } gxf_result_t tick() override { auto maybe_message = signal_->receive(); GXF_LOG_INFO("Message Received: %d", this->count); this->count = this->count + 1; if (!maybe_message || maybe_message.value().is_null()) { return GXF_CONTRACT_MESSAGE_NOT_AVAILABLE; } auto message = maybe_message.value(); auto maybe_cuda_buffer = message.get(); if (!maybe_cuda_buffer) { return ToResultCode(maybe_cuda_buffer); } auto cuda_buffer = maybe_cuda_buffer.value(); auto state = cuda_buffer->state(); if (state != CudaBuffer::State::DATA_AVAILABLE) { GXF_LOG_ERROR("CudaBuffer found in an invalid state %d", static_cast(state)); return GXF_FAILURE; } return GXF_SUCCESS; } private: Parameter> signal_; int count = 1; }; // Tracks unique SM IDs used during CUDA kernel executions and validates SM count class CudaSMCount : public Codelet { public: gxf_result_t initialize() override { unique_smids_.clear(); return GXF_SUCCESS; } gxf_result_t tick() override { std::lock_guard lock(smids_mutex_); // Default kernel configuration int num_blocks = 64; int threads_per_block = 1024; int32_t result = 0; // Check if we have a stream pool const auto maybe_stream_pool = stream_pool_.try_get(); if (maybe_stream_pool) { // Allocate a stream from the pool auto stream = maybe_stream_pool.value()->allocateStream(); if (!stream) { GXF_LOG_ERROR("Failed to allocate stream from pool"); return GXF_FAILURE; } // Launch kernel with stream result = collect_smid_from_kernel(num_blocks, threads_per_block, stream.value()->stream().value(), unique_smids_); // Release the stream back to the pool auto release_result = maybe_stream_pool.value()->releaseStream(stream.value()); if (!release_result) { GXF_LOG_ERROR("Failed to release stream back to pool"); return GXF_FAILURE; } } else { // Launch kernel without stream result = collect_smid_from_kernel(num_blocks, threads_per_block, nullptr, unique_smids_); } if (result != 0) { GXF_LOG_ERROR("Failed to collect SM IDs from kernel"); return GXF_FAILURE; } return GXF_SUCCESS; } gxf_result_t deinitialize() override { std::lock_guard lock(smids_mutex_); if (unique_smids_.size() > max_smid_count_.get()) { GXF_LOG_ERROR("SM count check failed: used %zu SMs, expected no more than %zu", unique_smids_.size(), max_smid_count_.get()); return GXF_FAILURE; } return GXF_SUCCESS; } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter( max_smid_count_, "max_smid_count", "Maximum number of SMs", "Maximum number of unique SMs expected to be used by CUDA kernels", 1UL); result &= registrar->parameter(stream_pool_, "stream_pool", "Cuda Stream Pool", "Optional CUDA stream pool for kernel execution", Registrar::NoDefaultParameter(), GXF_PARAMETER_FLAGS_OPTIONAL); return ToResultCode(result); } private: Parameter max_smid_count_; Parameter> stream_pool_; std::set unique_smids_; mutable std::mutex smids_mutex_; }; } // namespace cuda } // namespace test } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_CUDA_TESTS_TEST_CUDA_HELPER_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/logger/gxf_logger.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef COMMON_LOGGER_GXF_LOGGER_HPP #define COMMON_LOGGER_GXF_LOGGER_HPP #include #include #include "gxf/logger/logger.hpp" namespace nvidia { // Environment variable for log level override constexpr const char* kGxfLogEnvName = "GXF_LOG_LEVEL"; // Indicates the level of severity for a log message enum class Severity { // A utility case which can be used for 'SetSeverity' to disable all severity levels. NONE = -2, // A utility case which can be used for 'Redirect' and 'SetSeverity' ALL = -1, // The five different log severities in use from most severe to least severe. PANIC = 0, // Need to start at 0 ERROR, WARNING, INFO, DEBUG, VERBOSE, // A utility case representing the number of log levels used internally. COUNT }; // The output severity which might limit certain levels of severity struct SeverityContainer { Severity r = Severity::INFO; // Sets the default severity from the environment variable if it is set. SeverityContainer(); }; /// Namespace for the NVIDIA logger functionality. namespace logger { /// A logger that utilizes the GXF logging system. /// /// The GXF logger supports six log levels: /// PANIC(0), ERROR(1), WARNING(2), INFO(3), DEBUG(4), and VERBOSE(5). /// /// If no logger or log function is provided, a default logger implementation (DefaultGxfLogger) is /// used. The default logger leverages the existing functionality of the GXF logging system, which /// employs a global/singleton SeverityContainer to control the logging level, and a global /// `nvidia::LoggingFunction` to log messages. /// The initial logging level is determined by the environment variable `GXF_LOG_LEVEL` if it is /// set. Otherwise, the default logging level is INFO(3). class GxfLogger : public Logger { public: /// Constructs a logger with the provided logger or log function. /// /// If neither a logger nor a log function is provided, a default GXF logger will be instantiated. /// /// @param logger The logger to use (default: nullptr). /// @param func The log function to use (default: nullptr). explicit GxfLogger(const std::shared_ptr& logger = nullptr, const LogFunction& func = nullptr); }; /// A logger that facilitates access to the global GXF logger. /// /// The singleton GXF logger can be accessed via the instance() method. /// This class also provides a method to set the log severity from an environment variable. /// The log severity can be retrieved from the environment variable using GetSeverityFromEnv(). class GlobalGxfLogger { public: /// Retrieve the global/singleton GXF logger instance. static GxfLogger& instance(); /// Set the log severity based on the value of an environment variable. /// /// If the environment variable is not set or invalid, the severity remains unchanged. /// @param env_name The name of the environment variable to use. /// @return true if the environment variable is accessible and the severity was updated from it. static bool SetSeverityFromEnv(const char* env_name); /// Return the log severity based on the value of an environment variable. /// /// If the environment variable is not set or invalid, returns Severity::COUNT. /// If 'error_code' is not null, it will be set to 1 if the environment variable is set but /// invalid, or to 0 otherwise. /// /// @param env_name The name of the environment variable to use. /// @param error_code The error code to set if the environment variable is invalid. /// @return The log severity from the environment variable. static Severity GetSeverityFromEnv(const char* env_name, int* error_code); }; } // namespace logger } // namespace nvidia #endif /* COMMON_LOGGER_GXF_LOGGER_HPP */ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/logger/logger.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef COMMON_LOGGER_LOGGER_HPP #define COMMON_LOGGER_LOGGER_HPP #include #include #include #include #include #include namespace nvidia { /// Namespace for the NVIDIA logger functionality. namespace logger { using LogFunction = std::function; /// Interface for custom logger implementations. /// /// ILogger provides an interface for implementing custom logging mechanisms. /// This interface allows the integration of various logging systems with the Logger class. /// Users can define their own logging behavior by implementing these methods. class ILogger { public: /// Destructor for ILogger. virtual ~ILogger() = default; /// Log a message. /// /// This method logs a message based on the provided details such as file name, line number, /// function/module name, log level, message, and an optional argument. /// /// @param file The name of the source file where the log request originated. /// @param line The line number in the source file. /// @param name The name of the function/module making the log request. /// @param level The log level. /// @param message The log message. /// @param arg An optional argument for additional log information (default: nullptr). virtual void log(const char* file, int line, const char* name, int level, const char* message, void* arg = nullptr) = 0; /// Set the log message pattern. /// /// Set the pattern used for formatting log messages. /// /// @param pattern The pattern string for formatting log messages. virtual void pattern(const char* pattern) = 0; /// Get the current log message pattern. /// /// Retrieve the currently set pattern used for formatting log messages. /// /// @return The currently set pattern string. virtual const char* pattern() const = 0; /// Set the log level. /// /// Set the log level, determining the priority of messages that should be logged. /// /// @param level The log level. virtual void level(int level) = 0; /// Get the current log level. /// /// Retrieve the currently set log level. /// /// @return The currently set log level. virtual int level() const = 0; /// Redirect log output. /// /// Redirect log output to the specified file or other output for the given log level. /// /// @param level The log level for which output redirection is applied. /// @param output A pointer to the file or other output to redirect log output. virtual void redirect(int level, void* output) = 0; /// Get the current redirection for a specified log level. /// /// Retrieve the file/output pointer to which log output is currently being redirected for the /// specified log level. If no redirection is set for the given level, returns nullptr. /// /// @param level The log level for which the redirection is queried. /// @return A pointer to the file/output where log output is redirected, or nullptr if no /// redirection is set. virtual void* redirect(int level) const = 0; }; /// Logger class for logging messages. /// /// The Logger class provides a flexible and customizable logging system. It supports a variety of /// output targets, such as strings, standard error streams, files, or even network endpoints, and /// allows for logging at different levels of severity. This versatility makes it suitable for a /// wide range of applications and use cases. /// /// A key feature of the Logger is its ability to be specialized. Users can create a custom logger /// specialization (for example, targeting a string, standard error, a file, or a network endpoint) /// according to their specific needs. Once created, this specialized logger can be configured and /// used consistently across various components of an application. /// /// In addition to its flexibility in terms of output and configuration, the Logger class supports /// both singleton and regular class usage patterns. This provides further versatility in how /// logging functionality can be integrated into an application. /// /// The following examples illustrate how to use the Logger in both singleton and regular class /// contexts. /// /// ```cpp /// class SingletonLogger : public Logger { /// public: /// static SingletonLogger& instance() { /// static SingletonLogger instance; /// return instance; /// } /// /// private: /// SingletonLogger() { /// // Set default logger /// logger_ = std::make_shared(); /// func_ = nullptr; /// /// // Set level /// level(logger_->level()); /// /// // Set pattern /// pattern(logger_->pattern()); /// /// // Set sinks /// for (int severity = kNumSeverity - 1; severity >= 0; --severity) { /// redirect(severity, s_sinks[severity]); /// } /// } /// }; /// // ... /// SingletonLogger::instance().log(__FILE__, __LINE__, __FUNCTION__, 0, "Hello World!"); /// ``` /// /// The following example shows how to use Logger as a regular class: /// /// ```cpp /// class TestLogger : public Logger { /// public: /// static std::shared_ptr create() { return std::make_shared(); } /// }; /// // ... /// std::shared_ptr logger = TestLogger::create(); /// logger->log(__FILE__, __LINE__, __FUNCTION__, 0, "Hello World!"); /// ``` class Logger { public: /// Construct a logger instance. Logger() = default; /// Construct a logger instance with the custom logger. /// /// @param logger A shared pointer to the custom logger. explicit Logger(const std::shared_ptr& logger); /// Construct a logger instance with the custom log function. /// /// @param func The custom log function. explicit Logger(const LogFunction& func); /// Construct a logger instance with the custom logger or log function. /// /// @param logger A shared pointer to the custom logger. /// @param func The custom log function. Logger(const std::shared_ptr logger, const LogFunction& func); /// Log a message. /// /// Log a message using either a custom logger set via logger() or func(). /// The custom logger set via func() has priority over the one set via logger(). If neither is /// set, no logging occurs. /// /// @param file The name of the source file where the log request originated. /// @param line The line number in the source file. /// @param name The name of the function/module making the log request. /// @param level The log level. /// @param message The log message. void log(const char* file, int line, const char* name, int level, const char* message); /// Set a custom logger. /// /// Register a custom logger to be used for logging messages. The custom logger must implement /// the ILogger interface. /// /// @param custom_logger A shared pointer to the custom logger. void logger(std::shared_ptr custom_logger); /// Get the current custom logger. /// /// Retrieve the currently set custom logger. /// /// @return A shared pointer to the currently set custom logger. std::shared_ptr logger() const; /// Set a custom log function. /// /// Register a custom log function and an argument to be used for logging messages. This function /// has higher priority over the custom logger set via logger(). /// If func_arg is not nullptr, func_arg will be passed to log_func as an argument ('arg' /// parameter). /// /// @param log_func The custom log function. /// @param func_arg An opaque pointer to auxiliary data needed by log_func. void func(LogFunction log_func, void* func_arg = nullptr); /// Get the current custom log function. /// /// Retrieve the currently set custom log function. /// /// @return The currently set custom log function. LogFunction func() const; /// Get the current custom log function argument. /// /// Retrieve the currently set custom log function argument. /// /// @return The currently set custom log function argument. void* arg() const; /// Set the log message pattern. /// /// Set the pattern used for formatting log messages. /// /// @param pattern The pattern string for formatting log messages. void pattern(const char* pattern); /// Get the current log message pattern. /// /// Retrieve the currently set pattern used for formatting log messages. /// /// @return The currently set pattern string. const char* pattern() const; /// Set the log level. /// /// Set the log level, determining the priority of messages that should be logged. /// /// @param level The log level. void level(int level); /// Get the current log level. /// /// Retrieve the currently set log level. /// /// @return The currently set log level. int level() const; /// Redirect log output. /// /// Redirect log output to the specified file or other output for the given log level. /// /// @param level The log level for which output redirection is applied. /// @param output A pointer to the file or other output to redirect log output. void redirect(int level, void* output); /// Get the current redirection for a specified log level. /// /// Retrieve the file/output pointer to which log output is currently being redirected for the /// specified log level. If no redirection is set for the given level, returns nullptr. /// /// @param level The log level for which the redirection is queried. /// @return A pointer to the file/output where log output is redirected, or nullptr if no /// redirection is set. void* redirect(int level) const; protected: std::shared_ptr logger_; ///< shared pointer to the logger LogFunction func_; ///< log function void* func_arg_ = nullptr; ///< log function argument std::string pattern_; ///< log pattern int level_ = 0; ///< log level std::vector sinks_; ///< log sinks }; } // namespace logger } // namespace nvidia #endif /* COMMON_LOGGER_LOGGER_HPP */ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/multimedia/audio.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_MULTIMEDIA_AUDIO_HPP_ #define NVIDIA_GXF_MULTIMEDIA_AUDIO_HPP_ #include #include #include #include #include "gxf/core/expected.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/memory_buffer.hpp" namespace nvidia { namespace gxf { // Supported raw audio media types enum class AudioFormat { GXF_AUDIO_FORMAT_CUSTOM = 0, GXF_AUDIO_FORMAT_S16LE, // 16-bit signed PCM audio GXF_AUDIO_FORMAT_F32LE, // 32-bit floating-point audio }; // Supported channel layouts enum class AudioLayout { GXF_AUDIO_LAYOUT_CUSTOM = 0, GXF_AUDIO_LAYOUT_INTERLEAVED, // Data from all the channels to be interleaved LRLRLR GXF_AUDIO_LAYOUT_NON_INTERLEAVED, // Data from all the channels not to be interleaved LLLRRR }; template struct AudioTypeTraits; #define GXF_AUDIO_TYPE_TRAITS(ENUM, WIDTH) \ template <> \ struct AudioTypeTraits { \ static constexpr const char* name = #ENUM; \ static constexpr const AudioFormat value = AudioFormat::ENUM; \ static constexpr const int8_t width = WIDTH; \ }; GXF_AUDIO_TYPE_TRAITS(GXF_AUDIO_FORMAT_CUSTOM, 0); GXF_AUDIO_TYPE_TRAITS(GXF_AUDIO_FORMAT_S16LE, 16); GXF_AUDIO_TYPE_TRAITS(GXF_AUDIO_FORMAT_F32LE, 32); // Descriptor for an AudioBuffer struct AudioBufferInfo { // Number of channels in an audio frame uint32_t channels; // Number of samples in an audio frame uint32_t samples; // sampling rate in Hz uint32_t sampling_rate; // Number of bytes required per sample uint32_t bytes_per_sample; // AudioFormat of an audio frame AudioFormat audio_format; // AudioLayout of an audio frame AudioLayout audio_layout; }; // A media data type which stores information corresponding to an audio frame // resize(...) function is used to allocate memory for the audio frame based on // the audio frame info class AudioBuffer { public: AudioBuffer() = default; ~AudioBuffer() { memory_buffer_.freeBuffer(); } AudioBuffer(const AudioBuffer&) = delete; AudioBuffer(AudioBuffer&& other) { *this = std::move(other); } AudioBuffer& operator=(const AudioBuffer&) = delete; AudioBuffer& operator=(AudioBuffer&& other) { buffer_info_ = other.buffer_info_; memory_buffer_ = std::move(other.memory_buffer_); return *this; } template Expected resize(uint32_t channels, uint32_t samples, uint32_t sampling_rate, AudioLayout layout, MemoryStorageType storage_type, Handle allocator) { AudioTypeTraits audio_type; uint32_t bytes_per_sample = std::ceil(audio_type.width / 8); AudioBufferInfo buffer_info{channels, samples, sampling_rate, bytes_per_sample, audio_type.value, layout}; return resizeCustom(buffer_info, storage_type, allocator); } // Type of the callback function to release memory passed to the AudioFrame using the // wrapMemory method using release_function_t = MemoryBuffer::release_function_t; // Wrap existing memory inside the AudioBuffer. A callback function of type release_function_t // may be passed that will be called when the AudioBuffer wants to release the memory. Expected wrapMemory(AudioBufferInfo buffer_info, uint64_t size, MemoryStorageType storage_type, void* pointer, release_function_t release_func); // AudioBufferInfo of the AudioBuffer AudioBufferInfo audio_buffer_info() const { return buffer_info_; } // The type of memory where the frame data is stored. MemoryStorageType storage_type() const { return memory_buffer_.storage_type(); } // Size of the audio frame in bytes uint64_t size() const { return memory_buffer_.size(); } // Raw pointer to the first byte of the audio frame byte* pointer() const { return memory_buffer_.pointer(); } // Resizes the audio frame and allocates the corresponding memory with the allocator provided // Any data previously stored in the frame would be freed Expected resizeCustom(AudioBufferInfo buffer_info, MemoryStorageType storage_type, Handle allocator); private: AudioBufferInfo buffer_info_; MemoryBuffer memory_buffer_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_MULTIMEDIA_AUDIO_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/multimedia/camera.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_MULTIMEDIA_CAMERA_HPP_ #define NVIDIA_GXF_MULTIMEDIA_CAMERA_HPP_ #include #include #include "gxf/multimedia/video.hpp" #include "gxf/std/timestamp.hpp" namespace nvidia { namespace gxf { template struct Vector2 { T x; /**< point x coordinate. */ T y; /**< point y coordinate. */ }; using Vector2u = Vector2; using Vector2f = Vector2; using Vector2d = Vector2; enum class DistortionType { /** * No distortion */ Perspective, /** * Brown model with 3 radial and 2 tangential distortion coefficients. */ Brown, /** * Polynomial model with 6 radial and 2 tangential distortion coefficients. */ Polynomial, /** * Fisheye model with 4 radial distortion coefficients. * Specifies the equidistant fisheye mapping. * Mapping is defined by: * \f[r = f\theta\f] * where: * - \f$\theta\f$ is the angle from the optical axis. * - \f$f\f$ is the focal length. * - \f$r\f$ is the distance of a pixel from the image center. */ FisheyeEquidistant, /** * Fisheye model with 4 radial distortion coefficients. * Specifies the equisolid fisheye mapping. * Mapping is defined by: * \f[r = 2f\sin\left(\frac{\theta}{2}\right)\f] * where: * - \f$\theta\f$ is the angle from the optical axis. * - \f$f\f$ is the focal length. * - \f$r\f$ is the distance of a pixel from the image center. */ FisheyeEquisolid, /** * Fisheye model with 4 radial distortion coefficients. * Specifies the orthographic fisheye mapping. * Mapping is defined by: * \f[r = f\sin(\theta)\f] * where: * - \f$\theta\f$ is the angle from the optical axis. * - \f$f\f$ is the focal length. * - \f$r\f$ is the distance of a pixel from the image center. */ FisheyeOrthoGraphic, /** * Fisheye model with 4 radial distortion coefficients. * Specifies the stereographic fisheye mapping. * Mapping is defined by: * \f[r = 2f\tan\left(\frac{\theta}{2}\right)\f] * where: * - \f$\theta\f$ is the angle from the optical axis. * - \f$f\f$ is the focal length. * - \f$r\f$ is the distance of a pixel from the image center. */ FisheyeStereographic, }; /** * Camera intrinsics model. * Intrinsic camera matrix is defined as follow: * [fx s cx] * K = [ 0 fy cy] * [ 0 0 1] * where: * - fx, fy represent focal length. * - cx, cy represent principle point. * - s represents the skew value. */ template struct CameraModelBase { // The maximum number of distortion coefficients. static constexpr int kMaxDistortionCoefficients = 8; // The dimensions of the camera image plane in pixels in the order x, y. Vector2u dimensions; // Focal length of the projection (in pixels) in the order x, y. Vector2 focal_length; // Optical center of the projection (in pixels) in the order x, y. Vector2 principal_point; // The skew coefficient between the x and the y axis (usually 0). T skew_value; // Distortion type of the camera. DistortionType distortion_type; // Distortion coefficients of the camera. std::array distortion_coefficients; }; using CameraModel = CameraModelBase; /** * Camera extrinsics model. * Extrinsic camera matrix is defined as follow: * T = [R | t] * where: * - R is the rotation matrix. * - t is the translation vector. */ template struct Pose3DBase { // The 3x3 rotation matrix. std::array rotation; // The translation vector. std::array translation; }; using Pose3D = Pose3DBase; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_MULTIMEDIA_CAMERA_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/multimedia/video.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_MULTIMEDIA_VIDEO_HPP_ #define NVIDIA_GXF_MULTIMEDIA_VIDEO_HPP_ #include #include #include #include #include "gxf/core/expected.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/memory_buffer.hpp" #include "gxf/std/tensor.hpp" namespace nvidia { namespace gxf { #ifdef __aarch64__ static constexpr const uint16_t kGxfAlignValue = 256; #else static constexpr const uint16_t kGxfAlignValue = 256; #endif // Align frame stride to kGxfAlignValue static constexpr uint32_t StrideAlign(uint32_t stride) { return (stride % kGxfAlignValue == 0) ? stride : ((stride / kGxfAlignValue + 1) * kGxfAlignValue); } // Compute strides for video buffer // // If stride is non zero, use it as it is // If stride is not set and align is enabled (default), use align(w * bytes) // If stride is not set and align is disabled, use (w * bytes) static constexpr uint32_t ComputeStrides(bool stride_align, uint32_t width, uint32_t bytes_per_pixel, uint32_t stride) { if (stride != 0) { // Use existing stride without alignment return stride; } else if (stride_align) { // unset stride, align based on width return StrideAlign(width * bytes_per_pixel); } else { // return unaligned buffer return width * bytes_per_pixel; } } // Round up to the closest even number static constexpr uint32_t AlignToEvenDimension(uint32_t value) { return value + (value & 1); } // Supported raw video media types enum class VideoFormat : std::int64_t { GXF_VIDEO_FORMAT_CUSTOM = 0, GXF_VIDEO_FORMAT_YUV420, // BT.601 multi planar 4:2:0 YUV GXF_VIDEO_FORMAT_YUV420_ER, // BT.601 multi planar 4:2:0 YUV ER GXF_VIDEO_FORMAT_YUV420_709, // BT.709 multi planar 4:2:0 YUV GXF_VIDEO_FORMAT_YUV420_709_ER, // BT.709 multi planar 4:2:0 YUV GXF_VIDEO_FORMAT_NV12, // BT.601 multi planar 4:2:0 YUV with interleaved UV GXF_VIDEO_FORMAT_NV12_ER, // BT.601 multi planar 4:2:0 YUV ER with interleaved UV GXF_VIDEO_FORMAT_NV12_709, // BT.709 multi planar 4:2:0 YUV with interleaved UV GXF_VIDEO_FORMAT_NV12_709_ER, // BT.709 multi planar 4:2:0 YUV ER with interleaved UV GXF_VIDEO_FORMAT_RGBA, // RGBA-8-8-8-8 single plane GXF_VIDEO_FORMAT_BGRA, // BGRA-8-8-8-8 single plane GXF_VIDEO_FORMAT_ARGB, // ARGB-8-8-8-8 single plane GXF_VIDEO_FORMAT_ABGR, // ABGR-8-8-8-8 single plane GXF_VIDEO_FORMAT_RGBX, // RGBX-8-8-8-8 single plane GXF_VIDEO_FORMAT_BGRX, // BGRX-8-8-8-8 single plane GXF_VIDEO_FORMAT_XRGB, // XRGB-8-8-8-8 single plane GXF_VIDEO_FORMAT_XBGR, // XBGR-8-8-8-8 single plane GXF_VIDEO_FORMAT_RGB, // RGB-8-8-8 single plane GXF_VIDEO_FORMAT_BGR, // BGR-8-8-8 single plane GXF_VIDEO_FORMAT_R8_G8_B8, // RGB - unsigned 8 bit multiplanar GXF_VIDEO_FORMAT_B8_G8_R8, // BGR - unsigned 8 bit multiplanar GXF_VIDEO_FORMAT_GRAY, // 8 bit GRAY scale single plane GXF_VIDEO_FORMAT_GRAY16, // 16 bit GRAY scale single plane GXF_VIDEO_FORMAT_GRAY32, // 32 bit GRAY scale single plane GXF_VIDEO_FORMAT_GRAY32F, // float 32 bit GRAY scale single plane GXF_VIDEO_FORMAT_RGB16, // RGB-16-16-16 single plane GXF_VIDEO_FORMAT_BGR16, // BGR-16-16-16 single plane GXF_VIDEO_FORMAT_RGB32, // RGB-32-32-32 single plane GXF_VIDEO_FORMAT_BGR32, // BGR-32-32-32 single plane GXF_VIDEO_FORMAT_R16_G16_B16, // RGB - signed 16 bit multiplanar GXF_VIDEO_FORMAT_B16_G16_R16, // BGR - signed 16 bit multiplanar GXF_VIDEO_FORMAT_R32_G32_B32, // RGB - signed 32 bit multiplanar GXF_VIDEO_FORMAT_B32_G32_R32, // BGR - signed 32 bit multiplanar GXF_VIDEO_FORMAT_NV24, // multi planar 4:4:4 YUV with interleaved UV GXF_VIDEO_FORMAT_NV24_ER, // multi planar 4:4:4 YUV ER with interleaved UV GXF_VIDEO_FORMAT_R8_G8_B8_D8, // RGBD unsigned 8 bit multiplanar GXF_VIDEO_FORMAT_R16_G16_B16_D16, // RGBD unsigned 16 bit multiplanar GXF_VIDEO_FORMAT_R32_G32_B32_D32, // RGBD unsigned 32 bit multiplanar GXF_VIDEO_FORMAT_RGBD8, // RGBD 8 bit unsigned single plane GXF_VIDEO_FORMAT_RGBD16, // RGBD 16 bit unsigned single plane GXF_VIDEO_FORMAT_RGBD32, // RGBD 32 bit unsigned single plane GXF_VIDEO_FORMAT_D32F, // Depth 32 bit float single plane GXF_VIDEO_FORMAT_D64F, // Depth 64 bit float single plane GXF_VIDEO_FORMAT_RAW16_RGGB, // RGGB-16-16-16-16 single plane GXF_VIDEO_FORMAT_RAW16_BGGR, // BGGR-16-16-16-16 single plane GXF_VIDEO_FORMAT_RAW16_GRBG, // GRBG-16-16-16-16 single plane GXF_VIDEO_FORMAT_RAW16_GBRG, // GBRG-16-16-16-16 single plane }; // Supported surface memory types enum class SurfaceLayout : std::int32_t { GXF_SURFACE_LAYOUT_INVALID = 0, GXF_SURFACE_LAYOUT_PITCH_LINEAR, // pitch linear surface memory GXF_SURFACE_LAYOUT_BLOCK_LINEAR, // block linear surface memory }; template struct VideoTypeTraits; #define GXF_VIDEO_TYPE_TRAITS(ENUM) \ template <> \ struct VideoTypeTraits { \ static constexpr const char* name = #ENUM; \ static constexpr const VideoFormat value = VideoFormat::ENUM; \ }; GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_CUSTOM); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_YUV420); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_YUV420_ER); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_YUV420_709); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_YUV420_709_ER); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_NV12); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_NV12_ER); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_NV12_709); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_NV12_709_ER); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RGBA); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_BGRA); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_ARGB); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_ABGR); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RGBX); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_BGRX); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_XRGB); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_XBGR); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RGB); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_BGR); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_R8_G8_B8); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_B8_G8_R8); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_GRAY); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_GRAY16); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_GRAY32); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_GRAY32F); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RGB16); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_BGR16); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RGB32); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_BGR32); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_R16_G16_B16); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_B16_G16_R16); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_R32_G32_B32); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_B32_G32_R32); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_NV24); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_NV24_ER); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_R8_G8_B8_D8); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_R16_G16_B16_D16); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_R32_G32_B32_D32); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RGBD8); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RGBD16); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RGBD32); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_D32F); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_D64F); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RAW16_RGGB); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RAW16_BGGR); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RAW16_GRBG); GXF_VIDEO_TYPE_TRAITS(GXF_VIDEO_FORMAT_RAW16_GBRG); // Struct to hold the information regarding a single color plane struct ColorPlane { std::string color_space; uint8_t bytes_per_pixel = 0; uint32_t stride = 0; uint32_t offset = 0; uint32_t width = 0; uint32_t height = 0; uint64_t size = 0; ColorPlane() {} ColorPlane(const char* c_space, uint8_t c_depth, uint32_t c_stride = 0) : color_space(c_space), bytes_per_pixel(c_depth), stride(c_stride) {} }; // Template to compute the memory size of an image // for different color formats template struct VideoFormatSize { uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { return 0; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { return {}; } }; // Specifies YUV420 multi-planar variants template struct VideoFormatSize> { std::array default_yuv{ColorPlane("Y", 1), ColorPlane("U", 1), ColorPlane("V", 1)}; uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); color_planes[0].width = widthEven; color_planes[1].width = widthEven / 2; color_planes[2].width = widthEven / 2; color_planes[0].height = heightEven; color_planes[1].height = heightEven / 2; color_planes[2].height = heightEven / 2; uint64_t size = 0; for (size_t i = 0; i < color_planes.size(); ++i) { if (i == 0) { color_planes[i].stride = ComputeStrides(stride_align, color_planes[i].width, color_planes[i].bytes_per_pixel, color_planes[i].stride); } else if (color_planes[i].stride == 0) { // YUV formats require UV planes stride to be half of Y plane color_planes[i].stride = color_planes[0].stride / 2; } color_planes[i].size = color_planes[i].stride * color_planes[i].height; color_planes[i].offset = size; size += color_planes[i].size; } return size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto yuv = default_yuv; fillColorPlanes(width, height, yuv, stride_align); std::vector result(yuv.begin(), yuv.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { return fillColorPlanes(width, height, default_yuv, stride_align); } }; // Specifies YUV444 multi-planar variants template struct VideoFormatSize> { std::array default_yuv{ColorPlane("Y", 1), ColorPlane("UV", 2)}; uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); uint64_t size = 0; for (size_t i = 0; i < color_planes.size(); ++i) { color_planes[i].width = widthEven; color_planes[i].height = heightEven; color_planes[i].stride = ComputeStrides(stride_align, color_planes[i].width, color_planes[i].bytes_per_pixel, color_planes[i].stride); color_planes[i].size = color_planes[i].stride * color_planes[i].height; color_planes[i].offset = size; size += color_planes[i].size; } return size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto yuv = default_yuv; fillColorPlanes(width, height, yuv, stride_align); std::vector result(yuv.begin(), yuv.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { return fillColorPlanes(width, height, default_yuv, stride_align); } }; // Specifies NV12 Y/CbCr 4:2:0 multi-planar variants template struct VideoFormatSize> { std::array default_yuv{ColorPlane("Y", 1), ColorPlane("UV", 2)}; uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); color_planes[0].width = widthEven; color_planes[1].width = widthEven / 2; color_planes[0].height = heightEven; color_planes[1].height = heightEven / 2; uint64_t size = 0; for (size_t i = 0; i < color_planes.size(); ++i) { color_planes[i].stride = ComputeStrides(stride_align, color_planes[i].width, color_planes[i].bytes_per_pixel, color_planes[i].stride); color_planes[i].size = color_planes[i].stride * color_planes[i].height; color_planes[i].offset = size; size += color_planes[i].size; } return size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto yuv = default_yuv; fillColorPlanes(width, height, yuv, stride_align); std::vector result(yuv.begin(), yuv.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { return fillColorPlanes(width, height, default_yuv, stride_align); } }; // Specifies 8-8-8-8 single plane RGBX/XRGB variants template struct VideoFormatSize< T, std::enable_if_t< T == VideoFormat::GXF_VIDEO_FORMAT_RGBA || T == VideoFormat::GXF_VIDEO_FORMAT_BGRA || T == VideoFormat::GXF_VIDEO_FORMAT_ARGB || T == VideoFormat::GXF_VIDEO_FORMAT_ABGR || T == VideoFormat::GXF_VIDEO_FORMAT_RGBX || T == VideoFormat::GXF_VIDEO_FORMAT_BGRX || T == VideoFormat::GXF_VIDEO_FORMAT_XRGB || T == VideoFormat::GXF_VIDEO_FORMAT_XBGR>> { std::array defaultRGBA() { if (T == VideoFormat::GXF_VIDEO_FORMAT_RGBA) { return {ColorPlane("RGBA", 4)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_BGRA) { return {ColorPlane("BGRA", 4)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_ARGB) { return {ColorPlane("ARGB", 4)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_ABGR) { return {ColorPlane("ABGR", 4)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_RGBX) { return {ColorPlane("RGBX", 4)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_BGRX) { return {ColorPlane("BGRX", 4)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_XRGB) { return {ColorPlane("XRGB", 4)}; } else { // T == VideoFormat::GXF_VIDEO_FORMAT_XBGR return {ColorPlane("XBGR", 4)}; } } uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_plane, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); color_plane[0].width = widthEven; color_plane[0].height = heightEven; color_plane[0].stride = ComputeStrides(stride_align, color_plane[0].width, color_plane[0].bytes_per_pixel, color_plane[0].stride); color_plane[0].size = color_plane[0].stride * color_plane[0].height; color_plane[0].offset = 0; return color_plane[0].size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto rgba = defaultRGBA(); fillColorPlanes(width, height, rgba, stride_align); std::vector result(rgba.begin(), rgba.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { auto rgba = defaultRGBA(); return fillColorPlanes(width, height, rgba, stride_align); } }; // Specifies x-x-x(8/16/32) bit single plane RGB/BGR variants template struct VideoFormatSize< T, std::enable_if_t< T == VideoFormat::GXF_VIDEO_FORMAT_RGB || T == VideoFormat::GXF_VIDEO_FORMAT_BGR || T == VideoFormat::GXF_VIDEO_FORMAT_RGB16 || T == VideoFormat::GXF_VIDEO_FORMAT_BGR16 || T == VideoFormat::GXF_VIDEO_FORMAT_RGB32 || T == VideoFormat::GXF_VIDEO_FORMAT_BGR32>> { std::array defaultRGB() { if (T == VideoFormat::GXF_VIDEO_FORMAT_RGB) { return {ColorPlane("RGB", 3)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_BGR) { return {ColorPlane("BGR", 3)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_RGB16) { return {ColorPlane("RGB", 3 * 2)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_BGR16) { return {ColorPlane("BGR", 3 * 2)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_RGB32) { return {ColorPlane("RGB", 3 * 4)}; } else { // T == VideoFormat::GXF_VIDEO_FORMAT_BGR32 return {ColorPlane("BGR", 3 * 4)}; } } uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_plane, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); color_plane[0].width = widthEven; color_plane[0].height = heightEven; color_plane[0].stride = ComputeStrides(stride_align, color_plane[0].width, color_plane[0].bytes_per_pixel, color_plane[0].stride); color_plane[0].size = color_plane[0].stride * color_plane[0].height; color_plane[0].offset = 0; return color_plane[0].size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto rgb = defaultRGB(); fillColorPlanes(width, height, rgb, stride_align); std::vector result(rgb.begin(), rgb.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { auto rgb = defaultRGB(); return fillColorPlanes(width, height, rgb, stride_align); } }; // Specifies x-x-x(8/16/32) bit multi planar RGB/BGR variants template struct VideoFormatSize> { std::array defaultRGB() { if (T == VideoFormat::GXF_VIDEO_FORMAT_R8_G8_B8) { return {ColorPlane("R", 1), ColorPlane("G", 1), ColorPlane("B", 1)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_B8_G8_R8) { return {ColorPlane("B", 1), ColorPlane("G", 1), ColorPlane("R", 1)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_R16_G16_B16) { return {ColorPlane("R", 2), ColorPlane("G", 2), ColorPlane("B", 2)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_B16_G16_R16) { return {ColorPlane("B", 2), ColorPlane("G", 2), ColorPlane("R", 2)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_R32_G32_B32) { return {ColorPlane("R", 4), ColorPlane("G", 4), ColorPlane("B", 4)}; } else { // T == VideoFormat::GXF_VIDEO_FORMAT_B32_G32_R32 return {ColorPlane("B", 4), ColorPlane("G", 4), ColorPlane("R", 4)}; } } uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); uint64_t size = 0; for (size_t i = 0; i < color_planes.size(); ++i) { color_planes[i].width = widthEven; color_planes[i].height = heightEven; color_planes[i].stride = ComputeStrides(stride_align, color_planes[i].width, color_planes[i].bytes_per_pixel, color_planes[i].stride); color_planes[i].size = color_planes[i].stride * color_planes[i].height; color_planes[i].offset = size; size += color_planes[i].size; } return size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto rgb = defaultRGB(); fillColorPlanes(width, height, rgb, stride_align); std::vector result(rgb.begin(), rgb.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { auto rgb = defaultRGB(); return fillColorPlanes(width, height, rgb, stride_align); } }; // Specifies x-x-x(8/16/32) bit multi planar RGBD variants template struct VideoFormatSize> { std::array defaultRGBD() { if (T == VideoFormat::GXF_VIDEO_FORMAT_R8_G8_B8_D8) { return {ColorPlane("R", 1), ColorPlane("G", 1), ColorPlane("B", 1), ColorPlane("D", 1)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_R16_G16_B16_D16) { return {ColorPlane("R", 2), ColorPlane("G", 2), ColorPlane("B", 2), ColorPlane("D", 2)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_R32_G32_B32_D32) { return {ColorPlane("R", 4), ColorPlane("G", 4), ColorPlane("B", 4), ColorPlane("D", 4)}; } } uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); uint64_t size = 0; for (size_t i = 0; i < color_planes.size(); ++i) { color_planes[i].width = widthEven; color_planes[i].height = heightEven; color_planes[i].stride = ComputeStrides(stride_align, color_planes[i].width, color_planes[i].bytes_per_pixel, color_planes[i].stride); color_planes[i].size = color_planes[i].stride * color_planes[i].height; color_planes[i].offset = size; size += color_planes[i].size; } return size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto rgbd = defaultRGBD(); fillColorPlanes(width, height, rgbd, stride_align); std::vector result(rgbd.begin(), rgbd.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { auto rgbd = defaultRGBD(); return fillColorPlanes(width, height, rgbd, stride_align); } }; // Specifies x-x-x-x(8/16/32) bit float single plane RGBD variants template struct VideoFormatSize> { std::array defaultRGBD() { if (T == VideoFormat::GXF_VIDEO_FORMAT_RGBD8) { return {ColorPlane("RGBD", 4)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_RGBD16) { return {ColorPlane("RGBD", 8)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_RGBD32) { return {ColorPlane("RGBD", 16)}; } } uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_plane, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); color_plane[0].width = widthEven; color_plane[0].height = heightEven; color_plane[0].stride = ComputeStrides(stride_align, color_plane[0].width, color_plane[0].bytes_per_pixel, color_plane[0].stride); color_plane[0].size = color_plane[0].stride * color_plane[0].height; color_plane[0].offset = 0; return color_plane[0].size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto rgbd = defaultRGBD(); fillColorPlanes(width, height, rgbd, stride_align); std::vector result(rgbd.begin(), rgbd.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { auto rgbd = defaultRGBD(); return fillColorPlanes(width, height, rgbd, stride_align); } }; // Specifies 32/64 bit float single plane Depth template struct VideoFormatSize> { std::array defaultDepth() { if (T == VideoFormat::GXF_VIDEO_FORMAT_D32F) { return {ColorPlane("D", 4)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_D64F) { return {ColorPlane("D", 8)}; } } uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_plane, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); color_plane[0].width = widthEven; color_plane[0].height = heightEven; color_plane[0].stride = ComputeStrides(stride_align, color_plane[0].width, color_plane[0].bytes_per_pixel, color_plane[0].stride); color_plane[0].size = color_plane[0].stride * color_plane[0].height; color_plane[0].offset = 0; return color_plane[0].size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto depth = defaultDepth(); fillColorPlanes(width, height, depth, stride_align); std::vector result(depth.begin(), depth.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_planes, bool stride_align = true) { return fillColorPlanes(width, height, color_planes, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { auto depth = defaultDepth(); return fillColorPlanes(width, height, depth, stride_align); } }; // Specifies x-x-x(8/16/32) bit single plane GRAY scale template struct VideoFormatSize> { std::array defaultGray() { if (T == VideoFormat::GXF_VIDEO_FORMAT_GRAY) { return {ColorPlane("gray", 1)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_GRAY16) { return {ColorPlane("gray", 2)}; } else { // T == VideoFormat::GXF_VIDEO_FORMAT_GRAY32 & VideoFormat::GXF_VIDEO_FORMAT_GRAY32F return {ColorPlane("gray", 4)}; } } uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_plane, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); color_plane[0].width = widthEven; color_plane[0].height = heightEven; color_plane[0].stride = ComputeStrides(stride_align, color_plane[0].width, color_plane[0].bytes_per_pixel, color_plane[0].stride); color_plane[0].size = color_plane[0].stride * color_plane[0].height; color_plane[0].offset = 0; return color_plane[0].size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto gray = defaultGray(); fillColorPlanes(width, height, gray, stride_align); std::vector result(gray.begin(), gray.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_plane, bool stride_align = true) { return fillColorPlanes(width, height, color_plane, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { auto gray = defaultGray(); return fillColorPlanes(width, height, gray, stride_align); } }; // Specifies x-x-x-x(16) bit single plane Bayer RAW16 template struct VideoFormatSize> { std::array defaultBayerRaw16() { if (T == VideoFormat::GXF_VIDEO_FORMAT_RAW16_RGGB) { return {ColorPlane("Raw_RGGB", 4 * 2)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_RAW16_BGGR) { return {ColorPlane("Raw_BGGR", 4 * 2)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_RAW16_GRBG) { return {ColorPlane("Raw_GRBG", 4 * 2)}; } else if (T == VideoFormat::GXF_VIDEO_FORMAT_RAW16_GBRG) { return {ColorPlane("Raw_GBRG", 4 * 2)}; } } uint64_t fillColorPlanes(uint32_t width, uint32_t height, std::array& color_plane, bool stride_align = true) { uint32_t widthEven = AlignToEvenDimension(width); uint32_t heightEven = AlignToEvenDimension(height); color_plane[0].width = widthEven; color_plane[0].height = heightEven; color_plane[0].stride = ComputeStrides(stride_align, color_plane[0].width, color_plane[0].bytes_per_pixel, color_plane[0].stride); color_plane[0].size = color_plane[0].stride * color_plane[0].height; color_plane[0].offset = 0; return color_plane[0].size; } std::vector getDefaultColorPlanes(uint32_t width, uint32_t height, bool stride_align = true) { auto bayerRaw16 = defaultBayerRaw16(); fillColorPlanes(width, height, bayerRaw16, stride_align); std::vector result(bayerRaw16.begin(), bayerRaw16.end()); return result; } uint64_t size(uint32_t width, uint32_t height, std::array& color_plane, bool stride_align = true) { return fillColorPlanes(width, height, color_plane, stride_align); } uint64_t size(uint32_t width, uint32_t height, bool stride_align = true) { auto bayerRaw16 = defaultBayerRaw16(); return fillColorPlanes(width, height, bayerRaw16, stride_align); } }; // Descriptor for a VideoBuffer struct VideoBufferInfo { // width of a video frame uint32_t width; // height of a video frame uint32_t height; // color format of a video frame VideoFormat color_format; // Color plane info std::vector color_planes; // surface memory layout of a video frame SurfaceLayout surface_layout; }; // A media type which stores information corresponding to a video frame // resize(...) function is used to allocate memory for the video frame based on // height, width and color format of the frame class VideoBuffer { public: VideoBuffer() = default; ~VideoBuffer() { memory_buffer_.freeBuffer(); } VideoBuffer(const VideoBuffer&) = delete; VideoBuffer(VideoBuffer&& other) { *this = std::move(other); } VideoBuffer& operator=(const VideoBuffer&) = delete; VideoBuffer& operator=(VideoBuffer&& other) { buffer_info_ = other.buffer_info_; memory_buffer_ = std::move(other.memory_buffer_); return *this; } // Resizes the video frame and allocates the corresponding memory with the allocator provided // Any data previously stored in the frame would be freed template Expected resize(uint32_t width, uint32_t height, SurfaceLayout layout, MemoryStorageType storage_type, Handle allocator, bool stride_align = true) { VideoTypeTraits video_type; VideoFormatSize color_format; uint64_t size = color_format.size(width, height, stride_align); auto color_planes = color_format.getDefaultColorPlanes(width, height, stride_align); VideoBufferInfo buffer_info{width, height, video_type.value, std::move(color_planes), layout}; return resizeCustom(std::move(buffer_info), size, storage_type, allocator); } // Type of the callback function to release memory passed to the VideoFrame using the // wrapMemory method using release_function_t = MemoryBuffer::release_function_t; // Wrap existing memory inside the VideoBuffer. A callback function of type release_function_t // may be passed that will be called when the VideoBuffer wants to release the memory. Expected wrapMemory(VideoBufferInfo buffer_info, uint64_t size, MemoryStorageType storage_type, void* pointer, release_function_t release_func); // Moves the existing video buffer to a tensor element specified by the handle Expected moveToTensor(Handle& tensor); // Moves the existing video buffer to a tensor element specified by the pointer Expected moveToTensor(Tensor* tensor); // Moves memory buffer from tensor to video buffer works on rank 2 and 3 tensors, // ordering of dimensions in tensor is assumed to be [whc] // OBS: If successful, tensor destructor will be called and handle set to null template Expected createFromTensor(Handle& tensor, SurfaceLayout layout, bool stride_align = true); // VideoBufferInfo of the video frame VideoBufferInfo video_frame_info() const { return buffer_info_; } // The type of memory where the frame data is stored. MemoryStorageType storage_type() const { return memory_buffer_.storage_type(); } // Size of the video frame in bytes uint64_t size() const { return memory_buffer_.size(); } // Raw pointer to the first byte of the video frame byte* pointer() const { return memory_buffer_.pointer(); } // Resizes the video frame and allocates the corresponding memory with the allocator provided // Any data previously stored in the frame would be freed Expected resizeCustom(VideoBufferInfo buffer_info, uint64_t size, MemoryStorageType storage_type, Handle allocator); // Helper function to get primitive types for color formats that are valid (planar) for moving // from Tensor to VideoBuffer, and vice versa. If color_format is not valid, // PrimitiveType::kCustom is returned static Expected getPlanarPrimitiveType(VideoFormat color_format) { PrimitiveType primitive_type; switch (color_format) { case VideoFormat::GXF_VIDEO_FORMAT_NV12: // BT.601 2 planes Y, UV case VideoFormat::GXF_VIDEO_FORMAT_RGBA: // RGBA-8-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_BGRA: // BGRA-8-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_ARGB: // ARGB-8-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_ABGR: // ABGR-8-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_RGBX: // RGBX-8-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_BGRX: // BGRX-8-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_XRGB: // XRGB-8-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_XBGR: // XBGR-8-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_RGB: // RGB-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_BGR: // BGR-8-8-8 single plane case VideoFormat::GXF_VIDEO_FORMAT_R8_G8_B8: // RGB - unsigned 8 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_B8_G8_R8: // BGR - unsigned 8 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_R8_G8_B8_D8: // RGBD unsigned 8 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_RGBD8: // RGBD 8 bit unsigned single plane case VideoFormat::GXF_VIDEO_FORMAT_GRAY: { // 8 bit GRAY scale single plane primitive_type = PrimitiveType::kUnsigned8; } break; case VideoFormat::GXF_VIDEO_FORMAT_GRAY16: // 16 bit GRAY scale single plane case VideoFormat::GXF_VIDEO_FORMAT_RGB16: // RGB-16-16-16 single plane case VideoFormat::GXF_VIDEO_FORMAT_BGR16: // BGR-16-16-16 single plane case VideoFormat::GXF_VIDEO_FORMAT_R16_G16_B16: // RGB unsigned 16 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_B16_G16_R16: // BGR unsigned 16 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_R16_G16_B16_D16: // RGBD unsigned 16 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_RGBD16: { // RGBD 16 bit unsigned single plane primitive_type = PrimitiveType::kUnsigned16; } break; case VideoFormat::GXF_VIDEO_FORMAT_GRAY32: // 32 bit GRAY scale single plane case VideoFormat::GXF_VIDEO_FORMAT_RGB32: // RGB-32-32-32 single plane case VideoFormat::GXF_VIDEO_FORMAT_BGR32: // BGR-32-32-32 single plane case VideoFormat::GXF_VIDEO_FORMAT_R32_G32_B32: // RGB unsigned 32 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_B32_G32_R32: // BGR unsigned 32 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_R32_G32_B32_D32: // RGBD unsigned 32 bit multiplanar case VideoFormat::GXF_VIDEO_FORMAT_RGBD32: { // RGBD 32 bit unsigned single plane primitive_type = PrimitiveType::kUnsigned32; } break; case VideoFormat::GXF_VIDEO_FORMAT_D32F: // Depth 32 bit float single plane case VideoFormat::GXF_VIDEO_FORMAT_GRAY32F: { // GRAY 32 bit float single plane primitive_type = PrimitiveType::kFloat32; } break; case VideoFormat::GXF_VIDEO_FORMAT_D64F: { // Depth 64 bit float single plane primitive_type = PrimitiveType::kFloat64; } break; case VideoFormat::GXF_VIDEO_FORMAT_CUSTOM: { // CUSTOM undefined primitive_type = PrimitiveType::kCustom; } break; default: { // Non-planar type given GXF_LOG_ERROR("VideoFormat is of non-planar color format (%ld)," " which cannot be moved from tensor", static_cast(color_format)); return Unexpected{GXF_INVALID_DATA_FORMAT}; } break; } return primitive_type; } private: VideoBufferInfo buffer_info_; MemoryBuffer memory_buffer_; }; template Expected VideoBuffer::createFromTensor(Handle& tensor, SurfaceLayout layout, bool stride_align) { if (!tensor) { GXF_LOG_ERROR("createFromTensor received invalid tensor handle"); return Unexpected{GXF_ARGUMENT_NULL}; } // Tensor must have rank 2 (single-plane image) or 3 (multi-plane image) const uint32_t rank = tensor->rank(); if ((rank < 2) || (rank > 3)) { GXF_LOG_ERROR("Tensor cannot be moved to VideoBuffer." " Invalid rank=[%d], should be 2 or 3", rank); return Unexpected{GXF_INVALID_DATA_FORMAT}; } // Get primitive type and sanity check color format VideoTypeTraits video_type; VideoFormatSize color_format; Expected primitive_type = getPlanarPrimitiveType(video_type.value); if (!primitive_type) { return ForwardError(primitive_type); } // Ensure video buffer and tensor has same data type PrimitiveType primite_type_tensor = tensor->element_type(); if (primitive_type.value() != primite_type_tensor) { GXF_LOG_ERROR("Type of video buffer (%d) is different from" " type of tensor (%d)", static_cast(primitive_type.value()), static_cast(primite_type_tensor)); return Unexpected{GXF_INVALID_DATA_FORMAT}; } // Get tensor dimensions auto width = static_cast(tensor->shape().dimension(0)); auto height = static_cast(tensor->shape().dimension(1)); auto channels = static_cast(tensor->shape().dimension(2)); // Get color planes auto color_planes = color_format.getDefaultColorPlanes(width, height, stride_align); // Sanity check that number of tensor channels corresponds to video format if (channels != color_planes.size()) { GXF_LOG_ERROR("Number of channels in tensor (%u) is " " different from video buffer (%lu)", channels, color_planes.size()); return Unexpected{GXF_INVALID_DATA_FORMAT}; } // Set buffer info VideoBufferInfo buffer_info{width, height, video_type.value, std::move(color_planes), layout}; buffer_info_ = std::move(buffer_info); // Move memory buffer memory_buffer_ = tensor->move_buffer(); // Explicit call to destructor as tensor is no longer usable (also set to Null handle) tensor->~Tensor(); tensor = Handle::Null(); return Success; } } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_MULTIMEDIA_VIDEO_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/network/tcp_client.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_NETWORK_TCP_CLIENT_HPP_ #define NVIDIA_GXF_NETWORK_TCP_CLIENT_HPP_ #include "gxf/network/tcp_codelet.hpp" namespace nvidia { namespace gxf { // Codelet that functions as a client in a TCP connection class TcpClient : public TcpCodelet { protected: Expected openSockets() override; Expected reconnectSockets() override; Expected closeSockets() override; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_NETWORK_TCP_CLIENT_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/network/tcp_client_socket.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_NETWORK_TCP_CLIENT_SOCKET_HPP_ #define NVIDIA_GXF_NETWORK_TCP_CLIENT_SOCKET_HPP_ #include #include #include #include "gxf/serialization/endpoint.hpp" #include "gxf/serialization/entity_serializer.hpp" namespace nvidia { namespace gxf { // Header containing metadata for TCP packets #pragma pack(push, 1) struct TcpHeader { uint64_t payload_size; // Size of the payload in bytes uint64_t entity_count; // Number of entities in the payload }; #pragma pack(pop) // Header containing metadata for entities #pragma pack(push, 1) struct MessageHeader { uint64_t channel_id; // Hashed channel name }; #pragma pack(pop) // TCP message consisting of a header and an entity struct TcpMessage { MessageHeader header; Entity entity; }; // Endpoint for exchanging data over a TCP connection. // Connection must be established prior to use. // Packets are organized in the following format: // // | TCP Header || Message Header | Entity | ... | ... | // // Each entity will have a header prepended to form a message. // Messages will be grouped together to form the packet. // Little-endian is used over big-endian for better performance on x86 and arm platforms. class TcpClientSocket : public Endpoint { public: TcpClientSocket() = default; ~TcpClientSocket() = default; TcpClientSocket(const TcpClientSocket& other) = delete; TcpClientSocket(TcpClientSocket&& other) { *this = std::move(other); } TcpClientSocket& operator=(const TcpClientSocket& other) = delete; TcpClientSocket& operator=(TcpClientSocket&& other) { fd_socket_ = other.fd_socket_; connected_ = other.connected_; maximum_attempts_ = other.maximum_attempts_; other.fd_socket_ = -1; other.connected_ = false; other.maximum_attempts_ = 1; return *this; } Expected open(); Expected close(); gxf_result_t write_abi(const void* data, size_t size, size_t* bytes_written) override; gxf_result_t read_abi(void* data, size_t size, size_t* bytes_read) override; // Initializes endpoint with a connected socket. // This is used by TcpServerSocket when establishing a connection. Expected openConnectedSocket(int socket); // Closes and reopens socket to enable reconnecting. // Socket needs to be reset after disconnecting to be used again. Expected reopenSocket(); // Configures the maximum number of attempts void setMaximumAttempts(size_t attempts) { maximum_attempts_ = attempts; } // Returns true if the socket has data available for reading bool available() const; // Returns true if the socket is connected bool connected() const { return connected_; } // Attempts to connect to a TCP server at the given IP address. // Call will fail if IP address is invalid or server is unreachable. Expected connect(const char* address, uint16_t port); // Sends a set of messages via TCP Expected sendMessages(const std::vector& messages, EntitySerializer* serializer); // Receives a set of messages via TCP Expected> receiveMessages(gxf_context_t context, EntitySerializer* serializer); private: // Sends a message to the socket Expected sendMessage(const TcpMessage& message, EntitySerializer* serializer); // Receives a message from the socket Expected receiveMessage(gxf_context_t context, EntitySerializer* serializer); // Sends a TCP header to the socket Expected sendTcpHeader(TcpHeader header); // Receives a TCP header from the socket Expected receiveTcpHeader(); // Sends a message header to the socket Expected sendMessageHeader(MessageHeader header); // Receives a message header from the socket Expected receiveMessageHeader(); // Socket file descriptor int fd_socket_{-1}; // TCP connection state bool connected_{false}; // Maximum number of attempts for each I/O operation size_t maximum_attempts_{1}; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_NETWORK_TCP_CLIENT_SOCKET_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/network/tcp_codelet.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_NETWORK_TCP_CODELET_HPP_ #define NVIDIA_GXF_NETWORK_TCP_CODELET_HPP_ #include #include #include #include #include "gxf/network/tcp_server_socket.hpp" #include "gxf/serialization/entity_serializer.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/scheduling_terms.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { // Abstract codelet supporting asynchronous TCP client/server class TcpCodelet : public Codelet { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t tick() override; gxf_result_t stop() override; protected: // Asynchronously monitors client socket and receivers. If data is available from either source, // schedules the TcpServer via the AsynchronousSchedulingTerm. Also handles connecting client // socket. Expected monitor(); virtual Expected openSockets() = 0; virtual Expected reconnectSockets() = 0; virtual Expected closeSockets() = 0; Parameter>> receivers_; Parameter>> transmitters_; Parameter> entity_serializer_; Parameter address_; Parameter port_; Parameter timeout_ms_; Parameter timeout_text_; Parameter maximum_attempts_; Parameter max_msg_delay_ms_; Parameter max_duration_ms_; Parameter max_connection_attempts_; Parameter> async_scheduling_term_; int64_t timeout_ns_; // Maps channel IDs to transmitters std::unordered_map> channel_map_; // TCP client socket TcpClientSocket client_socket_; // Tracks monitor thread result std::future> monitor_future_; // Stores receivers with available data std::vector> available_receivers_; // Stores messages read from receivers std::vector rx_messages_; // Stores messages read from socket std::vector tx_messages_; // Time when last message was received Expected> last_msg_timestamp_ = Unexpected{GXF_UNINITIALIZED_VALUE}; // Time when monitor thread began Expected> monitor_start_timestamp_ = Unexpected{GXF_UNINITIALIZED_VALUE}; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_NETWORK_TCP_CODELET_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/network/tcp_server.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_NETWORK_TCP_SERVER_HPP_ #define NVIDIA_GXF_NETWORK_TCP_SERVER_HPP_ #include #include #include #include "gxf/network/tcp_codelet.hpp" namespace nvidia { namespace gxf { // Codelet that functions as a server in a TCP connection class TcpServer : public TcpCodelet { protected: Expected openSockets() override; Expected reconnectSockets() override; Expected closeSockets() override; private: // TCP server socket TcpServerSocket server_socket_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_NETWORK_TCP_SERVER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/network/tcp_server_socket.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_NETWORK_TCP_SERVER_SOCKET_HPP_ #define NVIDIA_GXF_NETWORK_TCP_SERVER_SOCKET_HPP_ #include #include "gxf/network/tcp_client_socket.hpp" namespace nvidia { namespace gxf { // Object for managing a TCP socket on the server side. // Connection must be established prior to use. // Uses a TcpClientSocket as a proxy for communication. class TcpServerSocket { public: TcpServerSocket(const char* address, uint16_t port) : address_{address}, port_{port}, socket_{-1} {} TcpServerSocket() : address_{"0.0.0.0"}, port_{0}, socket_{-1} {} ~TcpServerSocket() = default; TcpServerSocket(const TcpServerSocket& other) = delete; TcpServerSocket(TcpServerSocket&& other) = default; TcpServerSocket& operator=(const TcpServerSocket& other) = delete; TcpServerSocket& operator=(TcpServerSocket&& other) = default; // Initializes server socket. // Creates socket file descriptor. // Binds IP address to socket. // Listens for incoming connections on socket. Expected open(); // Deinitializes server socket. // Destroys socket file descriptor. Expected close(); // Attempts to connect to a TCP client. // Returns a TCP client socket that can be used as an endpoint. // Call will fail if there are no clients requesting to connect. Expected connect(); private: // Server address std::string address_; // Server port uint16_t port_; // Socket file descriptor int socket_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_NETWORK_TCP_SERVER_SOCKET_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/npp/nppi_mul_c.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_NPP_NPPI_MUL_C_HPP #define NVIDIA_GXF_NPP_NPPI_MUL_C_HPP #include #include "gxf/core/parameter_parser_std.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { // Multiplies a CUDA tensor with a constant factor using NPP. class NppiMulC : public Codelet { public: virtual ~NppiMulC() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t tick() override; private: Parameter> in_; Parameter> factor_; Parameter> pool_; Parameter> out_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/npp/nppi_set.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_NPP_NPPI_SET_HPP #define NVIDIA_GXF_NPP_NPPI_SET_HPP #include #include #include "gxf/core/parameter_parser_std.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { // Creates a CUDA tensor with constant values using NPP. class NppiSet : public Codelet { public: virtual ~NppiSet() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t tick() override; private: Parameter rows_; Parameter columns_; Parameter channels_; Parameter> pool_; Parameter> value_; Parameter> out_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/rmm/rmm_allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_RMM_RMM_ALLOCATOR_HPP_ #define NVIDIA_GXF_RMM_RMM_ALLOCATOR_HPP_ #include #include #include #include // NOLINT #include #include #include #include "common/assert.hpp" #include "common/logger.hpp" #include "gxf/core/parameter.hpp" #include "gxf/cuda/cuda_allocator.hpp" #include "gxf/std/resources.hpp" #include "rmm/device_buffer.hpp" #include "rmm/mr/device/cuda_async_memory_resource.hpp" #include "rmm/mr/device/pool_memory_resource.hpp" #include "rmm/mr/host/pinned_memory_resource.hpp" namespace nvidia { namespace gxf { // RMM based device memory allocator class RMMAllocator : public CudaAllocator { public: RMMAllocator() = default; ~RMMAllocator() = default; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t is_available_abi(uint64_t size) override; gxf_result_t is_rmm_available_abi(uint64_t size, MemoryStorageType type); gxf_result_t allocate_abi(uint64_t size, int32_t storage_type, void** pointer) override; gxf_result_t allocate_async_abi(uint64_t size, void** pointer, cudaStream_t stream) override; gxf_result_t free_async_abi(void* pointer, cudaStream_t stream) override; gxf_result_t free_abi(void* pointer) override; Expected get_pool_size(MemoryStorageType type) const override; private: Parameter device_memory_initial_size_; Parameter device_memory_max_size_; Parameter host_memory_initial_size_; Parameter host_memory_max_size_; Resource> gpu_device_; AllocatorStage stage_{AllocatorStage::kUninitialized}; cudaStream_t stream_ = {}; size_t device_max_memory_pool_size_; size_t host_max_memory_pool_size_; // Create a CUDA memory resource std::unique_ptr device_mr_; std::unique_ptr> pool_mr_device_; std::unique_ptr pinned_mr_; std::unique_ptr> pool_mr_host_; mutable std::shared_mutex shared_mutex_; std::unordered_map> pool_map_ = {}; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_RMM_RMM_ALLOCATOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/component_serializer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_COMPONENT_SERIALIZER_HPP_ #define NVIDIA_GXF_SERIALIZATION_COMPONENT_SERIALIZER_HPP_ #include #include // NOLINT #include #include "gxf/core/component.hpp" #include "gxf/serialization/endpoint.hpp" #include "gxf/serialization/tid_hash.hpp" namespace nvidia { namespace gxf { // Interface for serializing components class ComponentSerializer : public Component { public: virtual ~ComponentSerializer() = default; // Checks if the serializer supports the given component type // Searches serializer map by default virtual gxf_result_t is_supported_abi(gxf_tid_t tid) { return getSerializer(tid) ? GXF_SUCCESS : GXF_FAILURE; } // Serializes component and writes to endpoint // Returns the size of the serialized component in bytes // Uses functions in serializer map by default virtual gxf_result_t serialize_component_abi(gxf_uid_t cid, Endpoint* endpoint, uint64_t* size); // Reads from endpoint and deserializes component // Uses functions in serializer map by default virtual gxf_result_t deserialize_component_abi(gxf_uid_t cid, Endpoint* endpoint); // C++ API wrappers bool isSupported(gxf_tid_t tid) { return is_supported_abi(tid) == GXF_SUCCESS; } Expected serializeComponent(UntypedHandle component, Endpoint* endpoint); Expected deserializeComponent(UntypedHandle component, Endpoint* endpoint); protected: // Serializer function handle // Takes a component pointer and an endpoint pointer as input // Returns the size of the serialized component in bytes using Serializer = std::function(void*, Endpoint*)>; // Deserializer function handle // Takes a component pointer and an endpoint pointer as input using Deserializer = std::function(void*, Endpoint*)>; // Returns a serializer for the given type ID Expected getSerializer(gxf_tid_t tid) const; // Returns a deserializer for the given type ID Expected getDeserializer(gxf_tid_t tid) const; // Adds a serializer for the given type ID Expected setSerializer(gxf_tid_t tid, Serializer serializer); // Adds a deserializer for the given type ID Expected setDeserializer(gxf_tid_t tid, Deserializer deserializer); // Removes a serializer for the given type ID Expected clearSerializer(gxf_tid_t tid) { return setSerializer(tid, nullptr); } // Removes a deserializer for the given type ID Expected clearDeserializer(gxf_tid_t tid) { return setDeserializer(tid, nullptr); } // Returns a serializer for the given type template Expected getSerializer() const { gxf_tid_t tid; return ExpectedOrCode(GxfComponentTypeId(context(), TypenameAsString(), &tid)) .and_then([&](){ return getSerializer(tid); }); } // Returns a deserializer for the given type template Expected getDeserializer() const { gxf_tid_t tid; return ExpectedOrCode(GxfComponentTypeId(context(), TypenameAsString(), &tid)) .and_then([&](){ return getDeserializer(tid); }); } // Adds a serializer for the given type template Expected setSerializer(Serializer serializer) { gxf_tid_t tid; return ExpectedOrCode(GxfComponentTypeId(context(), TypenameAsString(), &tid)) .and_then([&](){ return setSerializer(tid, serializer); }); } // Adds a deserializer for the given type template Expected setDeserializer(Deserializer deserializer) { gxf_tid_t tid; return ExpectedOrCode(GxfComponentTypeId(context(), TypenameAsString(), &tid)) .and_then([&](){ return setDeserializer(tid, deserializer); }); } // Removes a serializer for the given type template Expected clearSerializer(Serializer serializer) { gxf_tid_t tid; return ExpectedOrCode(GxfComponentTypeId(context(), TypenameAsString(), &tid)) .and_then([&](){ return clearSerializer(tid); }); } // Removes a deserializer for the given type template Expected clearDeserializer(Deserializer deserializer) { gxf_tid_t tid; return ExpectedOrCode(GxfComponentTypeId(context(), TypenameAsString(), &tid)) .and_then([&](){ return clearDeserializer(tid); }); } private: // Structure for organizing serialize-deserialize function pairs struct SerializerFunctions { Serializer serializer; Deserializer deserializer; }; // Table that maps component type ID to serializer functions std::unordered_map serializer_map_; // Mutex to guard concurrent access to serializer map mutable std::shared_timed_mutex mutex_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_COMPONENT_SERIALIZER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/endpoint.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_ENDPOINT_HPP_ #define NVIDIA_GXF_SERIALIZATION_ENDPOINT_HPP_ #include "gxf/core/component.hpp" #include "gxf/std/allocator.hpp" namespace nvidia { namespace gxf { // Interface for exchanging data external to an application graph class Endpoint : public Component { public: virtual ~Endpoint() = default; // Returns `GXF_SUCCESS` if endpoint can be written to virtual gxf_result_t is_write_available_abi() { return GXF_SUCCESS; } // Returns `GXF_SUCCESS` if endpoint can be read from virtual gxf_result_t is_read_available_abi() { return GXF_SUCCESS; } // Writes data to the endpoint and returns the number of bytes written virtual gxf_result_t write_abi(const void* data, size_t size, size_t* bytes_written) = 0; // Reads data from the endpoint and returns the number of bytes read virtual gxf_result_t read_abi(void* data, size_t size, size_t* bytes_read) = 0; // Writes pointer to the data and size of the data to a vector virtual gxf_result_t write_ptr_abi(const void* pointer, size_t size, MemoryStorageType type) { return GXF_NOT_IMPLEMENTED; } // C++ API wrappers bool isWriteAvailable(); bool isReadAvailable(); Expected write(const void* data, size_t size); Expected read(void* data, size_t size); Expected write_ptr(const void* pointer, size_t size, MemoryStorageType type); // Writes an object of type T to the endpoint template Expected writeTrivialType(const T* object) { return write(object, sizeof(T)); } // Reads an object of type T from the endpoint template Expected readTrivialType(T* object) { return read(object, sizeof(T)); } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_ENDPOINT_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/entity_recorder.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_ENTITY_RECORDER_HPP_ #define NVIDIA_GXF_SERIALIZATION_ENTITY_RECORDER_HPP_ #include #include "gxf/serialization/entity_serializer.hpp" #include "gxf/serialization/file_stream.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" namespace nvidia { namespace gxf { // Records incoming entities by serializaing and writing to a file. // Uses one file to store binary data and a second file as an index to enable random-access. class EntityRecorder : public Codelet { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t tick() override; private: Parameter> receiver_; Parameter> entity_serializer_; Parameter directory_; Parameter basename_; Parameter flush_on_tick_; // File stream for data index FileStream index_file_stream_; // File stream for binary data FileStream binary_file_stream_; // Offset into binary file size_t binary_file_offset_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_ENTITY_RECORDER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/entity_replayer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_ENTITY_REPLAYER_HPP_ #define NVIDIA_GXF_SERIALIZATION_ENTITY_REPLAYER_HPP_ #include #include "gxf/serialization/entity_serializer.hpp" #include "gxf/serialization/file_stream.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/scheduling_terms.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { // Replays entities by reading and deserializing from a file. // The file is processed sequentially and a single entity is published per tick. class EntityReplayer : public Codelet { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t tick() override; private: Parameter> transmitter_; Parameter> entity_serializer_; Parameter> boolean_scheduling_term_; Parameter directory_; Parameter basename_; Parameter batch_size_; Parameter ignore_corrupted_entities_; // File stream for entities FileStream entity_file_stream_; // File stream for index FileStream index_file_stream_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_ENTITY_REPLAYER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/entity_serializer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_ENTITY_SERIALIZER_HPP_ #define NVIDIA_GXF_SERIALIZATION_ENTITY_SERIALIZER_HPP_ #include "gxf/core/component.hpp" #include "gxf/serialization/endpoint.hpp" namespace nvidia { namespace gxf { // Interface for serializing entities class EntitySerializer : public Component { public: virtual ~EntitySerializer() = default; // Deserializes a received entity. // Returns the deserialized entity. virtual Expected deserialize_entity_header_abi( Endpoint* endpoint) = 0; // Serializes entity and writes to endpoint // Returns the size of the serialized entity in bytes virtual gxf_result_t serialize_entity_abi(gxf_uid_t eid, Endpoint* endpoint, uint64_t* size) = 0; // Reads from endpoint and deserializes entity virtual gxf_result_t deserialize_entity_abi(gxf_uid_t eid, Endpoint* endpoint) = 0; // C++ API wrappers Expected serializeEntity(Entity entity, Endpoint* endpoint); Expected deserializeEntity(Entity entity, Endpoint* endpoint); Expected deserializeEntity(gxf_context_t context, Endpoint* endpoint); }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_ENTITY_SERIALIZER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/file.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_FILE_HPP_ #define NVIDIA_GXF_SERIALIZATION_FILE_HPP_ #include #include #include #include "gxf/serialization/endpoint.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/memory_buffer.hpp" namespace nvidia { namespace gxf { // Wrapper around C file I/O API class File : public Endpoint { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t write_abi(const void* data, size_t size, size_t* bytes_written) override; gxf_result_t read_abi(void* data, size_t size, size_t* bytes_read) override; // Opens a file with the given mode // Uses parameter values if arguments are not specified Expected open(const char* path = nullptr, const char* mode = nullptr); // Closes the opened file Expected close(); // Clears the end-of-file and error indicators void clear(); // Returns true if the end-of-file indicator is set bool eof(); // Returns true if the error indicator is set bool error(); // Flushes the output buffer of the file stream Expected flush(); // Sets the file position to the given offset Expected seek(int offset, int position = SEEK_SET); // Returns the current file position Expected tell(); // Returns true if the file is open bool isOpen(); // Returns the configured file path const char* path(); // Returns the configured file mode const char* mode(); // Renames the file Expected rename(const char* path); // Prepends a timestamp to the file name // Uses local time zone by default and UTC if specified Expected addTimestamp(int64_t timestamp, bool utc = false); // Write-protects the file Expected writeProtect(); private: Parameter> allocator_; Parameter file_path_; Parameter file_mode_; Parameter buffer_size_; // File stream std::FILE* file_; // Stream buffer MemoryBuffer buffer_; // Mutex to guard concurrent access mutable std::recursive_mutex mutex_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_FILE_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/file_stream.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_FILE_STREAM_HPP_ #define NVIDIA_GXF_SERIALIZATION_FILE_STREAM_HPP_ #include #include #include #include "gxf/serialization/endpoint.hpp" namespace nvidia { namespace gxf { #pragma pack(push, 1) struct EntityIndex { uint64_t log_time; // Time when data was logged uint64_t data_size; // Size of data block uint64_t data_offset; // Location of data block }; #pragma pack(pop) // Graph endpoint that exchanges data using files // Input file path is used for reading (empty string to disable reading) // Output file path is used for writing (empty string to disable writing) // The same file can be used for both reading and writing class FileStream : public Endpoint { public: // Extension for index files static constexpr const char* kIndexFileExtension = ".gxf_index"; // Extension for binary files static constexpr const char* kBinaryFileExtension = ".gxf_entities"; FileStream(std::string input_file, std::string output_file) : input_file_path_{std::move(input_file)}, output_file_path_{std::move(output_file)} {} FileStream() = default; ~FileStream() = default; FileStream(const FileStream& other) = delete; FileStream(FileStream&& other) { *this = std::move(other); } FileStream& operator=(const FileStream& other) = delete; FileStream& operator=(FileStream&& other) { input_file_path_ = std::move(other.input_file_path_); output_file_path_ = std::move(other.output_file_path_); input_file_ = std::move(other.input_file_); output_file_ = std::move(other.output_file_); return *this; } Expected open(); Expected close(); gxf_result_t write_abi(const void* data, size_t size, size_t* bytes_written) override; gxf_result_t read_abi(void* data, size_t size, size_t* bytes_read) override; // Clears error state flags for input and output streams void clear(); // Flushes output stream buffer to file // Returns an error if operation failed Expected flush(); // Moves the output stream to the desired position Expected setWriteOffset(size_t index); // Returns the current position of the output stream Expected getWriteOffset(); // Moves the input stream to the desired position Expected setReadOffset(size_t index); // Returns the current position of the input stream Expected getReadOffset(); private: // Path to input file std::string input_file_path_; // Path to output file std::string output_file_path_; // Input file stream std::ifstream input_file_; // Output file stream std::ofstream output_file_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_FILE_STREAM_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/serialization_buffer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_SERIALIZATION_BUFFER_HPP_ #define NVIDIA_GXF_SERIALIZATION_SERIALIZATION_BUFFER_HPP_ #include #include "gxf/serialization/endpoint.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/memory_buffer.hpp" namespace nvidia { namespace gxf { // Buffer to hold serialized data class SerializationBuffer : public Endpoint { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override { return ToResultCode(buffer_.freeBuffer()); } gxf_result_t write_abi(const void* data, size_t size, size_t* bytes_written) override; gxf_result_t read_abi(void* data, size_t size, size_t* bytes_read) override; // Resizes the buffer Expected resize(size_t size, MemoryStorageType storage_type); // Type of the callback function to release memory passed to the SerializationBuffer // using the wrapMemory method using release_function_t = MemoryBuffer::release_function_t; // Wrap existing memory inside the SerializationBuffer. // A callback function of type release_function_t may be passed that will be called when the // SerializationBuffer wants to release the memory. Expected wrapMemory(void* pointer, uint64_t size, MemoryStorageType storage_type, release_function_t release_func); // The type of memory where the data is stored MemoryStorageType storage_type() const { return buffer_.storage_type(); } // Returns a read-only pointer to buffer data const byte* data() const { return buffer_.pointer(); } // Returns the capacity of the buffer size_t capacity() const { return buffer_.size(); } // Returns the number of bytes written to the buffer size_t size() const; // Resets buffer for sequential access void reset(); private: Parameter> allocator_; Parameter buffer_size_; Parameter storage_type_; // Data buffer MemoryBuffer buffer_; // Offset for sequential writes size_t write_offset_; // Offset for sequential reads size_t read_offset_; // Mutex to guard concurrent access mutable std::mutex mutex_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_SERIALIZATION_BUFFER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/std_component_serializer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_STD_COMPONENT_SERIALIZER_HPP_ #define NVIDIA_GXF_SERIALIZATION_STD_COMPONENT_SERIALIZER_HPP_ #include #include "common/endian.hpp" #include "gxf/cuda/cuda_common.hpp" #include "gxf/serialization/component_serializer.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/tensor.hpp" #include "gxf/std/timestamp.hpp" namespace nvidia { namespace gxf { // Serializer that supports serializaing Timestamps, Tensors, and integer components // Valid for sharing data between devices with the same endianness class StdComponentSerializer : public ComponentSerializer { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override { return GXF_SUCCESS; } private: // Configures all serializer functions Expected configureSerializers(); // Configures all deserializer functions Expected configureDeserializers(); // Serializes a nvidia::gxf::Timestamp Expected serializeTimestamp(Timestamp timestamp, Endpoint* endpoint); // Deserializes a nvidia::gxf::Timestamp Expected deserializeTimestamp(Endpoint* endpoint); // Serializes a nvidia::gxf::Tensor Expected serializeTensor(const Tensor& tensor, Endpoint* endpoint); // Deserializes a nvidia::gxf::Tensor Expected deserializeTensor(Endpoint* endpoint); // Serializes an integer template Expected serializeInteger(T value, Endpoint* endpoint) { if (!endpoint) { return Unexpected{GXF_ARGUMENT_NULL}; } T encoded = EncodeLittleEndian(value); return endpoint->writeTrivialType(&encoded); } // Deserializes an integer template Expected deserializeInteger(Endpoint* endpoint) { if (!endpoint) { return Unexpected{GXF_ARGUMENT_NULL}; } T encoded; return endpoint->readTrivialType(&encoded) .and_then([&]() { return DecodeLittleEndian(encoded); }); } Parameter> allocator_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_STD_COMPONENT_SERIALIZER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/std_entity_id_serializer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_STD_ENTITY_ID_SERIALIZER_HPP_ #define NVIDIA_GXF_SERIALIZATION_STD_ENTITY_ID_SERIALIZER_HPP_ #include #include "common/fixed_vector.hpp" #include "gxf/serialization/entity_serializer.hpp" namespace nvidia { namespace gxf { // Serializes and deserializes entity id. No component serializer used. class StdEntityIdSerializer : public EntitySerializer { public: #pragma pack(push, 1) struct EntityHeader { uint64_t entity_id; uint64_t sequence_number; }; #pragma pack(pop) gxf_result_t initialize() override { return GXF_SUCCESS; } gxf_result_t deinitialize() override { return GXF_SUCCESS; } Expected deserialize_entity_header_abi(Endpoint* endpoint) override; gxf_result_t serialize_entity_abi(gxf_uid_t eid, Endpoint* endpoint, uint64_t* size) override; gxf_result_t deserialize_entity_abi(gxf_uid_t eid, Endpoint* endpoint) override; private: // Sequence number for outgoing messages uint64_t outgoing_sequence_number_{0}; // Sequence number for incoming messages uint64_t incoming_sequence_number_{0}; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_STD_ENTITY_ID_SERIALIZER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/std_entity_serializer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_STD_ENTITY_SERIALIZER_HPP_ #define NVIDIA_GXF_SERIALIZATION_STD_ENTITY_SERIALIZER_HPP_ #include #include "common/fixed_vector.hpp" #include "gxf/serialization/component_serializer.hpp" #include "gxf/serialization/entity_serializer.hpp" #include "gxf/serialization/tid_hash.hpp" namespace nvidia { namespace gxf { // Serializes and deserializes entities with the provided component serializers // Little-endian is used over big-endian for better performance on x86 and arm platforms // Entities are serialized in the following format: // // | Entity Header || Component Header | Component Name | Component | ... | ... | ... | // // Components will be serialized in the order they are added to the entity // Components without serializers will be skipped // Each component will be preceded by a component header and the name of the component // The component itself will be serialized with a component serializer // An entity header will be added at the beginning class StdEntitySerializer : EntitySerializer { public: #pragma pack(push, 1) // Header preceding entities struct EntityHeader { uint64_t serialized_size; // Size of the serialized entity in bytes uint32_t checksum; // Checksum to verify the integrity of the message uint64_t sequence_number; // Sequence number of the message uint32_t flags; // Flags to specify delivery options uint64_t component_count; // Number of components in the entity uint64_t reserved; // Bytes reserved for future use }; #pragma pack(pop) #pragma pack(push, 1) // Header preceding components struct ComponentHeader { uint64_t serialized_size; // Size of the serialized component in bytes gxf_tid_t tid; // Type ID of the component uint64_t name_size; // Size of the component name in bytes }; #pragma pack(pop) gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override { return GXF_SUCCESS; } gxf_result_t serialize_entity_abi(gxf_uid_t eid, Endpoint* endpoint, uint64_t* size) override; gxf_result_t deserialize_entity_abi(gxf_uid_t eid, Endpoint* endpoint) override; Expected deserialize_entity_header_abi(Endpoint* endpoint) override; private: // Structure used to organize serializable components struct ComponentEntry; // Populates a list of component entries using a list of component handles Expected> createComponentEntries( const FixedVector& components); // Serializes a list of components and writes them to an endpoint // Returns the total number of bytes serialized Expected serializeComponents(const FixedVector& entries, Endpoint* endpoint); // Reads from an endpoint and deserializes a list of components Expected deserializeComponents(size_t component_count, Entity entity, Endpoint* endpoint); // Searches for a component serializer that supports the given type ID // Uses the first valid serializer found and caches it for subsequent lookups // Returns an Unexpected if no valid serializer is found Expected> findComponentSerializer(gxf_tid_t tid); Parameter, kMaxComponents>> component_serializers_; Parameter verbose_warning_; // Table that caches type ID with a valid component serializer std::unordered_map, TidHash> serializer_cache_; // Sequence number for outgoing messages uint64_t outgoing_sequence_number_ = 0; // Sequence number for incoming messages uint64_t incoming_sequence_number_ = 0; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_STD_ENTITY_SERIALIZER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/tests/serialization_tester.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_TESTS_SERIALIZATION_TESTER_HPP_ #define NVIDIA_GXF_SERIALIZATION_TESTS_SERIALIZATION_TESTER_HPP_ #include #include "gxf/serialization/entity_serializer.hpp" #include "gxf/serialization/serialization_buffer.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { namespace test { // Codelet that serializes incoming messages and stores them in a buffer // Messages are immediately deserialized from the buffer and published class SerializationTester : public Codelet { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override { return GXF_SUCCESS; } gxf_result_t deinitialize() override { return GXF_SUCCESS; } gxf_result_t tick() override; private: Parameter> input_; Parameter> output_; Parameter> entity_serializer_; Parameter> serialization_buffer_; }; } // namespace test } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_TESTS_SERIALIZATION_TESTER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/serialization/tid_hash.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_TID_HASH_HPP_ #define NVIDIA_GXF_SERIALIZATION_TID_HASH_HPP_ #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { // Hash function for gxf_tid_t that XORs upper 64 bits with lower 64 bits struct TidHash { size_t operator()(const gxf_tid_t& tid) const { return tid.hash1 ^ tid.hash2; } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_TID_HASH_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_ALLOCATOR_HPP #define NVIDIA_GXF_STD_ALLOCATOR_HPP #include #include "common/byte.hpp" #include "gxf/core/component.hpp" namespace nvidia { namespace gxf { enum struct MemoryStorageType { kHost = 0, // Host Pinned Memory kDevice = 1, // Cuda Device Memory kSystem = 2, // Heap Memory kCudaManaged = 3 // Cuda Managed Memory }; // Custom parameter parser for MemoryStorageType template <> struct ParameterParser { static Expected Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { const std::string value = node.as(); if (strcmp(value.c_str(), "Host") == 0) { return MemoryStorageType::kHost; } if (strcmp(value.c_str(), "Device") == 0) { return MemoryStorageType::kDevice; } if (strcmp(value.c_str(), "System") == 0) { return MemoryStorageType::kSystem; } if (strcmp(value.c_str(), "Managed") == 0) { return MemoryStorageType::kCudaManaged; } return Unexpected{GXF_ARGUMENT_OUT_OF_RANGE}; } }; // Custom parameter parser for MemoryStorageType template<> struct ParameterWrapper { static Expected Wrap(gxf_context_t context, const MemoryStorageType& value) { YAML::Node node(YAML::NodeType::Scalar); switch (value) { case MemoryStorageType::kHost: { node = std::string("Host"); break; } case MemoryStorageType::kDevice: { node = std::string("Device"); break; } case MemoryStorageType::kSystem: { node = std::string("System"); break; } case MemoryStorageType::kCudaManaged: { node = std::string("Managed"); break; } default: return Unexpected{GXF_PARAMETER_OUT_OF_RANGE}; } return node; } }; // Lifecycle stages of an allocator enum struct AllocatorStage : uint8_t { kUninitialized = 0, kInitializationInProgress = 1, kInitialized = 2, kDeinitializationInProgress = 3, }; // Provides allocation and deallocation of memory. struct Allocator : public Component { virtual ~Allocator() = default; virtual gxf_result_t is_available_abi(uint64_t size) = 0; virtual gxf_result_t allocate_abi(uint64_t size, int32_t type, void** pointer) = 0; virtual gxf_result_t free_abi(void* pointer) = 0; virtual uint64_t block_size_abi() const; // Returns true if the allocator can provide a memory block with the given size. bool is_available(uint64_t size); // Allocates a memory block with the given size. Expected allocate(uint64_t size, MemoryStorageType type); // Frees the given memory block. Expected free(byte* pointer); // Get the block size of this allocator, defaults to 1 for byte-based allocators uint64_t block_size() const; // Get the string value of allocator status const char* allocator_stage_str(AllocatorStage stage) const; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/async_buffer_receiver.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_ASYNC_BUFFER_RECEIVER_HPP_ #define NVIDIA_GXF_STD_ASYNC_BUFFER_RECEIVER_HPP_ #include #include "gxf/core/component.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/receiver.hpp" namespace nvidia { namespace gxf { /** * @brief A receiver which uses a Simpson's four-slot buffer to enable lockless/lock-free and * asynchronous communication. This receiver is designed to be used in a single producer and single * consumer scenario. * */ class AsyncBufferReceiver : public Receiver { public: gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t pop_abi(gxf_uid_t* uid) override; gxf_result_t push_abi(gxf_uid_t other) override; gxf_result_t peek_abi(gxf_uid_t* uid, int32_t index) override; gxf_result_t peek_back_abi(gxf_uid_t* uid, int32_t index) override; size_t capacity_abi() override; size_t size_abi() override; gxf_result_t receive_abi(gxf_uid_t* uid) override; size_t back_size_abi() override; gxf_result_t sync_abi() override; gxf_result_t sync_io_abi() override; private: // Resets the four-slot control variables. void reset_buffer(); Entity read_freshest(); // The following variables are used to implement a Simpson's four-slot buffer. Entity entity_data_[2][2]; // Four-slot control variables int32_t freshest_; int32_t reading_; // control bits int32_t slots_[2]; // To indicate whether the buffer has been filled at least once. After first-time, receiving end // will always be able to retrieve a value from the buffer. bool is_filled_first_time_; }; } // namespace gxf } // namespace nvidia #endif /* NVIDIA_GXF_STD_ASYNC_BUFFER_RECEIVER_HPP_ */ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/async_buffer_transmitter.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_ASYNC_BUFFER_TRANSMITTER_HPP_ #define NVIDIA_GXF_STD_ASYNC_BUFFER_TRANSMITTER_HPP_ #include #include "gxf/core/component.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { /** * @brief A transmitter which uses a Simpson's four-slot buffer to enable lockless and asynchronous * communication. This transmitter is designed to be used in a single producer and single consumer * scenario. * */ class AsyncBufferTransmitter : public Transmitter { public: gxf_result_t initialize() override; gxf_result_t pop_abi(gxf_uid_t* uid) override; gxf_result_t pop_io_abi(gxf_uid_t* uid) override; gxf_result_t push_abi(gxf_uid_t other) override; gxf_result_t peek_abi(gxf_uid_t* uid, int32_t index) override; size_t capacity_abi() override; size_t size_abi() override; gxf_result_t publish_abi(gxf_uid_t uid) override; size_t back_size_abi() override; gxf_result_t sync_abi() override; gxf_result_t sync_io_abi() override; private: Entity entity_; int size_; }; } // namespace gxf } // namespace nvidia #endif /* NVIDIA_GXF_STD_ASYNC_BUFFER_TRANSMITTER_HPP_ */ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/block_memory_pool.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_BLOCK_MEMORY_POOL_HPP #define NVIDIA_GXF_STD_BLOCK_MEMORY_POOL_HPP #include #include #include #include #include "gxf/std/allocator.hpp" #include "gxf/std/resources.hpp" namespace nvidia { namespace gxf { class FixedPoolUint64; // A memory pools which provides a maximum number of equally sized blocks of // memory. class BlockMemoryPool : public Allocator { public: BlockMemoryPool(); ~BlockMemoryPool(); gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t is_available_abi(uint64_t size) override; gxf_result_t allocate_abi(uint64_t size, int32_t type, void** pointer) override; gxf_result_t free_abi(void* pointer) override; gxf_result_t deinitialize() override; uint64_t block_size_abi() const override; // Returns the storage type of the memory blocks MemoryStorageType storage_type() const { return static_cast(storage_type_.get()); } // Returns the total number of blocks uint64_t num_blocks() const { return num_blocks_.get(); } private: Parameter storage_type_; Parameter block_size_; Parameter num_blocks_; Resource> gpu_device_; void* pointer_; std::unique_ptr stack_; std::mutex stack_mutex_; // Holds lifecycle stage of the allocator std::atomic stage_{AllocatorStage::kUninitialized}; int32_t dev_id_ = -1; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/clock.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_CLOCK_HPP_ #define NVIDIA_GXF_STD_CLOCK_HPP_ #include #include "gxf/core/component.hpp" namespace nvidia { namespace gxf { /// @brief Keeps track of time // // This clock is based on a steady clock however time can be scaled to run slower or faster. class Clock : public Component { public: virtual ~Clock() = default; /// @brief The current time of the clock. Time is measured in seconds. virtual double time() const = 0; /// @brief The current timestamp of the clock. Timestamps are measured in nanoseconds. virtual int64_t timestamp() const = 0; /// @brief Waits until the given duration has elapsed on the clock virtual Expected sleepFor(int64_t duration_ns) = 0; /// @brief Waits until the given target time virtual Expected sleepUntil(int64_t target_ns) = 0; }; /// @brief A clock which runs based on a realtime clock class RealtimeClock : public Clock { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; double time() const override; int64_t timestamp() const override; Expected sleepFor(int64_t duration_ns) override; Expected sleepUntil(int64_t target_time_ns) override; // Changes time scaling used by the clock. Expected setTimeScale(double time_scale); private: Parameter initial_time_offset_; Parameter initial_time_scale_; Parameter use_time_since_epoch_; std::chrono::time_point reference_; double time_offset_; double time_scale_; }; /// @brief A clock where time flow is controlled manually class ManualClock : public Clock { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; double time() const override; int64_t timestamp() const override; Expected sleepFor(int64_t duration_ns) override; Expected sleepUntil(int64_t target_time_ns) override; private: Parameter initial_timestamp_; int64_t current_time_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/codelet.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gxf/core/component.hpp" namespace nvidia { namespace gxf { // Codelets are special components which allow the execution of custom code. The user can // create her own codelets by deriving from this class and overriding the functions initialize, // start, tick, stop, and deinitialize. class Codelet : public Component { public: virtual ~Codelet() = default; // This function is called during the start phase of the codelet. It allows derived classes to // execute custom code during the start phase. This is a good place to obtain resources which // are necessary for ticking the codelet. This function is guaranteed to be called before the // first call to tick. virtual gxf_result_t start() { return GXF_SUCCESS; } // This function is called whenever the codelet is expected to do work, e.g. when an event was // received or periodically. The tick method can be specified with various other member functions. // This function is the main work horse of the codelet. virtual gxf_result_t tick() = 0; // This function is called during the stop phase of the codelet. It allows derived classes to // execute custom code during the stop phase. This is a good place to clean up any resources which // where obtained during 'start'. After the codelet is stopped it should be in the same state as // it was before 'start' was called. Be careful to not leave any unintended left overs as 'start' // might be called again afterwards. It is guaranteed that stop is called after the last // call to tick. When start was called stop will be called, too. virtual gxf_result_t stop() { return GXF_SUCCESS; } // Timestamp (in nanoseconds) of the beginning of the start, tick or stop function. The execution // timestamp does not change during the start, tick or stop function. int64_t getExecutionTimestamp() const { return execution_timestamp_; } // Similar to getExecutionTimestamp but returns time as a floating point number and using seconds // as unit. Equivalent to 'ToSeconds(getExecutionCount())'. double getExecutionTime() const { return execution_time_; } // The delta between the current execution time and the execution time of the previous execution. // During the start function this will return 0. double getDeltaTime() const { return delta_time_; } // Returns the number of times a codelet is executed. This will return 0 during start and 1 during // the first tick. int64_t getExecutionCount() const { return execution_count_; } // Returns true if this is the first time tick is called after start. bool isFirstTick() const { return getExecutionCount() == 1; } private: // Class is friend to allow EntityExecutor to call private member functions friend class EntityExecutor; // Called by EntityExecutor before each 'start' void beforeStart(int64_t timestamp); // Called by EntityExecutor before each 'tick' void beforeTick(int64_t timestamp); // Called by EntityExecutor before each 'stop' void beforeStop(); // The number of times the codelet tick function was called. int64_t execution_count_{0}; // The timestamp of the previous execution. Equal to 'execution_timestamp' during 'start'. int64_t previous_execution_timestamp_{0}; // The timestamp of the current execution in nanoseconds. int64_t execution_timestamp_{0}; // Same as execution_timestamp_ but in seconds and as a floating point. double execution_time_{0.0}; // The difference between the current and the previous execution time in seconds. double delta_time_{0.0}; }; } // namespace gxf } // namespace nvidia ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/complex.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_COMPLEX_HPP_ #define NVIDIA_GXF_STD_COMPLEX_HPP_ #include #include //NOLINT #include //NOLINT namespace nvidia { namespace gxf { using complex64 = cuda::std::complex; using complex128 = cuda::std::complex; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/component_allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_COMPONENT_ALLOCATOR_HPP #define NVIDIA_GXF_STD_COMPONENT_ALLOCATOR_HPP #include "gxf/core/expected.hpp" namespace nvidia { namespace gxf { // Base class for allocating components. class ComponentAllocator { public: virtual ~ComponentAllocator() = default; ComponentAllocator(const ComponentAllocator&) = delete; ComponentAllocator(ComponentAllocator&&) = delete; ComponentAllocator& operator=(const ComponentAllocator&) = delete; ComponentAllocator& operator=(ComponentAllocator&&) = delete; // Allocates a new component of the specific component type this allocator is handling. virtual gxf_result_t allocate_abi(void** out_pointer) = 0; // Deallocates a component which was previously allocated by this allocator. virtual gxf_result_t deallocate_abi(void* pointer) = 0; Expected allocate(); Expected deallocate(void* pointer); protected: ComponentAllocator() = default; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/component_factory.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_COMPONENT_FACTORY_HPP #define NVIDIA_GXF_STD_COMPONENT_FACTORY_HPP #include "gxf/core/expected.hpp" namespace nvidia { namespace gxf { // Base class for extension factories. An extension factory is used to create instances // of components. class ComponentFactory { public: virtual ~ComponentFactory() = default; ComponentFactory(const ComponentFactory&) = delete; ComponentFactory(ComponentFactory&&) = delete; ComponentFactory& operator=(const ComponentFactory&) = delete; ComponentFactory& operator=(ComponentFactory&&) = delete; // Allocates a component of the given type virtual gxf_result_t allocate_abi(gxf_tid_t tid, void** out_pointer) = 0; // Frees a component of the given type virtual gxf_result_t deallocate_abi(gxf_tid_t tid, void* pointer) = 0; Expected allocate(gxf_tid_t tid); Expected deallocate(gxf_tid_t tid, void* pointer); protected: ComponentFactory() = default; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/controller.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_CONTROLLER_HPP_ #define NVIDIA_GXF_STD_CONTROLLER_HPP_ #include "gxf/core/component.hpp" #include "gxf/std/scheduling_condition.hpp" namespace nvidia { namespace gxf { /// @brief The status returned by controller to executor deciding termination /// policy /// - GXF_EXECUTE_SUCCESS: executor resumes execution /// - GXF_EXECUTE_FAILURE_REPEAT: codelet fails and executor repeatedly execute /// this entity /// - GXF_EXECUTE_FAILURE_DEACTIVATE: codelet fails and executor deactivate this /// entity /// - GXF_EXECUTE_FAILURE: codelet fails and executor deactivates all the /// entities and stops the entire graph typedef enum { GXF_EXECUTE_SUCCESS = 0, GXF_EXECUTE_FAILURE_REPEAT = 1, GXF_EXECUTE_FAILURE_DEACTIVATE = 2, GXF_EXECUTE_FAILURE = 3, } gxf_execution_status_t; // Type to represent codelet::tick() result for behavior tree parent and // execution status for executor to use termination policy struct gxf_controller_status_t { entity_state_t behavior_status; gxf_execution_status_t exec_status; gxf_controller_status_t(entity_state_t b_status, gxf_execution_status_t e_status) : behavior_status(b_status), exec_status(e_status) {} gxf_controller_status_t() { behavior_status = GXF_BEHAVIOR_SUCCESS; exec_status = GXF_EXECUTE_SUCCESS; } }; // Interface for controlling entity's termination policy and entity's execution // status class Controller : public Component { public: virtual ~Controller() = default; // Return a struct encapsulating the determined behavior status and execution // status by the controller given the result of codelet's tick() virtual gxf_controller_status_t control(gxf_uid_t eid, Expected code) = 0; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_CONTROLLER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/cpu_thread.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_CPU_THREAD_HPP #define NVIDIA_GXF_STD_CPU_THREAD_HPP #include #include #include "gxf/core/component.hpp" namespace nvidia { namespace gxf { // Real-time scheduling policies supported by POSIX and Linux kernel enum class SchedulingPolicy : int32_t { kFirstInFirstOut = 1, // SCHED_FIFO supported by POSIX and Linux kernel kRoundRobin = 2, // SCHED_RR supported by POSIX and Linux kernel kDeadline = 6 // SCHED_DEADLINE supported by Linux kernel }; // Custom parameter parser for SchedulingPolicy template <> struct ParameterParser { static Expected Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { const std::string value = node.as(); if (strcmp(value.c_str(), "SCHED_FIFO") == 0) { return SchedulingPolicy::kFirstInFirstOut; } if (strcmp(value.c_str(), "SCHED_RR") == 0) { return SchedulingPolicy::kRoundRobin; } if (strcmp(value.c_str(), "SCHED_DEADLINE") == 0) { return SchedulingPolicy::kDeadline; } GXF_LOG_ERROR("Invalid scheduling policy: %s", value.c_str()); return Unexpected{GXF_ARGUMENT_OUT_OF_RANGE}; } }; // Custom parameter wrapper for SchedulingPolicy template<> struct ParameterWrapper { static Expected Wrap(gxf_context_t context, const SchedulingPolicy& value) { YAML::Node node(YAML::NodeType::Scalar); switch (value) { case SchedulingPolicy::kFirstInFirstOut: { node = std::string("SCHED_FIFO"); break; } case SchedulingPolicy::kRoundRobin: { node = std::string("SCHED_RR"); break; } case SchedulingPolicy::kDeadline: { node = std::string("SCHED_DEADLINE"); break; } default: GXF_LOG_ERROR("Invalid scheduling policy: %d", static_cast(value)); return Unexpected{GXF_PARAMETER_OUT_OF_RANGE}; } return node; } }; class CPUThread : public Component { public: gxf_result_t registerInterface(Registrar* registrar) override; bool pinned() const { return pin_entity_; } std::vector pinCores() const { const auto maybe_pin_cores = pin_cores_.try_get(); if (maybe_pin_cores) { return maybe_pin_cores.value(); } return {}; } Expected schedPolicy() const { return sched_policy_.try_get(); } Expected schedPriority() const { return sched_priority_.try_get(); } Expected schedRuntime() const { return sched_runtime_.try_get(); } Expected schedDeadline() const { return sched_deadline_.try_get(); } Expected schedPeriod() const { return sched_period_.try_get(); } // Helper method to check if real-time scheduling is used bool isRealtime() const { const auto maybe_sched_policy = sched_policy_.try_get(); if (maybe_sched_policy) { auto sched_policy_value = maybe_sched_policy.value(); return sched_policy_value == SchedulingPolicy::kFirstInFirstOut || sched_policy_value == SchedulingPolicy::kRoundRobin || sched_policy_value == SchedulingPolicy::kDeadline; } return false; } private: // Keep track of whether or not the component should be pinned to a worker thread Parameter pin_entity_; // CPU core IDs to pin the worker thread to (empty means no core pinning) Parameter> pin_cores_; // Real-time scheduling parameters (optional) // Real-time scheduling policy (kFirstInFirstOut, kRoundRobin, kDeadline) Parameter sched_policy_; // Thread priority (only for kFirstInFirstOut and kRoundRobin) Parameter sched_priority_; // Expected worst case execution time in nanoseconds (only for kDeadline) Parameter sched_runtime_; // Relative deadline in nanoseconds (only for kDeadline) Parameter sched_deadline_; // Period in nanoseconds (only for kDeadline) Parameter sched_period_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_CPU_THREAD_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/cuda_green_context.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_CUDA_GREEN_CONTEXT_HPP_ #define NVIDIA_GXF_STD_CUDA_GREEN_CONTEXT_HPP_ #include "cuda.h" #include #include #include #include "gxf/core/component.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/cuda_green_context_pool.hpp" namespace nvidia { namespace gxf { /** * @brief Holds and provides access to CUgreenCtx. CudaGreenContext is allocated and * recycled by CudaGreenContextPool */ class CudaGreenContext : public Component { public: CudaGreenContext() = default; ~CudaGreenContext(); gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; // Retrieves CUgreenCtx Expected greenContext() const; // Retrieves CUcontext that associated with this green context Expected cudaContext(); uint32_t index() const { return pool_index_; } CudaGreenContextPool* cudaGreenContextPool() const { return cuda_green_context_pool_.try_get().value(); } private: Parameter index_; Parameter> cuda_green_context_pool_; Parameter nvtx_identifier_; CUgreenCtx green_context_ = nullptr; CUcontext cuda_context_ = nullptr; uint32_t pool_index_ = 0; mutable std::shared_timed_mutex mutex_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_CUDA_GREEN_CONTEXT_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/cuda_green_context_pool.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_CUDA_GREEN_CONTEXT_POOL_HPP_ #define NVIDIA_GXF_STD_CUDA_GREEN_CONTEXT_POOL_HPP_ #include "cuda.h" #include #include #include #include #include #include #include "gxf/core/component.hpp" #include "gxf/core/expected.hpp" #include "gxf/std/resources.hpp" #define CHECK_CUDA_ERROR_RESULT(cu_result, fmt, ...) \ do { \ cudaError_t err = (cu_result); \ if (err != cudaSuccess) { \ GXF_LOG_ERROR(fmt ", cuda_error: %s, error_str: %s", ##__VA_ARGS__, \ cudaGetErrorName(err), cudaGetErrorString(err)); \ return GXF_FAILURE; \ } \ } while (0) #define CHECK_CUDA_DRV_ERROR(cu_result, driver_fn_table, fmt, ...) \ do { \ if (CUDA_SUCCESS != cu_result) { \ const char* errorName = nullptr; \ const char* errorString = nullptr; \ driver_fn_table.cuGetErrorName(cu_result, &errorName); \ driver_fn_table.cuGetErrorString(cu_result, &errorString); \ GXF_LOG_ERROR(fmt ", cuda driver API failed with error: %s:%s ", \ errorName, errorString); \ return GXF_FAILURE; \ } \ } while (0) #define GET_CUDA_DRV_API_PTR(func, version, name) \ do { \ cudaDriverEntryPointQueryResult driver_status; \ auto result = cudaGetDriverEntryPointByVersion(name, \ reinterpret_cast(&func), \ version, \ cudaEnableDefault, \ &driver_status); \ if (func == nullptr) { \ GXF_LOG_ERROR("Failed to load %s from CUDA runtime library, " \ "error[%d], driver_status: %d", name, result, driver_status); \ return GXF_FAILURE; \ } \ } while (0) namespace nvidia { namespace gxf { struct CudaDriverFunctionTable { CUresult (*cuDeviceGet)(CUdevice*, int) = nullptr; CUresult (*cuGreenCtxGetDevResource)(CUgreenCtx, CUdevResource*, CUdevResourceType) = nullptr; CUresult (*cuGreenCtxCreate)(CUgreenCtx*, CUdevResourceDesc, CUdevice, unsigned int) = nullptr; CUresult (*cuDevSmResourceSplitByCount)( CUdevResource*, unsigned int*, const CUdevResource*, CUdevResource*, unsigned int, unsigned int) = nullptr; CUresult (*cuCtxFromGreenCtx)(CUcontext*, CUgreenCtx) = nullptr; CUresult (*cuDevResourceGenerateDesc)( CUdevResourceDesc*, CUdevResource*, unsigned int) = nullptr; CUresult (*cuDeviceGetDevResource)( CUdevice, CUdevResource*, CUdevResourceType) = nullptr; CUresult (*cuGetErrorName)(CUresult, const char**) = nullptr; CUresult (*cuGetErrorString)(CUresult, const char**) = nullptr; }; /** * @brief A pool containing a specified number of CUDA Green Contexts on a single device. */ class CudaGreenContextPool : public Component { public: CudaGreenContextPool() = default; ~CudaGreenContextPool(); gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t registerInterface(Registrar* registrar) override; Expected getGreenContext(uint32_t index); Expected getCudaContext(uint32_t index); Expected getPartitionSms(uint32_t index); Expected getDefaultContextIndex(); Expected getDefaultContext(); Expected getDeviceTotalSms(uint32_t index); private: gxf_result_t reserveGreenContexts(int32_t compute_capability_major); gxf_result_t loadCudaDriver(); Resource> gpu_device_; Parameter green_context_flags_; Parameter num_partitions_; Parameter min_sm_count_; Parameter> sms_per_partition_; Parameter nvtx_identifier_; Parameter default_context_; std::atomic initialized_{false}; std::mutex mutex_; std::vector green_context_; std::vector cu_context_; uint32_t max_sm_count_ = 0; int32_t dev_id_ = -1; uint32_t default_index_ = 0; // Function table for CUDA driver symbols CudaDriverFunctionTable cuda_driver_fn_table_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_CUDA_GREEN_CONTEXT_POOL_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/default_extension.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_DEFAULT_EXTENSION_HPP_ #define NVIDIA_GXF_STD_DEFAULT_EXTENSION_HPP_ #include #include #include #include #include "common/fixed_vector.hpp" #include "common/type_name.hpp" #include "gxf/core/expected.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/component_allocator.hpp" #include "gxf/std/extension.hpp" #include "gxf/std/new_component_allocator.hpp" namespace nvidia { namespace gxf { namespace detail { struct VoidBaseHelper {}; template struct BaseTypenameAsString { static const char* Value() { return TypenameAsString(); } }; template <> struct BaseTypenameAsString { static constexpr const char* Value() { return ""; } }; } // namespace detail // A standard component factor for GXF extensions. It keeps track of all components in the // extensions and provides mechanisms to create components. class DefaultExtension : public Extension { public: ~DefaultExtension() override = default; // Sets the extension metadata info gxf_result_t setInfo_abi(gxf_tid_t tid, const char* name, const char* desc, const char* author, const char* version, const char* license) override; // Capture extension display metadata gxf_result_t setDisplayInfo_abi(const char* display_name, const char* category, const char* brief) override; // Gets description of the extension and list of components it provides gxf_result_t getInfo_abi(gxf_extension_info_t* info) override; gxf_result_t checkInfo_abi() override; // Gets description of specified component (No parameter information) gxf_result_t getComponentInfo_abi(const gxf_tid_t tid, gxf_component_info_t* info) override; gxf_result_t registerComponents_abi(gxf_context_t context) override; gxf_result_t hasComponent_abi(const gxf_tid_t& tid) override; gxf_result_t getComponentTypes_abi(gxf_tid_t* pointer, size_t* size) override; gxf_result_t allocate_abi(gxf_tid_t tid, void** out_pointer) override; gxf_result_t deallocate_abi(gxf_tid_t tid, void* pointer) override; gxf_result_t getParameterInfo_abi(gxf_context_t context, const gxf_tid_t cid, const char* key, gxf_parameter_info_t* info) override; gxf_tid_t tid () const { return tid_; } template Expected add(gxf_tid_t tid, const char* description, const char* display_name = "", const char* brief = "") { static_assert(std::is_same::value || std::is_base_of::value, "The given base class is not actually a base class"); static_assert(!std::is_base_of::value || (std::is_base_of::value || std::is_same::value), "If a component derives from Codelet then its base class also needs to derive " "from Codelet. Have you used Component as base class instead of Codelet?"); if (find(tid)) { return Unexpected{GXF_FACTORY_DUPLICATE_TID}; } std::string display_name_str{display_name}; if (display_name_str.length() > 50) { GXF_LOG_ERROR("Component display name '%s' exceeds 50 characters", display_name); return Unexpected{GXF_ARGUMENT_OUT_OF_RANGE}; } std::string brief_str{brief}; if (brief_str.length() > 128) { GXF_LOG_ERROR("Component brief '%s' exceeds 128 characters", brief); return Unexpected{GXF_ARGUMENT_OUT_OF_RANGE}; } std::string description_str{description}; if (description_str.length() > 1026) { GXF_LOG_ERROR("Component description '%s' exceeds 1026 characters", description); return Unexpected{GXF_ARGUMENT_OUT_OF_RANGE}; } auto result = entries_.push_back({ tid, TypenameAsString(), detail::BaseTypenameAsString::Value(), description_str, display_name_str, brief_str, std::is_abstract::value ? nullptr : std::make_unique>()}); if (!result) { GXF_LOG_WARNING("Exceeding maximum number of components"); return Unexpected{GXF_EXCEEDING_PREALLOCATED_SIZE}; } return Success; } private: struct Entry { gxf_tid_t tid; std::string name; std::string base; std::string description; std::string display_name; std::string brief; std::unique_ptr allocator; }; Expected find(const gxf_tid_t& tid); FixedVector entries_; gxf_tid_t tid_{GxfTidNull()}; std::string name_; std::string description_; std::string author_; std::string extension_version_; std::string gxf_core_version_{kGxfCoreVersion}; // FIXME: Use setInfo() api to set this post 2.3 std::string license_; std::string display_name_; std::string category_; std::string brief_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_DEFAULT_EXTENSION_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/dlpack_utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "dlpack/dlpack.h" #include "gxf/core/expected.hpp" namespace nvidia { namespace gxf { // Determine the GPU device (if any) associated with a raw pointer Expected DLDeviceFromPointer(void* ptr); /** * @brief Fill strides from the given DLTensor object. * * The following fields are used to fill strides: * * - ndim * - shape * - dtype * * If tensor's strides is nullptr, `strides` argument is filled with the calculated strides of the * given DLTensor object. Otherwise, `strides` argument is filled with the given DLTensor object's * strides. `strides` vector would be resized to the size of `ndim` field of the given DLTensor * object. * * @param tensor DLTensor object that holds information to fill strides. * @param[out] strides Strides to fill. * @param to_num_elments If true, the strides in `strides` argument are in number of elements, not * bytes (default: false). */ void ComputeDLPackStrides(const DLTensor& tensor, std::vector& strides, bool to_num_elements = false); // Return DLDataType object from a NumPy type string. Expected DLDataTypeFromTypeString(const std::string& typestr); /** * @brief Return a string providing the basic type of the homogeneous array in NumPy. * * Note: This method assumes little-endian for now. * * @return A const character pointer that represents a string */ Expected numpyTypestr(const DLDataType dtype); } // namespace gxf } // namespace nvidia ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/double_buffer_receiver.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef DOUBLE_BUFFER_RECEIVER_HPP #define DOUBLE_BUFFER_RECEIVER_HPP #include #include "gxf/core/component.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/gems/staging_queue/staging_queue.hpp" #include "gxf/std/receiver.hpp" namespace nvidia { namespace gxf { // A receiver which uses a double-buffered queue where new messages are first pushed to a // backstage. Incoming messages are not immediately available and need to be moved to the mainstage // first. class DoubleBufferReceiver : public Receiver { public: using queue_t = ::gxf::staging_queue::StagingQueue; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t pop_abi(gxf_uid_t* uid) override; gxf_result_t push_abi(gxf_uid_t other) override; gxf_result_t peek_abi(gxf_uid_t* uid, int32_t index) override; gxf_result_t peek_back_abi(gxf_uid_t* uid, int32_t index) override; size_t capacity_abi() override; size_t size_abi() override; gxf_result_t receive_abi(gxf_uid_t* uid) override; size_t back_size_abi() override; gxf_result_t sync_abi() override; gxf_result_t sync_io_abi() override; Parameter capacity_; Parameter policy_; private: std::unique_ptr queue_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/double_buffer_transmitter.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef DOUBLE_BUFFER_TRANSMITTER_HPP #define DOUBLE_BUFFER_TRANSMITTER_HPP #include #include "gxf/core/component.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/gems/staging_queue/staging_queue.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { // A transmitter which uses a double-buffered queue where messages are pushed to a backstage after // they are published. Outgoing messages are not immediately available and need to be // moved to the backstage first. class DoubleBufferTransmitter : public Transmitter { public: using queue_t = ::gxf::staging_queue::StagingQueue; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t pop_abi(gxf_uid_t* uid) override; gxf_result_t pop_io_abi(gxf_uid_t* uid) override; gxf_result_t push_abi(gxf_uid_t other) override; gxf_result_t peek_abi(gxf_uid_t* uid, int32_t index) override; size_t capacity_abi() override; size_t size_abi() override; gxf_result_t publish_abi(gxf_uid_t uid) override; size_t back_size_abi() override; gxf_result_t sync_abi() override; gxf_result_t sync_io_abi() override; Parameter capacity_; Parameter policy_; private: std::unique_ptr queue_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/eos.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef EOS_HPP #define EOS_HPP #include #include "gxf/core/entity.hpp" namespace nvidia { namespace gxf { // A component which represents an end-of-stream notification class EndOfStream { public: // Returns the stream which generated the notification. Negative value indicates // pipeline/graph EoS. Non-negative value indicates individual stream EoS int64_t stream_id() { return stream_id_; } void stream_id(int64_t stream_id) { stream_id_ = stream_id; } EndOfStream() = default; ~EndOfStream() = default; EndOfStream(const EndOfStream&) = delete; EndOfStream(EndOfStream&& other) { *this = std::move(other); } EndOfStream& operator=(const EndOfStream&) = delete; EndOfStream& operator=(EndOfStream&& other) { stream_id_ = other.stream_id_; return *this; } // Factory method to create EOS message entity static Expected createEoSMessage(gxf_context_t context, int64_t stream_id = -1) { Expected message = Entity::New(context); if (!message) { return message; } auto eos = message.value().add(); if (!eos) { return ForwardError(eos); } eos.value()->stream_id_ = stream_id; return message; } private: int64_t stream_id_ = -1; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/event_based_scheduler.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_EVENT_BASED_SCHEDULER_HPP_ #define NVIDIA_GXF_STD_EVENT_BASED_SCHEDULER_HPP_ #include #include #include #include #include #include #include #include #include // NOLINT #include #include #include #include #include #include "cuda.h" #include "common/fixed_map.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/clock.hpp" #include "gxf/std/cpu_thread.hpp" #include "gxf/std/cuda_green_context_pool.hpp" #include "gxf/std/gems/event_list/unique_event_list.hpp" #include "gxf/std/gems/staging_queue/staging_queue.hpp" #include "gxf/std/gems/timed_job_list/timed_job_list.hpp" #include "gxf/std/resources.hpp" #include "gxf/std/scheduler.hpp" #include "gxf/std/scheduling_condition.hpp" namespace nvidia { namespace gxf { // Forward declarations class EntityExecutor; /// @brief Event based scheduler /// /// The scheduler requires a Clock to keep track of time. It spawns a dispatcher thread and several /// worker threads as configured. Dispatcher thread checks condition of entities and place them in /// worker queue if they are ready to run or have expected time to run. class EventBasedScheduler : public Scheduler { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t prepare_abi(EntityExecutor* executor) override; gxf_result_t schedule_abi(gxf_uid_t eid) override; gxf_result_t unschedule_abi(gxf_uid_t eid) override; gxf_result_t runAsync_abi() override; gxf_result_t stop_abi() override; gxf_result_t wait_abi() override; gxf_result_t event_notify_abi(gxf_uid_t eid, gxf_event_t event) override; gxf_result_t notifyDispatcher(gxf_uid_t eid = kNullUid); private: // Enum to indicate if a worker thread has acquired an entity for execution or not enum class EntityOwnership : uint8_t { kFree = 0, kAcquired }; class ScheduleEntity { public: ScheduleEntity(gxf_uid_t eid, const char * name) { eid_ = eid; name_ = std::string(name); condition_ = SchedulingCondition{SchedulingConditionType::READY, 0}; ownership_ = EntityOwnership::kFree; queue_index_ = -1; thread_pool_id_ = -1; thread_id_ = kDefaultThreadPoolThreadId; unschedule_ = false; is_present_in_ready_queue_ = false; cuda_context_ = nullptr; cuda_green_context_pool_ = nullptr; } void updateCondition() { condition_ = SchedulingCondition{SchedulingConditionType::READY, 0}; } Expected tryToAcquire(void) { EntityOwnership free = EntityOwnership::kFree; if (ownership_.compare_exchange_strong(free, EntityOwnership::kAcquired)) { return Success; } return Unexpected{GXF_FAILURE}; } Expected releaseOwnership(void) { EntityOwnership acquired = EntityOwnership::kAcquired; if (ownership_.compare_exchange_strong(acquired, EntityOwnership::kFree)) { return Success; } return Unexpected{GXF_FAILURE}; } int32_t queue_index_; gxf_uid_t eid_; SchedulingCondition condition_; std::string name_; std::atomic ownership_; int32_t thread_pool_id_; gxf_uid_t thread_id_; bool unschedule_; std::shared_timed_mutex ready_queue_sync_mutex_; bool is_present_in_ready_queue_; CUcontext cuda_context_ = nullptr; CudaGreenContextPool* cuda_green_context_pool_ = nullptr; }; std::unordered_map> entities_; struct TimeStat { std::atomic execTime = {0}; std::atomic waitTime = {0}; std::atomic execCount = {0}; }; struct TimeStat dispatcherStats; struct TimeStat workerStats; // operations from multiple worker threads static constexpr int64_t kMsToNs = 1'000'000l; // Convenient constant of 1 ms = 1e6 ns static constexpr int64_t kMaxSlipNs = 1 * kMsToNs; // Max slip tolerance set to 1 ms static constexpr size_t kMaxThreads = 128; // Max number of worker threads // Common thread id for all the worker threads in default thread pool static constexpr int64_t kDefaultThreadPoolThreadId = -1; // Position of ready queue for threads belonging to default thread pool static constexpr int64_t kDefaultThreadPoolQueueIndex = 0; // Entrance for dispatcher threads void dispatcherThreadEntrance(); // notify the dispatcher thread // Move entity to some queue void dispatchEntity(std::shared_ptr e); void dispatchEntityAsync(std::shared_ptr e); // Entrance for async event handler thread void asyncEventThreadEntrance(); // Entrance for worker threads void workerThreadEntrance(ThreadPool* pool, int64_t thread_number, gxf_uid_t cpu_thread_cid = kUnspecifiedUid); // Checks if need to stop due to no active entities or expiration bool checkEndingCriteria(int64_t timestamp); // Updates condition of specific entity id and keep track of how many entities are good to run void updateCondition(std::shared_ptr e, const SchedulingCondition& next_condition); // stops all async threads and deactivates all the entities gxf_result_t stopAllThreads(); // stops all jobs queued in dispatcher and workers void stopAllJobs(); // returns the current state of the scheduler as string const char* schedulerStateString(); // cache thread info for pinned job into resources_ and set cuda context if provided gxf_result_t prepareResourceMapStrict(std::shared_ptr e); // index of the ready queue in the ready_wait_time_jobs_ vector where entity is supposed to go uint64_t getReadyCount(); // Helper functions for configuring worker threads gxf_result_t configureThread(gxf_uid_t thread_uid, gxf_uid_t cpu_thread_cid); gxf_result_t setCPUAffinity(const std::vector& cpu_cores); bool isRealtimeCPUThread(gxf_uid_t cpu_thread_cid); // Load CUDA Driver API functions through runtime API gxf_result_t loadDriverFunctions(); // Parameters Parameter> clock_; Parameter max_duration_ms_; Parameter stop_on_deadlock_; Parameter stop_on_deadlock_timeout_; Parameter worker_thread_number_; Parameter thread_pool_allocation_auto_; Parameter worker_thread_name_id_; // CPU core IDs to pin the worker threads to (empty means no core pinning) Parameter> pin_cores_; EntityExecutor* executor_ = nullptr; Entity default_thread_pool_entity_; ThreadPool* default_thread_pool_; // thread pool set including default pool and added pools std::set thread_pool_set_; // map for storing the relevant ready_wait_queue FixedMap thread_queue_mapping_; gxf_result_t thread_error_code_; // A thread to dispatch jobs to worker pool std::thread dispatcher_thread_; // A thread to trigger exit after max time duration std::thread max_duration_thread_; // Mutex to synchronize dispatcher thread std::mutex dispatcher_sync_mutex_; // Mutex to synchronize max duration thread std::mutex max_duration_sync_mutex_; // instances of dispatcher/worker threads. 0 index would be async event handler thread. std::vector async_threads_; // Keep track of the timestamp that the scheduler started working for checking expiration int64_t start_timestamp_ = 0; // Queue with execution time for jobs to execute std::vector>> ready_wait_time_jobs_; // synchronize entities std::mutex external_event_notification_mutex_; std::mutex internal_event_notification_mutex_; // Mutex to synchronize worker thread pool std::mutex thread_sync_mutex_; std::condition_variable thread_sync_cv_; // Keep track of asynchronous external events std::unique_ptr> external_event_notified_; // Holds entities waiting for some event std::unique_ptr> event_waiting_; // Holds entities waiting for custom conditions std::unique_ptr> waiting_; // Keep track of asynchronous internal events std::unique_ptr> internal_event_notified_; // Running count of entities in flight / execution std::atomic running_threads_{0}; std::condition_variable external_event_notification_cv_; std::condition_variable internal_event_notification_cv_; std::condition_variable max_duration_thread_cv_; // enum type to represent scheduler state changes enum class State : uint8_t { kNotStarted = 0, // Scheduler has not started execution yet, starts during runAsync_abi() kRunning, // Execution threads are running kStopping, // Ending criteria reached, execution threads are doing pending jobs kStopped, // Scheduler has stopped }; std::atomic state_{State::kNotStarted}; std::mutex state_change_mutex_; std::condition_variable work_done_cv_; // latest timestamp from last should_stop == false int64_t last_no_stop_ts_ = 0; // maintain last no stop timestamp, and check if need to update should_stop gxf_result_t stop_on_deadlock_timeout(const int64_t timeout, const int64_t now, bool& should_stop); // Deadlock detection grace period end timestamp int64_t grace_end_timestamp_ = 0; // Armed flag to require two consecutive deadlock checks before exiting bool deadlock_armed_ = false; // CUDA Driver API CUresult (*fnCuCtxPushCurrent)(CUcontext) = nullptr; CUresult (*fnCuCtxPopCurrent)(CUcontext*) = nullptr; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_EVENT_BASED_SCHEDULER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/extension.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_EXTENSION_HPP #define NVIDIA_GXF_STD_EXTENSION_HPP #include "gxf/core/expected.hpp" #include "gxf/std/component_factory.hpp" namespace nvidia { namespace gxf { // Interface used for extensions. An extension class is holding information about the extension // and allows creation of components which are provided by the extension. class Extension : public ComponentFactory { public: virtual ~Extension() = default; Extension(const Extension&) = delete; Extension(Extension&&) = delete; Extension& operator=(const Extension&) = delete; Extension& operator=(Extension&&) = delete; // Capture extension metadata virtual gxf_result_t setInfo_abi(gxf_tid_t tid, const char* name, const char* desc, const char* author, const char* version, const char* license) = 0; // Capture extension display metadata virtual gxf_result_t setDisplayInfo_abi(const char* display_name, const char* category, const char* brief) = 0; // Check if extension metadata has been captured virtual gxf_result_t checkInfo_abi() = 0; // Gets description of the extension and list of components it provides virtual gxf_result_t getInfo_abi(gxf_extension_info_t* info) = 0; // Registers all components in the extension with the given context. virtual gxf_result_t registerComponents_abi(gxf_context_t context) = 0; // Checks if a component is present in the extension or not virtual gxf_result_t hasComponent_abi(const gxf_tid_t& tid) = 0; // Gets a list with IDs of all types which are registered with this factory. virtual gxf_result_t getComponentTypes_abi(gxf_tid_t* pointer, size_t* size) = 0; // Gets description of specified component (No parameter information) virtual gxf_result_t getComponentInfo_abi(const gxf_tid_t tid, gxf_component_info_t* info) = 0; // Gets description of specified parameter virtual gxf_result_t getParameterInfo_abi(gxf_context_t context, const gxf_tid_t cid, const char* key, gxf_parameter_info_t* info) = 0; Expected registerComponents(gxf_context_t context); Expected hasComponent(const gxf_tid_t& tid); Expected getComponentTypes(gxf_tid_t* pointer, size_t* size); Expected setInfo(gxf_tid_t tid, const char* name, const char* desc, const char* author, const char* version, const char* license); Expected setDisplayInfo(const char* display_name, const char* category, const char* brief); Expected checkInfo(); Expected getInfo(gxf_extension_info_t* info); Expected getComponentInfo(const gxf_tid_t tid, gxf_component_info_t* info); Expected getParameterInfo(gxf_context_t context, const gxf_tid_t cid, const char* key, gxf_parameter_info_t* info); protected: Extension() = default; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/extension_factory_helper.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_FACTORY_HPP #define NVIDIA_GXF_CORE_FACTORY_HPP #include #include #include "gxf/core/expected.hpp" #include "gxf/std/default_extension.hpp" // Helper macro to create an extensions factory. Every component in this extensions must be // explicitly registered. Otherwise it can not be used by GXF applications. // // A component can be registered using the macro GXF_EXT_FACTORY_ADD. For each // component the base class need to be specified. Components base classes must be registered before // they can be used as a base class in a component registration. If a component does not have a base // class the macro GXF_EXT_FACTORY_ADD_0 is used instead. // // Components can have at most one base class. Multiple base classes are not supported. // // Every component must be registered with a unique 128-bit identifier. The identifier must be // unique across all existing extensions. // // Note that the extension factory can also be created manually without using these macros. // // Usage example: // GXF_EXT_FACTORY_BEGIN(0x8ec2d5d6b5df48bf, 0x8dee0252606fdd7e, "1.0.0") // GXF_EXT_FACTORY_SET_INFO("Extension Name", "Extension Desc", "Author", "LICENSE") // GXF_EXT_FACTORY_ADD(0x792151bf31384603, 0xa9125ca91828dea8, // nvidia::gxf::Queue, nvidia::gxf::Component, // "Interface for storing entities in a queue"); // GXF_EXT_FACTORY_ADD(0xc30cc60f0db2409d, 0x92b6b2db92e02cce, // nvidia::gxf::Transmitter, nvidia::gxf::Queue, // "Interface for publishing entities"); // ... // GXF_EXT_FACTORY_END() #define GXF_EXT_FACTORY_BEGIN() \ namespace { \ nvidia::gxf::Expected> \ CreateComponentFactory() { \ auto factory = std::make_unique(); \ if (!factory) { return nvidia::gxf::Unexpected{GXF_OUT_OF_MEMORY}; } \ // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_SET_INFO(H1, H2, NAME, DESC, AUTHOR, VERSION, LICENSE) \ { \ const nvidia::gxf::Expected result = factory->setInfo({(H1), (H2)}, NAME, DESC, \ AUTHOR, VERSION, LICENSE); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ } \ // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_SET_DISPLAY_INFO(DISPLAY_NAME, CATEGORY, BRIEF) \ { \ const nvidia::gxf::Expected result = factory->setDisplayInfo(DISPLAY_NAME, CATEGORY, \ BRIEF); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ } // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_ADD_0(H1, H2, TYPE, DESC) \ { \ const nvidia::gxf::Expected result = factory->add({(H1), (H2)}, DESC); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ } \ // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_ADD_0_VERBOSE(H1, H2, TYPE, DISPLAY_NAME, BRIEF, DESC) \ { \ const nvidia::gxf::Expected result = factory->add({(H1), (H2)}, DESC, \ DISPLAY_NAME, BRIEF); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ } // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_ADD_0_LITE(H1, H2, TYPE) \ { \ const nvidia::gxf::Expected result = factory->add({(H1), (H2)}, ""); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ } \ // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_ADD(H1, H2, TYPE, BASE, DESC) \ { \ const nvidia::gxf::Expected result = factory->add({(H1), (H2)}, DESC); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ } \ // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_ADD_VERBOSE(H1, H2, TYPE, BASE, DISPLAY_NAME, BRIEF, DESC) \ { \ const nvidia::gxf::Expected result = factory->add({(H1), (H2)}, DESC, \ DISPLAY_NAME, BRIEF); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ } // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_ADD_LITE(H1, H2, TYPE, BASE) \ { \ const nvidia::gxf::Expected result = factory->add({(H1), (H2)}, ""); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ } \ // See GXF_EXT_FACTORY_BEGIN for more information. #define GXF_EXT_FACTORY_END() \ const nvidia::gxf::Expected result = factory->checkInfo(); \ if (!result) { return nvidia::gxf::ForwardError(result); } \ return std::move(factory); \ } \ } /* namespace */ \ \ extern "C" { \ gxf_result_t GxfExtensionFactory(void** result) { \ static nvidia::gxf::Expected> s_factory \ = CreateComponentFactory(); \ if (!s_factory) { return s_factory.error(); } \ *result = s_factory.value().get(); \ return GXF_SUCCESS; \ } \ } /* extern "C" */ \ #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/event_list/event_list.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_EVENT_LIST_HPP_ #define NVIDIA_GXF_EVENT_LIST_HPP_ #include #include #include #include #include #include #include #include #include #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { // A simple thread safe list implementation to store and retrieve events template class EventList { public: EventList() = default; EventList(const EventList&) = delete; EventList& operator=(const EventList&) = delete; // Adds an item on to the event list void pushEvent(T item) { std::lock_guard lock(list_mutex_); list_.push_back(item); } // Removes an event from the list if it exists and returns true, // returns false otherwise void removeEvent(T item) { std::lock_guard lock(list_mutex_); for (auto it = list_.begin(); it != list_.end();) { if (*it == item) { // remove all instances in case of multiple event notifications // for the same entity it = list_.erase(it); } else { ++it; } } } // pops the first element in the list Expected popEvent() { std::lock_guard lock(list_mutex_); if (list_.empty()) { return Unexpected{GXF_FAILURE}; } T event = list_.front(); list_.pop_front(); return event; } // exports a copy of the events in the list std::list exportList() const { std::lock_guard lock(list_mutex_); return list_; } // checks if the list is empty bool empty() const { std::lock_guard lock(list_mutex_); return list_.empty(); } // returns size of the event list size_t size() const { std::lock_guard lock(list_mutex_); return list_.size(); } // checks if the list has event bool hasEvent(T item) const { std::lock_guard lock(list_mutex_); for (const auto& element : list_) { if (item == element) { return true; } } return false; } // clears the event list void clear() { std::lock_guard lock(list_mutex_); list_.clear(); } mutable std::mutex list_mutex_; std::list list_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_EVENT_LIST_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/event_list/unique_event_list.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_UNIQUE_EVENT_LIST_HPP_ #define NVIDIA_GXF_UNIQUE_EVENT_LIST_HPP_ #include #include #include #include #include #include #include #include #include #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { // A simple thread safe list implementation to store and retrieve events template class UniqueEventList { public: UniqueEventList() = default; UniqueEventList(const UniqueEventList&) = delete; UniqueEventList& operator=(const UniqueEventList&) = delete; // Adds an item on to the event list bool pushEvent(T item) { std::lock_guard lock(list_mutex_); if (items_.find(item) != items_.end()) { return false; } list_.push_back(item); items_.insert(std::make_pair(item, --list_.end())); return true; } // Removes an event from the list if it exists and returns true, // returns false otherwise void removeEvent(T item) { std::lock_guard lock(list_mutex_); if (items_.find(item) == items_.end()) { return; } list_.erase(items_.at(item)); items_.erase(item); } // pops the first element in the list Expected popEvent() { std::lock_guard lock(list_mutex_); if (list_.empty()) { return Unexpected{GXF_FAILURE}; } T event = list_.front(); list_.pop_front(); items_.erase(event); return event; } // exports a copy of the events in the list std::list exportList() const { std::lock_guard lock(list_mutex_); return list_; } // checks if the list is empty bool empty() const { std::lock_guard lock(list_mutex_); return list_.empty(); } // returns size of the event list size_t size() const { std::lock_guard lock(list_mutex_); return items_.size(); } // checks if the list has event bool hasEvent(T item) const { std::lock_guard lock(list_mutex_); return items_.find(item) != items_.end() ? true : false; } // clears the event list void clear() { std::lock_guard lock(list_mutex_); list_.clear(); items_.clear(); } mutable std::mutex list_mutex_; std::list list_; std::unordered_map::iterator> items_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_UNIQUE_EVENT_LIST_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/queue_thread/queue_thread.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_GEMS_QUEUE_THREAD_HPP #define NVIDIA_GXF_STD_GEMS_QUEUE_THREAD_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include "common/assert.hpp" #include "common/logger.hpp" #define STR(str) ((str).empty() ? "DefaultName" : (str).c_str()) namespace nvidia { namespace gxf { /** * Entry wrapper for the user item and its associated promise */ template struct UserItemWithPromise { // typedef ItemType user_item_type; ItemType user_item; std::promise promise; bool is_stop_signal = false; UserItemWithPromise(ItemType i) : user_item(std::move(i)) {} UserItemWithPromise() : is_stop_signal(true) {} }; /** * A thread safe generic container serving as the queue for QueueThread */ template class GuardQueue { public: using Entry = UserItemWithPromise; void push(Entry data) { std::unique_lock lock(queue_mutex_); queue_.emplace_back(std::move(data)); queue_cv_.notify_one(); } Entry pop() { GXF_LOG_VERBOSE("GuardQueue::pop() acquiring lock..."); std::unique_lock lock(queue_mutex_); GXF_LOG_VERBOSE("GuardQueue::pop() acquired lock, waiting on cv..."); queue_cv_.wait( lock, [this]() { bool wait_condition = wakeup_once_ || !queue_.empty(); GXF_LOG_VERBOSE("GuardQueue::pop() cv wait condition[%d]", wait_condition); return wait_condition; }); if (wakeup_once_) { wakeup_once_ = false; GXF_LOG_VERBOSE("GuardQueue pop end on wakeup signal"); // empty Entry carries is_stop_signal true return Entry(); } GXF_ASSERT_TRUE(!queue_.empty()); Entry ret = std::move(*queue_.begin()); queue_.erase(queue_.begin()); GXF_LOG_VERBOSE("GuardQueue::pop() popped an entry"); return ret; } void wakeupOnce() { GXF_LOG_VERBOSE("GuardQueue trigger wakeup once"); std::unique_lock lock(queue_mutex_); wakeup_once_ = true; queue_cv_.notify_all(); GXF_LOG_VERBOSE("GuardQueue finish wakeup once notification"); } void clear() { GXF_LOG_VERBOSE("GuardQueue clear"); std::unique_lock lock(queue_mutex_); queue_.clear(); wakeup_once_ = false; } int size() { std::unique_lock lock(queue_mutex_); return queue_.size(); } private: std::mutex queue_mutex_; std::condition_variable queue_cv_; std::list queue_; bool wakeup_once_ = false; }; /** * The Async Runnable * Usage is similar to std::thread, but here the run function is event-driven callback. * * Construction: * 1. user event type in template; * 2. user run function implementation that takes user event type; * 3. thread name. * * Upon startup or no event is enqueued, the process thread remains sleep. * Whenever an event is raised in caller thread, simply enqueue that event * then the run function callback will process the event asynchronously * * Optionally an std::future is returned for each enqueued event, such that * users can synchronize completion of the event. */ template class QueueThread { public: using Entry = UserItemWithPromise; using RunFunction = std::function; /** * Constructor, asynchronously running RunFunction */ QueueThread(RunFunction run_function, const std::string& name) : run_function_(run_function) { std::promise promise; std::future future = promise.get_future(); GXF_LOG_DEBUG("QueueThread starting new thread"); thread_ = std::thread([&promise, this]() { GXF_LOG_DEBUG("QueueThread std::thread created[name: %s, ID: %s]", this->name_.c_str(), callerThreadId().c_str()); promise.set_value(); this->threadLoop(); }); setThreadName(name); future.wait(); } /** * set thread name for profiling display */ void setThreadName(const std::string& name) { GXF_ASSERT_TRUE(!name.empty()); name_ = name; // POSIX pthread_setname_np max length limit 15 characters plus null terminator std::string pthread_name = (name.length() > 15) ? name.substr(0, 15) : name; if (thread_.joinable()) { if (pthread_setname_np(thread_.native_handle(), pthread_name.c_str()) != 0) { GXF_LOG_ERROR("set thread name: %s failed", STR(pthread_name)); return; } GXF_LOG_DEBUG("QueueThread set new thread name: %s", STR(pthread_name)); } } /** * Destructor */ ~QueueThread() { if (!joined_) { // Ensure the stop logic is called if not already done so stop(); } // Clear any remaining items after the thread has been joined guard_queue_.clear(); } /** * Main API. Enqueue item to process, return future to sync the result. */ std::future queueItem(ItemType item) { Entry itemWithPromise(std::move(item)); std::future future = itemWithPromise.promise.get_future(); guard_queue_.push(std::move(itemWithPromise)); return future; } /** * Thread safe size check */ int size() { return guard_queue_.size(); } /** * Stop the Async Runnable */ void stop() { std::string caller_thread_id = callerThreadId(); GXF_LOG_DEBUG("QueueThread[%s]::stop() caller thread[%s] acquiring stop lock...", name_.c_str(), caller_thread_id.c_str()); { std::lock_guard lock(stop_mutex_); stop_requested_ = true; } GXF_LOG_DEBUG("QueueThread[%s]::stop() caller thread[%s] acquired stop lock", name_.c_str(), caller_thread_id.c_str()); // Wake up the thread if it's waiting for new items guard_queue_.wakeupOnce(); // Notify the wait() that stop was requested stop_cv_.notify_all(); // Try join the thread, thread safe joinThread(); } /** * Wait the Async Runnable */ void wait() { std::string caller_thread_id = callerThreadId(); GXF_LOG_DEBUG("QueueThread[%s]::wait() caller thread[%s] acquiring stop lock...", name_.c_str(), caller_thread_id.c_str()); std::unique_lock lock(stop_mutex_); GXF_LOG_DEBUG("QueueThread[%s]::wait() caller thread[%s] acquired stop lock", name_.c_str(), caller_thread_id.c_str()); // Block caller thread stop_cv_.wait(lock, [this]() { bool wait_condition = stop_requested_ && guard_queue_.size() == 0; GXF_LOG_DEBUG("stop_requested_[%d] && guard_queue_.size()[%d], cv wait condition[%d]", stop_requested_.load(), guard_queue_.size(), wait_condition); return wait_condition; }); // Try join the thread, thread safe joinThread(); } private: /** * Thread safe join thread */ void joinThread() { std::string caller_thread_id = callerThreadId(); GXF_LOG_DEBUG("QueueThread[%s]::joinThread() caller thread[%s] acquiring join lock...", name_.c_str(), caller_thread_id.c_str()); // Ensure only one caller can join the thread std::lock_guard lock(join_mutex_); GXF_LOG_DEBUG("QueueThread[%s]::joinThread() caller thread[%s] acquired join lock", name_.c_str(), caller_thread_id.c_str()); if (thread_.joinable()) { GXF_LOG_DEBUG("QueueThread[%s]::joinThread() got its thread joinable(), joining...", name_.c_str()); thread_.join(); GXF_LOG_DEBUG("QueueThread[%s]::joinThread() got its thread joined", name_.c_str()); joined_ = true; } } /** * Thread loop listening and processing tasks */ void threadLoop() { while (true) { try { Entry entry = guard_queue_.pop(); if (entry.is_stop_signal) { GXF_LOG_INFO("QueueThread[%s]::threadLoop() return", STR(name_)); return; // okay to return } if (stop_requested_ && guard_queue_.size() == 0) { // Exit loop if stop is requested and all entries are processed break; } bool result = run_function_(std::move(entry.user_item)); entry.promise.set_value(result); if (!result) { GXF_LOG_INFO("QueueThread[%s]::threadLoop() return and stop", STR(name_)); break; // don't return } } catch (const std::exception& e) { // unexpected but continue GXF_LOG_ERROR("QueueThread:%s %s", STR(name_), e.what()); // move on to next continue; } catch (...) { // unexpected GXF_LOG_ERROR( "QueueThread:%s internal unexpected error, may cause stop", STR(name_)); // Usually can move on to next, but need to check continue; } } GXF_LOG_DEBUG("threadLoop() break while loop"); // Clear the queue before exiting the thread loop guard_queue_.clear(); // unblock external thread blocking on wait() call stop_requested_ = true; // Notify that the thread is about to exit after processing all entries stop_cv_.notify_all(); } private: // basic member variables std::thread thread_; std::string name_; RunFunction run_function_; GuardQueue guard_queue_; // member variable for stopping std::atomic stop_requested_{false}; std::mutex stop_mutex_; std::condition_variable stop_cv_; // member variable for joining thread std::mutex join_mutex_; bool joined_ = false; private: std::string callerThreadId() { pid_t tid = syscall(SYS_gettid); std::stringstream ss; ss << tid; return ss.str(); } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_GEMS_QUEUE_THREAD_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/staging_queue/staging_queue.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_GEMS_STAGING_QUEUE_HPP #define NVIDIA_GXF_STD_GEMS_STAGING_QUEUE_HPP #include #include #include #include "common/assert.hpp" #include "gxf/std/gems/staging_queue/staging_queue_iterator.hpp" namespace gxf { namespace staging_queue { // Defines the behavior of a StagingQueue in case an element is added while the queue is already // full. enum class OverflowBehavior { // Pops oldest item to make room for the incoming item. kPop, // Rejects the incoming item. kReject, // The queue goes into an error state. Currently this raises a PANIC. kFault }; // A thread-safe double-buffered queue implemented based on a ring buffer. // // This data structure provides a queue-like interface to a collection of items. When items are // added to the queue with the function push they are placed into a backstage area. The pop // function and query functions like size, peek or latest only operate on items on // the main stage. Items are moved from the backstage to the main stage by calling the sync // function. The queue only provides a fixed number of slots for elements. If elements are added to // a full queue a user-selected strategy is used to determine how to proceed. Note that the overflow // strategy can by triggered when calling push in case the backstage area is full, or when calling // sync in case the main stage is too full to receive all items from the backstage. When items are // removed from the queue they are overwritten with a user-defined default value. This is useful // for example in case shared pointers are stored in the queue. All functions of this type are // protected by a common mutex thus making this a thread-safe type. The queue is implemented as a // ring buffer internally. // // The following diagram depicts an example of a queue with a total capacity of four items. It // currently stores three items in the main stage and two items in the backstage. O indicates // empty slots, X indicates (filled) main stage slots and B indicates (filled) backstage slots. // There are three empty slots as neither main stage nor backstage are at full capacity. If the // sync function would be called in this situation the overflow behavior would be triggered as // the main stage does not have enough room to receive all items from the backstage. // // # start of ringbuffer # end of ringbuffer // | | // | O | X | X | X | B | B | O | O | // | | | // | | # end // # begin | // # backstage // template class StagingQueue { public: using const_iterator_t = StagingQueueIterator; // Creates a new staging queue. 'capacity' indicates the maximum number of elements allowed in // the queue. Note that the queue will allocate memory to hold two times capacity slots of item // type T. 'overflow_behavior' defines what will happen if a new item is added to a full queue. // 'null' is the default element which is used for empty slots. If an element is removed from the // queue the slot it occupied is set to this value. StagingQueue(size_t capacity, OverflowBehavior overflow_behavior, T null); // Creates an empty staging queue with no capacity and Fault overflow behavior StagingQueue(); // Gets the overflow behavior which is used by this queue OverflowBehavior overflow_behavior() const; // Returns true if there are no elements in the main stage of the queue. // Identical to 'size() == 0;' bool empty() const; // Returns the number of elements in the main stage of the queue. size_t size() const; // Returns the maximum number of elements which can be stored in the main stage. size_t capacity() const; // Returns the number of elements in the back main stage of the queue. size_t back_size() const; // Gets the item at position 'index' in the main stage of the queue starting with the oldest item. // Returns a reference to the null object if there are no items in the main stage. const T& peek(size_t index = 0) const; // Gets the item at position 'index' in the back stage of the queue starting with the oldest item. // Returns a reference to the null object if there are no items in the back stage. const T& peek_backstage(size_t index = 0) const; // Gets the item at position 'index' in the main stage of the queue starting with the newest item. // Returns a reference to the null object if there are no items in the main stage. // Identical to 'peek(size() - 1 - index)'. const T& latest(size_t index = 0) const; // Gives an iterator pointing to the first element in the main stage. const_iterator_t begin() const; // Gives an iterator pointing to the element after the last element in the main stage. const_iterator_t end() const; // Removes the oldest item from the queue's main stage and returns it. In case there are no items // in the main stage this function simply returns a copy of the null object. This function // invalidates iterators returned by begin() or end(). T pop(); // Removes all items from the main stage. This function invalidates iterators in the same way // as the pop() function. void popAll(); // Adds a new item to the back stage. In case the back stage is at capacity the overflow behavior // is used to decide what to do. The added item will NOT be visible to any other functions which // operate on the main stage, like size, peek, pop or similar, until 'sync' is called. bool push(T item); // Moves all items from the back stage to the main stage. In case the main stage is too full // to receive all items from the back stage the specified overflow behavior is used to decide what // to do. This function invalidates iterators in the same way as the pop() function. bool sync(); private: // Returns the item in the underlying ringbuffer which is at position 'index' relative to the // start of the ring buffer. const T& at(size_t index) const { return items_[index % items_.size()]; } T& at(size_t index) { return items_[index % items_.size()]; } // The maximum number of items in the main stage and back stage. Total number items in the queue // is two times capacity. const size_t capacity_; // This behavior defines if either push or sync are called but the main stage contains too many // items already. const OverflowBehavior overflow_behavior_; // The null value is used for empty slots. It is also used as return value for peek and latest // in case the given index is out of bounds. T null_; // The container which holds the elements of the main stage and back stage. The container // allocates memory in the constructor and does not change it's capacity thereafter. std::vector items_; // Index of the first element of the main stage. The value of begin_ is guaranteed to be in the // range {0, ..., items_.size() - 1}. size_t begin_; // Number of elements in the mainstage. size_t num_mainstage_; // Number of elements in the backstage. size_t num_backstage_; // This mutext protects all functions from concurrent access. mutable std::mutex mutex_; }; //-------------------------------------------------------------------------------------------------- template StagingQueue::StagingQueue(size_t capacity, OverflowBehavior overflow_behavior, T null) : capacity_(capacity), overflow_behavior_(overflow_behavior), null_(null), items_(2 * capacity, null), begin_(0), num_mainstage_(0), num_backstage_(0) {} template StagingQueue::StagingQueue() : capacity_(0), overflow_behavior_(OverflowBehavior::kFault), null_(), items_(0), begin_(0), num_mainstage_(0), num_backstage_(0) {} template OverflowBehavior StagingQueue::overflow_behavior() const { // Mutex not necessary as overflow_behavior_ is immutable. return overflow_behavior_; } template bool StagingQueue::empty() const { std::lock_guard lock(mutex_); return num_mainstage_ == 0; } template size_t StagingQueue::size() const { std::lock_guard lock(mutex_); return num_mainstage_; } template size_t StagingQueue::capacity() const { // Mutex not necessary as capacity_ is immutable. return capacity_; } template size_t StagingQueue::back_size() const { std::lock_guard lock(mutex_); return num_backstage_; } template const T& StagingQueue::peek(size_t index) const { std::lock_guard lock(mutex_); if (index < num_mainstage_) { return at(begin_ + index); } else { return null_; } } template const T& StagingQueue::peek_backstage(size_t index) const { std::lock_guard lock(mutex_); if (index < num_backstage_) { const size_t begin_backstage = begin_ + num_mainstage_; return at(begin_backstage + index); } else { return null_; } } template const T& StagingQueue::latest(size_t index) const { std::lock_guard lock(mutex_); if (index < num_mainstage_) { return at(begin_ + num_mainstage_ - index - 1); } else { return null_; } } template typename StagingQueue::const_iterator_t StagingQueue::begin() const { return const_iterator_t(items_.data(), items_.size(), begin_); } template typename StagingQueue::const_iterator_t StagingQueue::end() const { return const_iterator_t(items_.data(), items_.size(), begin_ + num_mainstage_); } template T StagingQueue::pop() { std::lock_guard lock(mutex_); T result = null_; if (num_mainstage_ > 0) { std::swap(at(begin_++), result); num_mainstage_--; } begin_ %= items_.size(); return result; } template void StagingQueue::popAll() { std::lock_guard lock(mutex_); const size_t begin_backstage = begin_ + num_mainstage_; while (begin_ < begin_backstage) { at(begin_++) = null_; } begin_ %= items_.size(); num_mainstage_ = 0; } template bool StagingQueue::push(T item) { std::lock_guard lock(mutex_); const size_t begin_backstage = begin_ + num_mainstage_; if (num_backstage_ == capacity_) { // Trying to add a item to a full backstage. switch (overflow_behavior_) { case OverflowBehavior::kPop: { // Move items in back stage one over. This removes the oldest item and makes room for one // new item. const size_t backstage_end = begin_backstage + num_backstage_; for (size_t i = begin_backstage + 1; i < backstage_end; i++) { at(i - 1) = std::move(at(i)); } // Add new item at the end of the backstage. at(backstage_end - 1) = std::move(item); } break; case OverflowBehavior::kReject: // Don't add the new item to the backstage. break; case OverflowBehavior::kFault: return false; // FIXME "Added an item to a full queue while using the 'Fault' overflow behavior." default: // FIXME "Invalid parameter" return false; } } else { // Add the new item to the end of the backstage. at(begin_backstage + num_backstage_) = std::move(item); num_backstage_++; } return true; } template bool StagingQueue::sync() { std::lock_guard lock(mutex_); // Add back stage items to main stage num_mainstage_ += num_backstage_; num_backstage_ = 0; // Handle overflow if necessary if (num_mainstage_ > capacity_) { switch (overflow_behavior_) { case OverflowBehavior::kPop: { // Make sure that main and back stage together don't exceed capacity. Remove excess items // starting with the first item in the main stage. This effectively pops the oldest items to // make room for new items. const size_t new_begin = begin_ + num_mainstage_ - capacity_; while (begin_ < new_begin) { at(begin_++) = null_; } num_mainstage_ = capacity_; } break; case OverflowBehavior::kReject: // Make sure that main and back stage together don't exceed capacity. Remove excess items // starting with the last item in the back stage. This effectively rejects new items. while (num_mainstage_ > capacity_) { at(begin_ + --num_mainstage_) = null_; } break; case OverflowBehavior::kFault: return false; // FIXME "Added items to a full queue while using the 'Fault' overflow behavior."; default: // FIXME "Invalid parameter" return false; } } begin_ %= items_.size(); return true; } } // namespace staging_queue } // namespace gxf #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/staging_queue/staging_queue_iterator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_GEMS_STAGING_QUEUE_ITERATOR_HPP #define NVIDIA_GXF_STD_GEMS_STAGING_QUEUE_ITERATOR_HPP #include namespace gxf { namespace staging_queue { // A forward iterator for a staging queue. // // This type can be used to iterate through the items of the main stage of a staging queue. (It // could be used to iterate over any part of the ring buffer, but is only used for the main stage.) // The iterator correctly "wraps around" the ring buffer in case the iterated sequence spans over // the end of the ring buffer. This iterator could in theory also be used to loop over the range // multiple times by adding multiples of size to the end index, however it is not used in this // fashion by the staging queue. // // Let's take the example of a staging queue which stores four items (capacity = 2) as depicted in // the diagram below. An iterator using index=3 would point to the third element. An iterator using // index=5 would point to the second element in the sequence. If these two iterators would be used // as begin and end of a range iteration would "wrap around" and iterate over the items A and B. // // 0 1 2 3 4 // # # # # # // | B | O | O | A | // | | // | # begin // # end // // Note that the member functions of this type are part of the standard implementation for a // forward iterator. Please refer to the C++ standard definition for forward iterators for details. template class StagingQueueIterator { public: using difference_type = std::ptrdiff_t; using value_type = T; using reference = const T&; using pointer = const T*; // Creates an empty (invalid) iterator StagingQueueIterator() : data_(nullptr), size_(0), index_(0) {} // Creates and iterator based on a sequence of items pointed to by 'data' which stores 'size' // number of items. The given 'index' indicates the position of the element in the underlying // sequence modulo the length of the sequence. StagingQueueIterator(pointer data, size_t size, size_t index) : data_(data), size_(size), index_(index) {} StagingQueueIterator(const StagingQueueIterator& other) = default; StagingQueueIterator& operator=(const StagingQueueIterator& other) = default; StagingQueueIterator(StagingQueueIterator&& other) = default; StagingQueueIterator& operator=(StagingQueueIterator&& other) = default; ~StagingQueueIterator() = default; const StagingQueueIterator& operator++() { ++index_; return *this; } StagingQueueIterator operator++(int) { return StagingQueueIterator(data_, size_, index_++); } reference operator*() const { return data_[index_ % size_]; } pointer operator->() const { return data_ + (index_ % size_); } bool operator==(const StagingQueueIterator& rhs) const { return data_ == rhs.data_ && size_ == rhs.size_ && index_ == rhs.index_; } bool operator!=(const StagingQueueIterator& rhs) const { return !(*this == rhs); } private: // A pointer to the sequence of items to which this iterator refers. const pointer data_; // The length of the sequence pointer to by 'data_'. const size_t size_; // The index of the item in the sequence to which this iterator points. The index is taken modulo // 'size_' when accessing 'data_'. size_t index_; }; } // namespace staging_queue } // namespace gxf namespace std { template struct iterator_traits> { using difference_type = typename gxf::staging_queue::StagingQueueIterator::difference_type; using value_type = typename gxf::staging_queue::StagingQueueIterator::value_type; using reference = typename gxf::staging_queue::StagingQueueIterator::reference; using pointer = typename gxf::staging_queue::StagingQueueIterator::pointer; using iterator_category = std::forward_iterator_tag; }; } // namespace std #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/suballocators/first_fit_allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_GEMS_SUBALLOCATORS_FIRST_FIT_ALLOCATOR_HPP #define NVIDIA_GXF_STD_GEMS_SUBALLOCATORS_FIRST_FIT_ALLOCATOR_HPP #include #include #include #include #include "common/expected.hpp" #include "gxf/std/gems/suballocators/first_fit_allocator_base.hpp" namespace nvidia { namespace gxf { // Memory management class. // It pre-allocates memory for a given type and allow acquiring chunk of memory and releasing them. // Only the allocate function is doing some memory allocation, other functions are using constant // amount of memory on the stack. template class FirstFitAllocator { public: // Expected type used by this class. template using expected_t = nvidia::Expected; // Unexpected type used by this class. using unexpected_t = nvidia::Unexpected; FirstFitAllocator() = default; // Allocates the require memory to handle the query for a chunk of memory of a give size . // It fails if size is invalid (too big or negative). // Note that a minimum chunk size to be considered can be provided. It means the memory allocated // will always be a multiple of this size. This can help speed up the memory allocation, however // it loses control on the exact allocated size. // The total memory allocated will be around sizeof(T) * size + 32 * size / chunk_size. expected_t allocate(const int32_t size, const int chunk_size = 1) { if (buffer_.get() != nullptr) { return unexpected_t(FirstFitAllocatorBase::Error::kAlreadyInUse); } if (size < 0 || chunk_size <= 0) { return unexpected_t(FirstFitAllocatorBase::Error::kInvalidSize); } chunk_size_ = chunk_size; const int32_t number_of_chunks = getNumberOfChunks(size); // Allocate memory buffer_.reset(new(std::nothrow) T[number_of_chunks * chunk_size_]); if (buffer_.get() == nullptr) { return unexpected_t(FirstFitAllocatorBase::Error::kOutOfMemory); } // Prepare the memory management. auto res = memory_management_.allocate(number_of_chunks); if (!res) { return unexpected_t(res.error()); } return size; } // Attempts to acquire a block of memory of a given size. // If such a contiguous block exists, it will return a pointer to that block and the actual size // acquired (will be the smallest multiple of chunk_size_ that exceed or equal size). // If no block exists, it will return FirstFitAllocatorBase::Error::kOutOfMemory. expected_t> acquire(const int32_t size) { const int32_t number_of_chunks = getNumberOfChunks(size); auto res = memory_management_.acquire(number_of_chunks); if (!res) { return unexpected_t(res.error()); } return std::make_pair(&buffer_.get()[res.value() * chunk_size_], number_of_chunks * chunk_size_); } // Releases a block of memory that has been acquired with the function above. // If there was no `acquire(size)` that returned this pointer, this query will fail, otherwise it // will free the block of memory for further acquisition. // Note once a block of memory has been released, it can't be released again. expected_t release(const T* ptr) { const int32_t index = std::distance(buffer_.get(), ptr); if (index % chunk_size_ != 0) { return unexpected_t(FirstFitAllocatorBase::Error::kInvalidSize); } return memory_management_.release(index / chunk_size_); } private: // Returns the number of chunks of memory needed to have at least a given size. int32_t getNumberOfChunks(const int32_t size) const { return (size + chunk_size_ - 1) / chunk_size_; } // Real memory management. FirstFitAllocatorBase memory_management_; // Size of the chunk of memory. Only multiple of this size can be allocated. Whenever a request is // made, the allocated size will be the smaller multiple of chunk_size_ that is not smaller than // the requested size. int32_t chunk_size_; // Buffer holding the pre-allocated memory that is provided on demand. std::unique_ptr buffer_{nullptr}; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_GEMS_SUBALLOCATORS_FIRST_FIT_ALLOCATOR_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/suballocators/first_fit_allocator_base.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_GEMS_SUBALLOCATORS_FIRST_FIT_ALLOCATOR_BASE_HPP #define NVIDIA_GXF_STD_GEMS_SUBALLOCATORS_FIRST_FIT_ALLOCATOR_BASE_HPP #include #include #include #include #include "common/expected.hpp" namespace nvidia { namespace gxf { // Memory management helper class, it keeps track of what part of a big chunk of memory has been // allocated and can efficiently find the first available chunk of memory that fits a given size. // This class works only with indexes and rely on an external class to hold the memory. // Internally it uses binary segment tree to keep track the biggest available block in a given area // of the the memory. All the operation should take a logarithmic time. class FirstFitAllocatorBase { public: // Error codes used by the classes of this file. enum class Error { // Returned when the suballocators is already in use and some memory has not been released yet. kAlreadyInUse, // Returned if the size is invalid (negative or too big). kInvalidSize, // Returned if the class can't allocate enough memory. kOutOfMemory, // Returned if we attempt to release a block of memory not allocated yet. kBlockNotAllocated, // This error happens when there is logically issue during the execution. This should never // happen. kLogicError, }; // Expected type used by this class. template using expected_t = nvidia::Expected; // Unexpected type used by this class. using unexpected_t = nvidia::Unexpected; FirstFitAllocatorBase(); // Allocates the require memory to handle the query for a chunk of memory of a give size . // It requires 32 * 2^ceil(log2(size)) Bytes of memory. // It fails if size is invalid (too big or negative). expected_t allocate(int32_t size); // Attempts to acquire a block of memory of a given size. // If such a contiguous block exists, it will return the lowest index where such a block exist. // This block will be blocked until a call to release(index, size) is made. // If no block exists, it will return Error::kOutOfMemory. expected_t acquire(int32_t size); // Releases a block of memory that has been acquired with the function above. // If there was no `acquire(size)` that returned `index`, this query will fail, otherwise it will // free the block of memory for further acquisition. // Note once a block of memory has been released, it can't be released again. expected_t release(int32_t index); private: // Helper data structure to efficiently find a block of memory of a given size. // It represents a node in a binary segment tree. struct Memory { // Updates the node using both children. // size = l.size + r.size // left = l.left or l.size + r.left iff l.max == l.size // right = r.right or r.right + l.right iff r.max == r.size // max = max(l.max, r.max, l.right + r.left) void update(const Memory& left_child, const Memory& right_child); // Marks a node as being free (if == 1) or acquired (if == 0). void set(int32_t free); // Left and right store the size of available memory which start respectively from the left or // right side of the subtree. int32_t left, right; // Max is the size of biggest available block in the subtree. // When a block is starting at the given index, the leaf will contain -1. int32_t max; // Size is constant overtime and represent the size of the subtree. // When a block has been acquired, size will contain the size that has been acquired from the // given position. int32_t size; }; // Updates a path from a given node to the root. void propagateToRoot(int32_t idx); // Updates a segment of the tree [left, right[ and marks it as free or acquired. void update(int32_t left, int32_t right, int32_t free); // Hold the segment tree memory. std::unique_ptr tree_; // The total size available at the beginning. int32_t size_; // Helper index that helps pointing toward the leaves of the tree. int32_t last_layer_first_index_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_GEMS_SUBALLOCATORS_FIRST_FIT_ALLOCATOR_BASE_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/timed_job_list/timed_job_list.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_GEMS_TIMED_JOB_LIST_TIMED_JOB_LIST_HPP_ #define NVIDIA_GXF_STD_GEMS_TIMED_JOB_LIST_TIMED_JOB_LIST_HPP_ #include #include #include #include #include #include #include #include #include #include #include #include "gxf/core/expected.hpp" namespace nvidia { namespace gxf { // A thread-safe queue which sorts by target execution time. It provides a blocking pop to get // jobs precisely when the time is right. // T: The type of jobs to store in the queue // Eq: (T,T) -> bool: true if jobs are identical template class TimedJobList { public: using Clock_t = std::function; TimedJobList(Clock_t clock) : clock_(clock), is_running_(false) {} // Number of queued jobs. This should only be used for logging purposes as it is not acquiring // a lock. size_t sizeUnsafe() const { return queue_.size(); } // thread-safe implementation to find number of queued jobs size_t size() const { std::unique_lock lock(queue_cv_mutex_); return items_.size(); } // Adds a job to the queue to be executed at the given target time. O(log(n)) bool insert(JobT job, int64_t target_time, int64_t slack, int priority); // Notify that a job has completed. void notifyDone(JobT job); // This is a blocking call which will wait for an job. void waitForJob(JobT&); // Removes a job from the queue if present. Returns true if the job was found and removed. bool remove(JobT job); // Sets the job list to a running state void start() { is_running_.store(true); } // Sets the job list to a stopped state and wakes all waiting threads to flush. void stop() { // Acquire the lock to ensure a thread isn't trying to acquire a job // while invoking stop. std::unique_lock lock(queue_cv_mutex_); // Stop the queue is_running_.store(false); // Wake all waiting threads queue_cv_.notify_all(); } // Gets the target time of the next job; or returns an error if there is no job Expected getNextTargetTime() const { std::unique_lock lock(queue_cv_mutex_); if (queue_.empty()) { return Unexpected{GXF_QUERY_NOT_FOUND}; } else { return queue_.top().target_time; } } // wakes up one waiting threads void wakeOne() { queue_cv_.notify_one(); } // wakes all waiting threads void wakeAll() { queue_cv_.notify_all(); } // Pops the next pending or waiting job regardless of their // target execution time Expected popFront() { std::unique_lock lock(queue_cv_mutex_); // return pending jobs first for (auto pending_job = pending_.begin(); pending_job != pending_.end(); ++pending_job) { Item result = *pending_job; pending_.erase(pending_job); return result.job; } // return waiting jobs next if (queue_.empty()) { return Unexpected{GXF_FAILURE}; } Item result = queue_.top(); queue_.pop(); items_.erase(result.job); return result.job; } // Checks if there any pending or waiting jobs bool empty() const { std::unique_lock lock(queue_cv_mutex_); return queue_.empty() && pending_.empty(); } private: // We allow a small tolerance when executing jobs // static constexpr int64_t kTimeFudge = 100'000; // 0.1 ms static constexpr int64_t kTimeFudge = 1; // 100 ns // Helper class used to store jobs with additional information struct Item { // The job to execute JobT job; // The target time at which the job should be executed int64_t target_time; // The amount of time the target time can slip by int64_t slack; // The priority is used as a tie breaker when two jobs would be scheduled close together. int priority; }; // Sorts jobs such that the earliest non-running job has highest priority struct ItemPriorityCmp { bool operator()(const Item& a, const Item& b) { // If two jobs with their slack times are scheduled within a small // interval of each other check their priorities, // Otherwise earliest deadline goes first. const int64_t a_time = a.target_time + a.slack; const int64_t b_time = b.target_time + b.slack; if (std::abs(a_time - b_time) < kTimeFudge && a.priority != b.priority) { return a.priority < b.priority; } else { return a_time > b_time; } } }; // This function pointer should be set to utilize the desired clock for the queue. Clock_t clock_; // state variable to control if threads should block on waiting for jobs std::atomic is_running_; mutable std::mutex queue_cv_mutex_; std::condition_variable queue_cv_; // List of future events sorted by their scheduled execution time. std::priority_queue, ItemPriorityCmp> queue_; // Item lookup to avoid duplicates std::unordered_set items_; // List of events overdue, we have passed their scheduled execution time but have not been able to // run yet. std::list pending_; }; // ------------------------------------------------------------------------------------------------- template bool TimedJobList::insert(JobT job, int64_t target_time, int64_t slack, int priority) { { std::unique_lock lock(queue_cv_mutex_); if (items_.find(job) != items_.end()) { return false; } items_.insert(job); queue_.push(Item{std::move(job), target_time, slack, priority}); } queue_cv_.notify_one(); return true; } template void TimedJobList::notifyDone(JobT job) { std::unique_lock lock(queue_cv_mutex_); wakeOne(); } // Removes a job from the pending list or priority queue and from the items_ tracking set. // Since std::priority_queue doesn't support direct element removal, this method rebuilds // the queue excluding the target job when necessary. Returns true if the job was found // and successfully removed, false if the job wasn't present in any container. template bool TimedJobList::remove(JobT job) { std::unique_lock lock(queue_cv_mutex_); // Check if the job exists in our tracking set auto it = items_.find(job); if (it == items_.end()) { return false; // Job not found } // Remove from items_ items_.erase(it); // Check if job is in pending list and remove if found for (auto pending_it = pending_.begin(); pending_it != pending_.end(); ++pending_it) { if (pending_it->job == job) { pending_.erase(pending_it); return true; } } // If not in pending, it might be in the queue // Since std::priority_queue doesn't allow direct removal, we need to: // 1. Create a new queue // 2. Pop all elements from the old queue // 3. Push all elements except the one we want to remove into the new queue // 4. Swap the queues std::priority_queue, ItemPriorityCmp> new_queue; bool found = false; while (!queue_.empty()) { Item item = queue_.top(); queue_.pop(); if (item.job != job) { // Keep this item new_queue.push(item); } else { // Found the job to remove found = true; } } // Replace the old queue with the new one queue_.swap(new_queue); // Wake waiting threads to recalculate wait times wakeOne(); return found; } template void TimedJobList::waitForJob(JobT& job) { while (is_running_) { // Acquire the lock to check for a job std::unique_lock lock(queue_cv_mutex_); // Double check the running status as a stop could have been invoked. if (!is_running_) { return; } int64_t wait_duration = 0; const int64_t now = clock_(); while (!queue_.empty()) { // We have a job, check if it is time for it Item top_item = queue_.top(); const int64_t eta = top_item.target_time - now; // If the jobs target time is within our fudge factor fire now. if (eta <= kTimeFudge) { pending_.push_back(top_item); queue_.pop(); } else { // wait till next eta minus a small window wait_duration = std::max(eta - kTimeFudge, static_cast(0)); break; } } // Loop through the list of pending jobs to find one that can be run. for (auto pending_job = pending_.begin(); pending_job != pending_.end(); ++pending_job) { job = pending_job->job; pending_job->target_time = now; pending_.erase(pending_job); items_.erase(job); return; } // Wait for a new job or until time is up (the lock is released while waiting) if (wait_duration > 0) { queue_cv_.wait_for(lock, std::chrono::nanoseconds(wait_duration)); } else { queue_cv_.wait(lock); } } } } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_GEMS_TIMED_JOB_LIST_TIMED_JOB_LIST_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/utils/time.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GXF_STD_GEMS_UTILS_TIME_HPP_ #define NVIDIA_GXF_GXF_STD_GEMS_UTILS_TIME_HPP_ #include #include #include "gxf/core/expected.hpp" namespace nvidia { namespace gxf { /// @brief Converts time in seconds to a timestamp in nanoseconds int64_t TimeToTimestamp(double time); /// @brief Converts a timestamp Nanoseconds to seconds double TimestampToTime(int64_t timestamp); /// @brief Parses given text to return the desired period in nanoseconds. /// /// @param text Text containing number and time-units, to be parsed for desired period /// @param cid cid of component for which text is being parsed /// @return Period in nanoseconds if successful, or otherwise one of the GXF error codes. Expected ParseRecessPeriodString(std::string text, const gxf_uid_t& cid); inline uint64_t getCurrentTimeUs() { using std::chrono::duration_cast; using std::chrono::system_clock; return duration_cast(system_clock::now().time_since_epoch()).count(); } } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GXF_STD_GEMS_UTILS_TIME_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/gems/video_buffer/allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_GEMS_VIDEO_BUFFER_HPP #define NVIDIA_GXF_STD_GEMS_VIDEO_BUFFER_HPP #include #include #include "gxf/multimedia/video.hpp" #include "gxf/std/allocator.hpp" namespace nvidia { namespace gxf { template struct NoPaddingColorPlanes {}; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({gxf::ColorPlane("RGB", 3, width * 3)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("BGR", 3, width * 3)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("RGBA", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("BGRA", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("RGB", 6, width * 6)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("BGR", 6, width * 6)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("RGB", 12, width * 12)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("BGR", 12, width * 12)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("gray", 1, width)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("gray", 2, width * 2)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("gray", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("gray", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("Y", 1, width), nvidia::gxf::ColorPlane("UV", 2, width)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("Y", 1, width), nvidia::gxf::ColorPlane("UV", 2, width)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("Y", 1, width), nvidia::gxf::ColorPlane("UV", 2, width * 2)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("Y", 1, width), nvidia::gxf::ColorPlane("UV", 2, width * 2)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes({gxf::ColorPlane("R", 1, width), gxf::ColorPlane("G", 1, width), gxf::ColorPlane("B", 1, width)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes({gxf::ColorPlane("R", 2, width * 2), gxf::ColorPlane("G", 2, width * 2), gxf::ColorPlane("B", 2, width * 2)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes( {gxf::ColorPlane("R", 4, width * 4), gxf::ColorPlane("G", 4, width * 4), gxf::ColorPlane("B", 4, width * 4)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes({gxf::ColorPlane("B", 1, width), gxf::ColorPlane("G", 1, width), gxf::ColorPlane("R", 1, width)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes( {gxf::ColorPlane("R", 2, width * 2), gxf::ColorPlane("G", 2, width * 2), gxf::ColorPlane("B", 2, width * 2)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes( {gxf::ColorPlane("B", 4, width * 4), gxf::ColorPlane("G", 4, width * 4), gxf::ColorPlane("R", 4, width * 4)}) {} std::array planes; }; // This includes the list of video buffer formats that supported for the allocator constexpr bool IsSupportedVideoFormat(const gxf::VideoFormat format) { return format == gxf::VideoFormat::GXF_VIDEO_FORMAT_RGB || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_BGR || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_RGBA || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_BGRA || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_RGB16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_BGR16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_RGB32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_BGR32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_GRAY || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_GRAY16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_GRAY32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_GRAY32F || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_R8_G8_B8 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_B8_G8_R8 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_R16_G16_B16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_B16_G16_R16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_R32_G32_B32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_B32_G32_R32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_NV12 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_NV12_ER || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_NV24 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_NV24_ER; } template::type* = nullptr> gxf::Expected AllocateUnpaddedVideoBuffer( gxf::Handle frame, uint32_t width, uint32_t height, gxf::MemoryStorageType storage_type, gxf::Handle allocator) { GXF_LOG_ERROR("Received unsupported video format!"); return gxf::Unexpected{GXF_FAILURE}; } template::type* = nullptr> gxf::Expected AllocateUnpaddedVideoBuffer( gxf::Handle frame, uint32_t width, uint32_t height, gxf::MemoryStorageType storage_type, gxf::Handle allocator) { if (width % 2 != 0 || height % 2 != 0) { GXF_LOG_ERROR( "Error: expected even width and height but received %u width and %u height", width, height); return gxf::Unexpected{GXF_FAILURE}; } NoPaddingColorPlanes nopadding_planes(width); gxf::VideoFormatSize video_format_size; auto size = video_format_size.size(width, height, nopadding_planes.planes); std::vector color_planes{ nopadding_planes.planes.begin(), nopadding_planes.planes.end()}; gxf::VideoBufferInfo buffer_info{width, height, T, color_planes, gxf::SurfaceLayout::GXF_SURFACE_LAYOUT_PITCH_LINEAR}; return frame->resizeCustom(buffer_info, size, storage_type, allocator); } template gxf::Expected AllocateVideoBuffer( gxf::Handle frame, uint32_t width, uint32_t height, gxf::SurfaceLayout layout, gxf::MemoryStorageType storage_type, gxf::Handle allocator) { return frame->resize(width, height, layout, storage_type, allocator); } } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/graph_driver.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_DRIVER_HPP_ #define NVIDIA_GXF_GRAPH_DRIVER_HPP_ #include #include #include #include #include #include #include #include "gxf/std/gems/queue_thread/queue_thread.hpp" #include "gxf/std/graph_driver_worker_common.hpp" #include "gxf/std/ipc_client.hpp" #include "gxf/std/ipc_server.hpp" #include "gxf/std/system.hpp" namespace nvidia { namespace gxf { /** * ECS layer Component, resolving segments connection addresses * Works with GraphWorker as server-client pair * * Has event-based thread, IPC server, and IPC client * * Segments connection graph: * 1. Users to provide, via config or add connection API * * Resolve address of each segment pair: * 1. Listen to remote GraphWorkers that each runs one or more segments. * 2. Register all GraphWorkers until all segments in static graph are discovered * 3. Resolve connection address between each segment pair * 4. Send result address to each target segment via GraphWorker that manages the segment */ class GraphDriver : public System { public: using ConnectionMap = std::unordered_map; using GxfSystemThread = QueueThread; GraphDriver() = default; gxf_result_t schedule_abi(gxf_uid_t eid) override; gxf_result_t unschedule_abi(gxf_uid_t eid) override; gxf_result_t runAsync_abi() override; gxf_result_t stop_abi() override; gxf_result_t wait_abi() override; gxf_result_t event_notify_abi(gxf_uid_t eid, gxf_event_t event) override; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; // C++ API exclusive Expected addSegmentConnection(const std::string& source, const std::string& target); private: /** * Member thread event-based entrance */ bool asyncRunnerCallback(std::string event, GraphDriver* self); /** * Service to register a remote GraphWorker */ Expected onRegisterGraphWorker(const std::string& resource, const std::string& payload); /** * Service to record completion of each GraphWorker * then finally gently tear down this GraphDriver */ Expected onGraphWorkerComplete(const std::string& resource, const std::string& payload); /** * After discover all segments from remote GraphWorkers, resolve segments connection * then send remote request to update connection addresses */ Expected resolveConnections(); /** * After update segments connection in each segment, they're ready to execute * send remote request to all GraphWorkers to run the segments */ Expected executeWorkers(); /** * Send remote request to all GraphWorkers to deactivate the segments */ Expected deactivateWorkers(); /** * Send remote request to all GraphWorkers to stop the segments */ Expected stopWorkers(); private: // Communication layer Parameter> server_; Parameter> client_; Parameter> list_of_connections_; ConnectionMap connections_; ConnectionMap reverse_connections_; std::set segment_names_; std::unordered_map> workers_; std::set completed_workers_; std::unique_ptr driver_thread_; std::set requested_segment_names_; std::unordered_map segment_ip_address_; private: struct Event { static constexpr const char* kNotInitialized = "kNotInitialized"; static constexpr const char* kResolveConnections = "kResolveConnections"; static constexpr const char* kExecuteWorkers = "kExecuteWorkers"; static constexpr const char* kDeactivateWorkers = "kDeactivateWorkers"; static constexpr const char* kStopWorkers = "kStopWorkers"; }; }; /** * Utils */ template <> struct ParameterParser { static Expected Parse( gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!node.IsMap()) { return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } GraphDriver::ConnectionMap connections; for (const auto& p : node) { const std::string k = p.first.as(); const auto maybe = ParameterParser::Parse( context, component_uid, k.c_str(), node[k], prefix); if (!maybe) { return ForwardError(maybe); } connections[k] = maybe.value(); } return connections; } }; template <> struct ParameterWrapper { // Wrap the value to a YAML::Node instance static Expected Wrap( gxf_context_t context, const GraphDriver::ConnectionMap& value) { YAML::Node node(YAML::NodeType::Map); for (auto &i : value) { auto maybe = ParameterWrapper::Wrap(context, i.second); if (!maybe) { return ForwardError(maybe); } node[i.first] = maybe.value(); } return node; } }; template<> struct ParameterWrapper> { static Expected Wrap( gxf_context_t context, const std::vector& value) { YAML::Node node(YAML::NodeType::Sequence); for (auto &h : value) { auto maybe = ParameterWrapper::Wrap(context, h); if (!maybe) { return Unexpected{maybe.error()}; } node.push_back(maybe.value()); } return node; } }; template <> struct ParameterParser> { static Expected> Parse( gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!node.IsSequence()) { const char* component_name = "UNKNOWN"; GxfParameterGetStr(context, component_uid, kInternalNameParameterKey, &component_name); GXF_LOG_ERROR("Parameter '%s' in component '%s' must be a vector", key, component_name); return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } std::vector result(node.size()); for (size_t i = 0; i < node.size(); i++) { const auto maybe = ParameterParser::Parse( context, component_uid, key, node[i], prefix); if (!maybe) { return ForwardError(maybe); } result[i] = std::move(maybe.value()); } return result; } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_DRIVER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/graph_driver_worker_common.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_DRIVER_WORKER_COMMON_HPP_ #define NVIDIA_GXF_GRAPH_DRIVER_WORKER_COMMON_HPP_ #include #include #include #include #include #include #include #include #include #include "common/logger.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { void parseIpAddress(const std::string& ip_address_port, std::string& ip_address, int& port); void parseSegmentEntityComponentName( const std::string& segment_entity_component_name, std::string& segment_name, std::string& entity_name, std::string& component_name); // // JSON schema parsing // struct ComponentParam { struct ParamInfo { std::string key; std::string value; std::string value_type; static Expected strToBool(const std::string& str); static Expected strToInt32(const std::string& str); static Expected strToUInt32(const std::string& str); static Expected strToInt64(const std::string& str); static Expected strToUInt64(const std::string& str); static Expected strToFloat32(const std::string& str); static Expected strToFloat64(const std::string& str); static Expected strToUInt16(const std::string& str); }; std::string segment_name; std::string entity_name; std::string component_name; std::vector params; // Helpers std::string serialize() const { return segment_name + "." + entity_name + "." + component_name; } }; struct ComponentInfo { std::string segment_name; std::string entity_name; std::string component_name; // Helpers std::string serialize() const { return segment_name + "." + entity_name + "." + component_name; } static ComponentInfo deserialize(const std::string& data) { std::istringstream stream(data); std::string segment; std::string entity; std::string component; std::getline(stream, segment, '.'); std::getline(stream, entity, '.'); std::getline(stream, component, '.'); // Validate that all parts are present. if (segment.empty() || entity.empty() || component.empty()) { GXF_LOG_ERROR("Invalid data %s", data.c_str()); } return {segment, entity, component}; } }; struct SegmentInfo { std::string segment_name; // key: "Segment_name/Entity_name/UcxRx_name" // value: "10.0.0.1:3000" std::map ip_port_address_map; }; struct WorkerInfo { std::string server_ip_address; std::string server_port; std::vector segment_info_list; std::string ip_port() const { return server_ip_address + ":" + server_port; } }; class GraphDriverWorkerParser { public: GraphDriverWorkerParser() = default; static Expected> deserialize_onSetComponentParams(const std::string& payload); static Expected serialize_onSetComponentParams(const std::vector& component_param_list); static Expected deserialize_onRegisterGraphWorker(const std::string& payload); static Expected serialize_onRegisterGraphWorker(const WorkerInfo& worker_info); }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_DRIVER_WORKER_COMMON_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/graph_worker.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GRAPH_WORKER_HPP_ #define NVIDIA_GXF_GRAPH_WORKER_HPP_ #include #include #include #include #include #include "gxf/std/gems/queue_thread/queue_thread.hpp" #include "gxf/std/graph_driver_worker_common.hpp" #include "gxf/std/ipc_client.hpp" #include "gxf/std/ipc_server.hpp" #include "gxf/std/system.hpp" namespace nvidia { namespace gxf { // copy tid from ucx extension static const gxf_tid_t ucx_transmitter_tid{0x58165d0378b74696, 0xb20071621f90aee7}; struct GraphSpec { std::string app_path; std::string param_path; std::string manifest_path; uint32_t severity = 3; // default severity }; /** * SegmentRunner, context to run each graph segment */ class SegmentRunner { public: using GxfSystemThread = QueueThread; // YAML API compose graph SegmentRunner(const std::string& name, const GraphSpec& graph_spec) : name_(name), graph_spec_(graph_spec) { runner_thread_ = std::make_unique( std::bind(&SegmentRunner::asyncRunnerCallback, this, std::placeholders::_1, this), name); } SegmentRunner(const std::string& name, const GraphSpec& graph_spec, std::shared_ptr worker_thread) : SegmentRunner(name, graph_spec) { // delegating to the first constructor worker_thread_ = worker_thread; } // C++ API compose graph SegmentRunner(const std::string& name, const gxf_context_t context) : name_(name), context_(context) { runner_thread_ = std::make_unique( std::bind(&SegmentRunner::asyncRunnerCallback, this, std::placeholders::_1, this), name); } SegmentRunner(const std::string& name, const gxf_context_t context, std::shared_ptr worker_thread) : SegmentRunner(name, context) { worker_thread_ = worker_thread; } // ~SegmentRunner(); void stop(); void wait(); // combined/simplified gxf run sequence std::future asyncInitializeGxfGraph(); std::future asyncActivateGxfGraph(); std::future asyncRunGxfGraph(); std::future runGxfGraph(); std::future asyncDeactivateGxfGraph(); std::future asyncDestroyGxfGraph(); gxf_result_t setParameter(const std::string& entity_name, const std::string& comp_name, const std::string& key, const std::string& value, const std::string& value_type); Expected createSegmentInfo(const std::string& worker_host_ip); private: std::unique_ptr runner_thread_; std::shared_ptr worker_thread_; bool asyncRunnerCallback(std::string event, SegmentRunner* self); struct Event { // GXF C API sequence event static constexpr const char* kCreateGxfContext = "kCreateContext"; static constexpr const char* kLoadGxfManifest = "kLoadGxfManifest"; static constexpr const char* kLoadGxfGraph = "kLoadGxfGraph"; static constexpr const char* kActivateGxfGraph = "kActivateGxfGraph"; static constexpr const char* kNonBlockingRunGxfGraph = "kNonBlockingRunGxfGraph"; static constexpr const char* kBlockingRunGxfGraph = "kBlockingRunGxfGraph"; static constexpr const char* kInterruptGxfGraph = "kInterruptGxfGraph"; static constexpr const char* kDeactivateGxfGraph = "kDeactivateGxfGraph"; static constexpr const char* kDestroyGxfGraph = "kDestroyGxfGraph"; }; const std::string name_; const GraphSpec graph_spec_; gxf_context_t context_ = kNullContext; gxf_context_t s_signal_context_ = kNullContext; std::mutex context_mutex_; private: // gxf wrappers, non thread safe to gxf_context gxf_result_t wrapCreateGxfConext(); gxf_result_t wrapLoadGxfManifest(); gxf_result_t wrapLoadGxfGraph(); gxf_result_t wrapActivateGxfGraph(); gxf_result_t wrapBlockingRunGxfGraph(); gxf_result_t wrapNonBlockingRunGxfGraph(); gxf_result_t wrapInterruptGxfGraph(); gxf_result_t wrapDeactivateGxfGraph(); gxf_result_t wrapDestroyGxfGraph(); }; /** * ECS layer Component, manages executing a set of segments * Works with GraphDriver as server-client pair * * Has event-based thread, IPC server, and IPC client. * * Segments to manage: * 1. Users to provide, via config or add segment context API */ class GraphWorker : public System { public: using GxfSystemThread = QueueThread; GraphWorker() = default; gxf_result_t schedule_abi(gxf_uid_t eid) override; gxf_result_t unschedule_abi(gxf_uid_t eid) override; gxf_result_t runAsync_abi() override; gxf_result_t stop_abi() override; gxf_result_t wait_abi() override; gxf_result_t event_notify_abi(gxf_uid_t eid, gxf_event_t event) override; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; // C++ API exclusive Expected addSegment(const std::string& name, const gxf_context_t context); private: // This ECS component layer /** * Member thread event-based entrance */ bool asyncRunnerCallback(std::string event, GraphWorker* self); Parameter> graph_specs_; Parameter driver_reconnection_times_; std::map> segment_runners_; std::shared_ptr worker_thread_; size_t completed_segment_runner_nums_; struct Event { static constexpr const char* kInstantiateSegmentRunner = "kInstantiateSegmentRunner"; static constexpr const char* kRegisterWorker = "kRegisterWorker"; static constexpr const char* kCheckWorkComplete = "kCheckWorkComplete"; }; // Communication layer Parameter> server_; Parameter> client_; // Service layer Parameter initialize_segments_uri_; Parameter set_component_params_uri_; Parameter activate_segments_uri_; Parameter run_segments_uri_; Parameter deactivate_segments_uri_; Parameter destroy_segments_uri_; Parameter stop_worker_uri_; private: // Services to handle request from the GraphDriver Expected onInitializeSegments(const std::string& resource, const std::string& payload); Expected onSetComponentParams(const std::string& resource, const std::string& payload); Expected onActivateSegments(const std::string& resource, const std::string& payload); Expected onRunSegments(const std::string& resource, const std::string& payload); Expected onDeactivateSegments(const std::string& resource, const std::string& payload); Expected onDestroySegments(const std::string& resource, const std::string& payload); Expected onStopWorker(const std::string& resource, const std::string& payload); Expected instantiateSegmentRunners(); Expected registerGraphWorker(); Expected checkComplete(); std::unique_ptr worker_info_; gxf_result_t stop_all_segments(); // helper methods std::string getPrimaryIp(); Expected createWorkerInfo(); friend class SegmentRunner; }; // // utils for Parameter> // template <> struct ParameterParser { static Expected Parse( gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!node.IsMap() || node.size() < 2) { return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } GraphSpec graph_spec; // mandatory fields graph_spec.app_path = node["app-path"].as(); graph_spec.manifest_path = node["manifest-path"].as(); // optional fields if (node["param-path"].IsDefined()) { // Check if "param-path" is defined graph_spec.param_path = node["param-path"].as(); } else { graph_spec.param_path = ""; } if (node["severity"].IsDefined()) { graph_spec.severity = node["severity"].as(); } else { graph_spec.severity = 3; } return graph_spec; } }; template <> struct ParameterWrapper { // Wrap the value to a YAML::Node instance static Expected Wrap( gxf_context_t context, const GraphSpec& value) { YAML::Node node; // mandatory fields node["app-path"] = value.app_path; node["manifest-path"] = value.manifest_path; // optional fields if (!value.param_path.empty()) { node["param-path"] = value.param_path; } if (value.severity >= 0 && value.severity <= 4) { node["severity"] = value.severity; } return node; } }; template <> struct ParameterParser> { static Expected> Parse( gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { if (!node.IsMap()) { return Unexpected{GXF_PARAMETER_PARSER_ERROR}; } std::map segment_runners; for (const auto& p : node) { const std::string k = p.first.as(); const auto maybe = ParameterParser::Parse( context, component_uid, k.c_str(), node[k], prefix); if (!maybe) { return ForwardError(maybe); } segment_runners[k] = maybe.value(); } return segment_runners; } }; template <> struct ParameterWrapper> { // Wrap the value to a YAML::Node instance static Expected Wrap( gxf_context_t context, const std::map& value) { YAML::Node node(YAML::NodeType::Map); for (auto &i : value) { auto maybe = ParameterWrapper::Wrap(context, i.second); if (!maybe) { return ForwardError(maybe); } node[i.first] = maybe.value(); } return node; } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_GRAPH_WORKER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/greedy_scheduler.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_GREEDY_SCHEDULER_HPP_ #define NVIDIA_GXF_STD_GREEDY_SCHEDULER_HPP_ #include #include #include #include #include #include #include #include "common/fixed_vector.hpp" #include "common/logger.hpp" #include "gxf/core/component.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/clock.hpp" #include "gxf/std/gems/event_list/event_list.hpp" #include "gxf/std/scheduler.hpp" #include "gxf/std/scheduling_condition.hpp" namespace nvidia { namespace gxf { // Forward declarations class EntityExecutor; /// @brief A basic single-threaded scheduler which tests scheduling term greedily /// /// This scheduler is great for simple use cases and predictable execution. It evaluates /// scheduling terms greedily and may incur a large overhead of scheduling term execution. Thus it /// may not be suitable for large applications. /// /// The scheduler requires a Clock to keep track of time. Based on the choice of clock the scheduler /// will execute differently. If a Realtime clock is used the scheduler will execute in realtime. /// This means for example pausing execution, i.e. sleeping the thread, until periodic scheduling /// terms are due again. If a ManualClock is used scheduling will happen "time-compressed". This /// means flow of time is altered to execute codelets immediately after each other. class GreedyScheduler : public Scheduler { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t prepare_abi(EntityExecutor* executor) override; gxf_result_t schedule_abi(gxf_uid_t eid) override; gxf_result_t unschedule_abi(gxf_uid_t eid) override; gxf_result_t runAsync_abi() override; gxf_result_t stop_abi() override; gxf_result_t wait_abi() override; gxf_result_t event_notify_abi(gxf_uid_t eid, gxf_event_t event) override; private: Parameter> clock_; Parameter realtime_; Parameter max_duration_ms_; Parameter stop_on_deadlock_; Parameter check_recession_period_ms_; Parameter stop_on_deadlock_timeout_; EntityExecutor* executor_ = nullptr; std::atomic_bool stopping_{true}; std::atomic thread_error_code_; std::unique_ptr thread_ = nullptr; // Used temporarily until realtime flag is removed. Entity clock_entity_; // Used for keeping track of async events uint64_t count_wait_event_{0}; std::mutex event_mutex_; std::unique_ptr> event_notified_; std::unique_ptr> event_waiting_; std::condition_variable event_notification_cv_; // Used for keeping track of graph entities FixedVector active_entities_; FixedVector new_entities_; std::unique_ptr> unschedule_entities_; std::mutex entity_mutex_; // Dedicated mutex for each entity std::unordered_map> entity_mutex_map_; // latest timestamp from last should_stop == false int64_t last_no_stop_ts_ = 0; // maintain last no stop timestamp, and check if need to update should_stop gxf_result_t stop_on_deadlock_timeout(const int64_t timeout, const int64_t now, bool& should_stop); }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_GREEDY_SCHEDULER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/ipc_client.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GXF_STD_IPC_CLIENT_HPP_ #define NVIDIA_GXF_GXF_STD_IPC_CLIENT_HPP_ #include #include "gxf/core/component.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { /** * interface of client to IPCServer */ class IPCClient : public Component { public: static constexpr const char* kDefaultPingServiceName = "ping"; /** * param: * rervice: object that implements the query API * resource: on which the query is to be performed * return: text response that carries the result of a query */ virtual Expected query(const std::string& service, const std::string& resource) = 0; /** * param: * service: object that implements the action API * resource: on which the action is to be performed * data: action data * return: indicator of a success or failure */ virtual Expected action(const std::string& service, const std::string& resource, const std::string& data) = 0; virtual Expected ping(const std::string& service = kDefaultPingServiceName) = 0; virtual IPCClient& changeAddress(const std::string& ip, uint32_t port) = 0; protected: Parameter port_; Parameter server_ip_address_; std::string toIpPort(const std::string& ip, uint32_t port) { return ip + ":" + std::to_string(port); } }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/ipc_server.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_GXF_STD_IPC_SERVER_HPP_ #define NVIDIA_GXF_GXF_STD_IPC_SERVER_HPP_ #include #include #include "gxf/core/component.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { // interface of a request/response based server which accepts requests composed // of a list of strings as parameters and returns a text(json) response class IPCServer : public Component { public: typedef enum { kQuery = 0, kAction } ServiceType; // service handler for query requests // params: // resource: on which the query is to be performed // return: text response that carries the result of a query typedef std::function(const std::string& resource)> QueryHandler; // service handler for action requests // params: // resource: on which the action is to be performed // data: action data // return: indicator of a success or failure typedef std::function(const std::string& resource, const std::string& data)> ActionHandler; // callback to handle the request received by the server typedef struct { std::string name; ServiceType type; // TODO(chunlinl): use std::variant to wrap the handler once c++17 support is added struct { QueryHandler query; ActionHandler action; } handler; } Service; // register a named service on the IPC server to handler requests from remote clients virtual Expected registerService(const Service& service) = 0; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/memory_buffer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_MEMORY_BUFFER_HPP_ #define NVIDIA_GXF_STD_MEMORY_BUFFER_HPP_ #include #include "common/byte.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/allocator.hpp" namespace nvidia { namespace gxf { class MemoryBuffer { public: MemoryBuffer() = default; MemoryBuffer(const MemoryBuffer&) = delete; MemoryBuffer& operator=(const MemoryBuffer&) = delete; MemoryBuffer(MemoryBuffer&& other) { *this = std::move(other); } MemoryBuffer& operator=(MemoryBuffer&& other) { size_ = other.size_; storage_type_ = other.storage_type_; pointer_ = other.pointer_; release_func_ = std::move(other.release_func_); other.pointer_ = nullptr; other.release_func_ = nullptr; return *this; } // Type of the callback function to release memory passed to the MemoryBuffer // using the wrapMemory method using release_function_t = std::function (void* pointer)>; Expected freeBuffer() { if (release_func_ && pointer_) { const Expected result = release_func_(pointer_); if (!result) { return ForwardError(result); } release_func_ = nullptr; pointer_ = nullptr; size_ = 0; } return Success; } virtual ~MemoryBuffer() { freeBuffer(); } Expected resize(Handle allocator, uint64_t size, MemoryStorageType storage_type) { const auto result = freeBuffer(); if (!result) { GXF_LOG_ERROR("Failed to free memory. Error code: %s", GxfResultStr(result.error())); return ForwardError(result); } const auto maybe = allocator->allocate(size, storage_type); if (!maybe) { GXF_LOG_ERROR("%s Failed to allocate %ld size of memory of type %d. Error code: %s", allocator->name(), size, static_cast(storage_type), GxfResultStr(maybe.error())); return ForwardError(maybe); } storage_type_ = storage_type; pointer_ = maybe.value(); size_ = size; release_func_ = [allocator] (void *data) { return allocator->free(reinterpret_cast(data)); }; return Success; } // Wrap existing memory inside the MemoryBuffer. A callback function of type // release_function_t may be passed that will be called when the MemoryBuffer // wants to release the memory. Expected wrapMemory(void* pointer, uint64_t size, MemoryStorageType storage_type, release_function_t release_func) { if (pointer != this->pointer()) { const auto result = freeBuffer(); if (!result) { return ForwardError(result); } pointer_ = reinterpret_cast(pointer); } storage_type_ = storage_type; size_ = size; release_func_ = release_func; return Success; } // The type of memory where the data is stored. MemoryStorageType storage_type() const { return storage_type_; } // Raw pointer to the first byte of elements stored in the buffer. byte* pointer() const { return pointer_; } // Size of buffer contents in bytes uint64_t size() const { return size_; } protected: uint64_t size_ = 0; byte* pointer_ = nullptr; MemoryStorageType storage_type_ = MemoryStorageType::kHost; release_function_t release_func_ = nullptr; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_MEMORY_BUFFER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/metric.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_METRIC_HPP_ #define NVIDIA_GXF_STD_METRIC_HPP_ #include #include #include "gxf/core/component.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { // This component holds data for a single metric, where a metric is any double-typed value that is // computed during the execution of a GXF application, and has success criteria defined by a // lower threshold, an upper threshold, and an aggregation function that specifies how to // aggregate multiple samples into a final value for the metric. Other components in a GXF app can // access this component in order to, for example, write the metrics to a file for downstream // analysis of app execution. class Metric : public Component { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override { return GXF_SUCCESS; } // Type for the aggregation functor. using aggregation_function_t = std::function; // Records a single sample to the metric and updates aggregated_value_. Expected record(double sample); // Sets a custom function object to use when computing the aggregated_value_ over a set of // samples. Expected setAggregationFunction(aggregation_function_t aggregation_function); // Checks whether the aggregated_value_ lies within the expected range. Expected evaluateSuccess(); // Public accessor functions for metric data. Expected getAggregatedValue(); Expected getLowerThreshold(); Expected getUpperThreshold(); // Public functions to set a few common aggregation functions. // Computes the mean of a set of samples. Expected setMeanAggregationFunction(); // Computes the root-mean-square average over a set of samples. Expected setRootMeanSquareAggregationFunction(); // Finds the maximum absolute value over a set of samples. Expected setAbsMaxAggregationFunction(); // Finds the maximum over a set of samples. Expected setMaxAggregationFunction(); // Finds the minimum over a set of samples. Expected setMinAggregationFunction(); // Computes the total sum over a set of samples. Expected setSumAggregationFunction(); // Fixes the aggregated value to the last recorded sample. Expected setFixedAggregationFunction(); // Resets the aggregated value to an uninitialized value Expected reset(); private: Parameter aggregation_policy_; Parameter lower_threshold_; Parameter upper_threshold_; // Current aggregated value across all samples recorded to this metric. Updated on record(). Expected aggregated_value_ = Unexpected{GXF_UNINITIALIZED_VALUE}; // Function object that is used to update the metric's aggregated value based on a given sample. // The function accepts a sample and returns the updated aggregated value. Called on record(). aggregation_function_t aggregation_function_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_METRIC_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/monitor.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_MONITOR_HPP_ #define NVIDIA_GXF_STD_MONITOR_HPP_ #include "gxf/core/component.hpp" namespace nvidia { namespace gxf { // Interface for monitoring entities during runtime class Monitor : public Component { public: virtual ~Monitor() = default; // Callback for after an entity executes // eid - ID of entity that finished execution // timestamp - execution timestamp // code - execution result virtual gxf_result_t on_execute_abi(gxf_uid_t eid, uint64_t timestamp, gxf_result_t code) = 0; // C++ API wrapper Expected onExecute(gxf_uid_t eid, uint64_t timestamp, gxf_result_t code); }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_MONITOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/multi_thread_scheduler.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_MUTLI_THREAD_SCHEDULER_HPP_ #define NVIDIA_GXF_STD_MUTLI_THREAD_SCHEDULER_HPP_ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "gxf/core/entity.hpp" #include "gxf/core/handle.hpp" #include "gxf/std/clock.hpp" #include "gxf/std/cpu_thread.hpp" #include "gxf/std/gems/event_list/event_list.hpp" #include "gxf/std/gems/staging_queue/staging_queue.hpp" #include "gxf/std/gems/timed_job_list/timed_job_list.hpp" #include "gxf/std/scheduler.hpp" #include "gxf/std/scheduling_condition.hpp" namespace nvidia { namespace gxf { // Forward declarations class EntityExecutor; constexpr int64_t kMsToNs = 1'000'000l; // Convenient constant of 1 ms = 1e6 ns constexpr int64_t kMaxSlipNs = 1 * kMsToNs; // Max slip tolerance set to 1 ms /// @brief Multi-threaded scheduler /// /// The scheduler requires a Clock to keep track of time. It spawns a dispatcher thread and several /// worker threads as configured. Dispatcher thread checks condition of entities and place them in /// worker queue if they are ready to run or have expected time to run. class MultiThreadScheduler : public Scheduler { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t prepare_abi(EntityExecutor* executor) override; gxf_result_t schedule_abi(gxf_uid_t eid) override; gxf_result_t unschedule_abi(gxf_uid_t eid) override; gxf_result_t runAsync_abi() override; gxf_result_t stop_abi() override; gxf_result_t wait_abi() override; gxf_result_t event_notify_abi(gxf_uid_t eid, gxf_event_t event) override; private: std::atomic workerExecTime { 0 }; std::atomic workerWaitTime { 0}; std::atomic workerExecCount { 0 }; uint64_t dispatcherExecTime = 0; uint64_t dispatcherWaitTime = 0; uint64_t dispatcherExecCount = 0; // Entrance for dispatcher threads void dispatcherThreadEntrance(); // Entrance for async event handler thread void asyncEventThreadEntrance(); // Entrance for worker threads void workerThreadEntrance(ThreadPool* pool, int64_t thread_number); // Checks if need to stop due to no active entities or expiration void checkEndingCriteria(int64_t timestamp); // Updates condition of specific entity id and keep track of how many entities are good to run void updateCondition(gxf_uid_t eid, const SchedulingCondition& next_condition); // stops all async threads and deactivates all the entities gxf_result_t stopAllThreads(); // stops all jobs queued in dispatcher and workers void stopAllJobs(); // returns the current state of the scheduler as string const char* schedulerStateString(); // cache thread info for pinned job into resources_ void prepareResourceMap(gxf_uid_t eid); // cache thread info for every job into resources_, use default thread pool for non-pinned job void prepareResourceMapStrict(gxf_uid_t eid); // In worker thread, check if pinned job matches the thread bool isJobMatch(ThreadPool* pool, int64_t thread_number, gxf_uid_t eid); // In worker thread, check if the job matches the thread and if thread matches the job bool isJobMatchStrict(ThreadPool* pool, int64_t thread_number, gxf_uid_t eid); // Parameters Parameter> clock_; Parameter max_duration_ms_; Parameter check_recession_period_ms_; Parameter stop_on_deadlock_; Parameter stop_on_deadlock_timeout_; Parameter worker_thread_number_; Parameter thread_pool_allocation_auto_; Parameter strict_job_thread_pinning_; Parameter worker_thread_name_id_; EntityExecutor* executor_ = nullptr; ThreadPool default_thread_pool_; // thread pool set including default pool and added pools std::set thread_pool_set_; // Resource map for thread pools and worker threads std::map> resources_; gxf_result_t thread_error_code_; // A thread to dispatch jobs to worker pool std::thread dispatcher_thread_; // Mutex to synchronize dispatcher thread std::mutex dispatcher_sync_mutex_; // instances of dispatcher/worker threads. 0 index would be async event handler thread. std::vector async_threads_; // Keep track of the timestamp that the scheduler started working for checking expiration int64_t start_timestamp_ = 0; // Keep track of conditions for entities std::unordered_map conditions_; int64_t ready_count_{0}; int64_t wait_time_count_{0}; int64_t wait_event_count_{0}; int64_t wait_count_{0}; std::mutex conditions_mutex_; // Queue with execution time for jobs to execute std::unique_ptr> worker_jobs_; // Queue worker threads => dispatcher thread std::unique_ptr> check_jobs_; // synchronize entities std::mutex event_notification_mutex_; std::unique_ptr> unschedule_entities_; // Mutex to synchronize worker thread pool std::mutex thread_sync_mutex_; std::condition_variable thread_sync_cv_; // Keep track of asynchronous events std::unique_ptr> event_notified_; std::unique_ptr> event_waiting_; std::condition_variable event_notification_cv_; enum class State { kNotStarted = 0, // Scheduler has not started execution yet, starts during runAsync_abi() kRunning, // Execution threads are running kStopping, // Ending criteria reached, execution threads are doing pending jobs kStopped, // Scheduler has stopped }; std::atomic state_{State::kNotStarted}; std::mutex state_change_mutex_; std::condition_variable work_done_cv_; // latest timestamp from last should_stop == false int64_t last_no_stop_ts_ = 0; // maintain last no stop timestamp, and check if need to update should_stop gxf_result_t stop_on_deadlock_timeout(const int64_t timeout, const int64_t now, bool& should_stop); }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_MUTLI_THREAD_SCHEDULER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/network_context.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef GXF_STD_NETWORK_CONTEXT_HPP #define GXF_STD_NETWORK_CONTEXT_HPP #include "gxf/core/component.hpp" #include "gxf/core/handle.hpp" namespace nvidia { namespace gxf { class NetworkContext : public Component { public: virtual gxf_result_t init_context() = 0; // Finds transmitters and receivers passes the network context to transmitter // and receivers and make connection between them virtual Expected addRoutes(const Entity& entity) = 0; // Closes the connection between transmitters and receivers virtual Expected removeRoutes(const Entity& entity) = 0; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/new_component_allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_NEW_COMPONENT_ALLOCATOR_HPP #define NVIDIA_GXF_STD_NEW_COMPONENT_ALLOCATOR_HPP #include "gxf/core/expected.hpp" #include "gxf/std/component_allocator.hpp" namespace nvidia { namespace gxf { // Default implementation for allocating components using new/delete template class NewComponentAllocator : public ComponentAllocator { public: ~NewComponentAllocator() override = default; gxf_result_t allocate_abi(void** out_pointer) override { if (out_pointer == nullptr) { return GXF_ARGUMENT_NULL; } *out_pointer = static_cast(new T()); if (*out_pointer == nullptr) { return GXF_OUT_OF_MEMORY; } return GXF_SUCCESS; } gxf_result_t deallocate_abi(void* pointer) override { if (pointer == nullptr) { return GXF_ARGUMENT_NULL; } delete static_cast(pointer); return GXF_SUCCESS; } }; // Special case of standard component allocator for abstract components template class NewComponentAllocator::value>> : public ComponentAllocator { public: ~NewComponentAllocator() override = default; gxf_result_t allocate_abi(void** out_pointer) override { return GXF_FACTORY_ABSTRACT_CLASS; } gxf_result_t deallocate_abi(void* pointer) override { return GXF_FACTORY_ABSTRACT_CLASS; } }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/queue.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 202-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_QUEUE_HPP #define NVIDIA_GXF_STD_QUEUE_HPP #include "gxf/core/component.hpp" namespace nvidia { namespace gxf { // Interface for storing entities in a queue class Queue : public Component { public: virtual ~Queue() = default; // Gets the next (oldest) entity in the queue. virtual gxf_result_t pop_abi(gxf_uid_t* uid) = 0; // Adds a new entity to the queue. The receiver takes shared // ownership of the entity. virtual gxf_result_t push_abi(gxf_uid_t other) = 0; // Peeks the entity at given index on the main stage. virtual gxf_result_t peek_abi(gxf_uid_t* uid, int32_t index) = 0; // The total number of entities the queue can hold. virtual size_t capacity_abi() = 0; // The total number of entities the queue currently holds. virtual size_t size_abi() = 0; Expected pop(); Expected push(const Entity& other); Expected peek(int32_t index = 0); size_t capacity(); size_t size(); }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/receiver.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_RECEIVER_HPP #define NVIDIA_GXF_STD_RECEIVER_HPP #include #include "gxf/std/queue.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { // Interface for receiving entities. class Receiver : public Queue { public: // Receives the next entity from the main stage. virtual gxf_result_t receive_abi(gxf_uid_t* uid) = 0; // The total number of entities which have recently arrived but are not yet on the main stage. virtual size_t back_size_abi() = 0; // Peeks into back stage virtual gxf_result_t peek_back_abi(gxf_uid_t* uid, int32_t index) = 0; // Moves entities which recently arrived to the main stage. virtual gxf_result_t sync_abi() = 0; virtual gxf_result_t sync_io_abi() { return GXF_SUCCESS; } virtual gxf_result_t wait_abi() { return GXF_SUCCESS; } Expected receive(); size_t back_size(); Expected sync(); Expected sync_io(); Expected wait(); Expected peekBack(int32_t index = 0); Expected setTransmitter(Handle tx); private: std::set> connected_transmitters_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/resources.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_RESOURCES_HPP_ #define NVIDIA_GXF_STD_RESOURCES_HPP_ #include #include #include #include "gxf/core/component.hpp" #include "gxf/core/entity.hpp" namespace nvidia { namespace gxf { // A base type for all kinds of resources. // This is used to filter out resource Component from an entity class ResourceBase : public Component {}; class ThreadPool : public ResourceBase { public: struct Thread { gxf_uid_t uid; gxf_uid_t cpu_thread_cid; // Scalability: std::thread }; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; Expected addThread(gxf_uid_t key, gxf_uid_t cpu_thread_cid = kUnspecifiedUid); Expected addThread(gxf_uid_t key, const std::vector& pin_cores); const Expected getThread(gxf_uid_t key) const; const std::map& get() const; int64_t size() const; int64_t priority() const; std::vector coresToPin() const { const auto maybe_pin_cores = pin_cores_.try_get(); if (maybe_pin_cores) { return maybe_pin_cores.value(); } return {}; } private: Parameter initial_size_; Parameter priority_; // CPU core IDs to pin the worker threads to (empty means no core pinning) Parameter> pin_cores_; std::map thread_pool_; static inline gxf_uid_t next_uid_ = 0; }; class GPUDevice : public ResourceBase { public: gxf_result_t registerInterface(Registrar* registrar) override; int32_t device_id() const { return dev_id_; } private: Parameter dev_id_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_RESOURCES_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/scheduler.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gxf/core/gxf.h" #include "gxf/std/resources.hpp" #include "gxf/std/system.hpp" namespace nvidia { namespace gxf { class EntityExecutor; // forward declaration // An interface which extends the nvidia::gxf::System interface to create schedulers // which can execute codelets. class Scheduler : public System { public: virtual gxf_result_t prepare_abi(EntityExecutor* executor) = 0; }; #ifdef __linux__ // glibc before 2.41 does not provide wrappers for sched_setattr() and sched_getattr(), // so we need to define them here. #ifdef __x86_64__ #define __NR_sched_setattr 314 #define __NR_sched_getattr 315 #endif #ifdef __aarch64__ #define __NR_sched_setattr 274 #define __NR_sched_getattr 275 #endif struct sched_attr { uint32_t size; uint32_t sched_policy; uint64_t sched_flags; int32_t sched_nice; uint32_t sched_priority; uint64_t sched_runtime; uint64_t sched_deadline; uint64_t sched_period; }; static inline int sched_setattr(pid_t pid, const struct sched_attr* attr, unsigned flags) { return syscall(__NR_sched_setattr, pid, attr, flags); } static inline int sched_getattr(pid_t pid, struct sched_attr* attr, unsigned int size, unsigned int flags) { return syscall(__NR_sched_getattr, pid, attr, size, flags); } #endif } // namespace gxf } // namespace nvidia ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/scheduling_condition.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_SCHEDULING_CONDITION_HPP #define NVIDIA_GXF_STD_SCHEDULING_CONDITION_HPP #include namespace nvidia { namespace gxf { // The type of a scheduling condition enum class SchedulingConditionType : int32_t { // Will never execute again NEVER = 0, // Ready to execute now READY = 1, // May execute again at some point in the future WAIT = 2, // Will execute after a certain known time interval. Negative or zero interval will result in // immediate execution. WAIT_TIME = 3, // Waiting for an event with unknown interval time. Entity will be put in a waiting queue until // event done notification is signalled WAIT_EVENT = 4, }; // A condition for which the scheduling term is waiting. struct SchedulingCondition { // Describes the type of the condition SchedulingConditionType type; // A timestamp needed for certain conditions. Might not be set always. int64_t target_timestamp; }; // Merges two scheduling conditions with an And-like logic. For example NEVER and READY will result // in NEVER. SchedulingCondition AndCombine(SchedulingCondition a, SchedulingCondition b); // Gets a string describing the scheduling type condition const char* SchedulingConditionTypeStr(const SchedulingConditionType& condition_type); } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_SCHEDULING_CONDITION_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/scheduling_term.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_SCHEDULING_TERM_HPP #define NVIDIA_GXF_STD_SCHEDULING_TERM_HPP #include "gxf/core/component.hpp" #include "gxf/std/scheduling_condition.hpp" namespace nvidia { namespace gxf { /// @brief Base class for scheduling terms /// /// Scheduling terms are used by a scheduler to determine if codelets in an entity are ready for /// execution. class SchedulingTerm : public Component { public: virtual ~SchedulingTerm() = default; // Get the condition on which the scheduling waits before allowing execution. If the term is // waiting for a time event 'target_timestamp' will contain the target timestamp. virtual gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const = 0; // Called each time after the entity of this term was executed. virtual gxf_result_t onExecute_abi(int64_t dt) = 0; // Checks if the state of the scheduling term can be updated and updates it virtual gxf_result_t update_state_abi(int64_t timestamp) { return GXF_SUCCESS; } Expected check(int64_t timestamp) { SchedulingConditionType status; int64_t target_timestamp = 0; gxf_result_t result = update_state_abi(timestamp); if (result != GXF_SUCCESS) { return Unexpected{result}; } const gxf_result_t error = check_abi(timestamp, &status, &target_timestamp); return ExpectedOrCode(error, SchedulingCondition{status, target_timestamp}); } Expected onExecute(int64_t timestamp) { return ExpectedOrCode(onExecute_abi(timestamp)); } }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/scheduling_term_combiner.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_SCHEDULING_TERM_COMBINER_HPP #define NVIDIA_GXF_STD_SCHEDULING_TERM_COMBINER_HPP #include #include #include "gxf/std/scheduling_term.hpp" namespace nvidia { namespace gxf { /** * @brief Base class for scheduling term combiner * * scheduling term combiners can be used to create complex execution patterns by interpreting * combinations of scheduling terms differently */ class SchedulingTermCombiner : public Component { public: // Function to combine two SchedulingCondition types virtual SchedulingCondition combine(SchedulingCondition a, SchedulingCondition b) = 0; // Get the list of scheduling terms in an entity being governed by the combiner virtual FixedVector, kMaxComponents> getTermList() const = 0; }; /** * @brief OR combiners simulate the bitwise OR operation when combining scheduling conditions * */ class OrSchedulingTermCombiner : public SchedulingTermCombiner { public: gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(terms_, "terms", "SchedulingTerms", "The list of scheduling terms to be combined using OR operation"); return GXF_SUCCESS; } SchedulingCondition combine(SchedulingCondition a, SchedulingCondition b) override { // "never" has the highest significance if (a.type == SchedulingConditionType::NEVER || b.type == SchedulingConditionType::NEVER) { return {SchedulingConditionType::NEVER, 0}; } // If both are ready, choose the max target timestamp if (a.type == SchedulingConditionType::READY && b.type == SchedulingConditionType::READY) { return {SchedulingConditionType::READY, std::max(a.target_timestamp, b.target_timestamp)}; } // Check if either one of them is ready if (a.type == SchedulingConditionType::READY) { return {SchedulingConditionType::READY, a.target_timestamp}; } else if (b.type == SchedulingConditionType::READY) { return {SchedulingConditionType::READY, b.target_timestamp}; } // "wait event" has the third highest significance if (a.type == SchedulingConditionType::WAIT_EVENT || b.type == SchedulingConditionType::WAIT_EVENT) { return {SchedulingConditionType::WAIT_EVENT, 0}; } // "wait time" events are combined so that the maximum time is returned if (a.type == SchedulingConditionType::WAIT_TIME && b.type == SchedulingConditionType::WAIT_TIME) { return {SchedulingConditionType::WAIT_TIME, std::max(a.target_timestamp, b.target_timestamp)}; } // Check if atleast one of them have a target time if (a.type == SchedulingConditionType::WAIT_TIME) { return a; } else if (b.type == SchedulingConditionType::WAIT_TIME) { return b; } // The only remaining case is that both are wait return {SchedulingConditionType::WAIT, 0}; } FixedVector, kMaxComponents> getTermList() const { return terms_; } Parameter, kMaxComponents>> terms_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_SCHEDULING_TERM_COMBINER_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/scheduling_terms.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_SCHEDULING_TERMS_HPP_ #define NVIDIA_GXF_STD_SCHEDULING_TERMS_HPP_ #include #include #include #include #include "gxf/core/component.hpp" #include "gxf/core/handle.hpp" #include "gxf/core/parameter_parser.hpp" #include "gxf/core/parameter_parser_std.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/clock.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/scheduling_term.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { enum class PeriodicSchedulingPolicy { // scheduler will try to "catch up" on missed ticks // eg. assume recess period of 100ms: // tick 0 at 0ms -> next_target_ = 100ms // tick 1 at 250ms -> next_target_ = 200ms (next_target_ < timestamp) // tick 2 at 255ms -> next_target_ = 300ms (double tick before 300ms) kCatchUpMissedTicks, // scheduler guarantees recess period will have passed before next tick // eg. assume recess period of 100ms: // tick 0 at 0ms -> next_target_ = 100ms // tick 1 at 101ms -> next_target_ = 201ms // tick 2 at 350ms -> next_target_ = 450ms kMinTimeBetweenTicks, // scheduler will not try to "catch up" on missed ticks // eg. assume recess period of 100ms: // tick 0 at 0ms -> next_target_ = 100ms // tick 1 at 250ms -> next_target_ = 300ms (single tick before 300ms) // tick 2 at 305ms -> next_target_ = 400ms kNoCatchUpMissedTicks }; // Custom parameter parser for PeriodicSchedulingPolicy template <> struct ParameterParser { static Expected Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { const std::string value = node.as(); if (strcmp(value.c_str(), "CatchUpMissedTicks") == 0) { return PeriodicSchedulingPolicy::kCatchUpMissedTicks; } if (strcmp(value.c_str(), "MinTimeBetweenTicks") == 0) { return PeriodicSchedulingPolicy::kMinTimeBetweenTicks; } if (strcmp(value.c_str(), "NoCatchUpMissedTicks") == 0) { return PeriodicSchedulingPolicy::kNoCatchUpMissedTicks; } return Unexpected{GXF_ARGUMENT_OUT_OF_RANGE}; } }; // Custom parameter wrapper for PeriodicSchedulingPolicy template<> struct ParameterWrapper { static Expected Wrap(gxf_context_t context, const PeriodicSchedulingPolicy& value) { YAML::Node node(YAML::NodeType::Scalar); switch (value) { case PeriodicSchedulingPolicy::kCatchUpMissedTicks: { node = std::string("CatchUpMissedTicks"); break; } case PeriodicSchedulingPolicy::kMinTimeBetweenTicks: { node = std::string("MinTimeBetweenTicks"); break; } case PeriodicSchedulingPolicy::kNoCatchUpMissedTicks: { node = std::string("NoCatchUpMissedTicks"); break; } default: return Unexpected{GXF_PARAMETER_OUT_OF_RANGE}; } return node; } }; // A scheduling term which permits execution only after a minimum time period has passed since the // last execution. class PeriodicSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; // Minimum time which needs to elapse between two executions (in nano seconds). int64_t recess_period_ns() const { return recess_period_ns_; } // Get the last run time stamp Expected last_run_timestamp() const { return next_target_ - recess_period_ns_; } private: Parameter recess_period_; Parameter policy_; int64_t recess_period_ns_ = 0; Expected next_target_ = Unexpected{GXF_UNINITIALIZED_VALUE}; }; // A scheduling term which permits execution only a limited number of times. class CountSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; gxf_result_t update_state_abi(int64_t timestamp) override; private: Parameter count_; // The remaining number of permitted executions. int64_t remaining_; SchedulingConditionType current_state_; // The current state of the scheduling term int64_t last_run_timestamp_; // timestamp when the entity was last executed }; // A component which specifies that an entity shall be executed if the receiver for a given // transmitter can accept new messages. class DownstreamReceptiveSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; gxf_result_t update_state_abi(int64_t timestamp) override; // The transmitter which needs to be able to publish a message. Handle transmitter() const { return transmitter_.get(); } // The receiver which is connected to the transmitter and which needs to have room for messages. void setReceivers(std::set> receivers) { receivers_ = std::move(receivers); } // Set the transmitter parameter Expected setTransmitter(Handle value) { return transmitter_.set(value); } // Set the min_size parameter Expected setMinSize(uint64_t value) { return min_size_.set(value); } private: Parameter> transmitter_; Parameter min_size_; std::set> receivers_; // The receiver connected to the transmitter (if any). SchedulingConditionType current_state_; // The current state of the scheduling term int64_t last_state_change_; // timestamp when the state changed the last time }; // A scheduling term which permits execution at a user-specified timestamp. The timestamp is // specified on the clock provided. class TargetTimeSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; // Needs to be called to determine how long to wait for the next execution. If it is not called, // the scheduling condition will stay as WAIT. gxf_result_t setNextTargetTime(int64_t target_timestamp); private: Parameter> clock_; // The timestamp at which the most recent execution cycle began int64_t last_timestamp_; // The timestamp at which the next execution cycle is requested to begin mutable Expected target_timestamp_ = Unexpected{GXF_UNINITIALIZED_VALUE}; // The timestamp at which the next execution cycle is locked to begin mutable Expected locked_target_timestamp_ = Unexpected{GXF_UNINITIALIZED_VALUE}; }; // A component which specifies that an entity shall be executed when a queue has at least a certain // number of elements. class MessageAvailableSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; gxf_result_t update_state_abi(int64_t timestamp) override; // Set the receiver parameter Expected setReceiver(Handle value) { return receiver_.set(value); } // Set the min_size parameter Expected setMinSize(size_t value) { return min_size_.set(value); } // Set the front_stage_max_size parameter Expected setFrontStageMaxSize(size_t value) { return front_stage_max_size_.set(value); } private: // Returns true if the condition imposed by min_size is true. bool checkMinSize() const; // Returns true if the condition imposed by front_stage_max_size is true. bool checkFrontStageMaxSize() const; Parameter> receiver_; Parameter min_size_; Parameter front_stage_max_size_; SchedulingConditionType current_state_; // The current state of the scheduling term int64_t last_state_change_; // timestamp when the state changed the last time }; // Type of sampling to be used for incoming messages enum struct SamplingMode { kSumOfAll = 0, // Min size specified is for the sum of all messages at all receivers; kPerReceiver = 1, // Min size specified is per receiver connected; }; // Custom parameter parser for SamplingMode template <> struct ParameterParser { static Expected Parse(gxf_context_t context, gxf_uid_t component_uid, const char* key, const YAML::Node& node, const std::string& prefix) { const std::string value = node.as(); if (strcmp(value.c_str(), "SumOfAll") == 0) { return SamplingMode::kSumOfAll; } if (strcmp(value.c_str(), "PerReceiver") == 0) { return SamplingMode::kPerReceiver; } return Unexpected{GXF_ARGUMENT_OUT_OF_RANGE}; } }; // Custom parameter wrapper for SamplingMode template<> struct ParameterWrapper { static Expected Wrap(gxf_context_t context, const SamplingMode& value) { YAML::Node node(YAML::NodeType::Scalar); switch (value) { case SamplingMode::kSumOfAll: { node = std::string("SumOfAll"); break; } case SamplingMode::kPerReceiver: { node = std::string("PerReceiver"); break; } default: return Unexpected{GXF_PARAMETER_OUT_OF_RANGE}; } return node; } }; // A scheduling term which specifies that an entity can be executed when a list of provided input // channels combined have at least a given number of messages. class MultiMessageAvailableSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; gxf_result_t update_state_abi(int64_t timestamp) override; // Set the min_size parameter Expected setMinSize(size_t value) { return min_size_.set(value); } // Set the min_sum parameter Expected setMinSum(size_t value) { return min_sum_.set(value); } // Set the sampling_mode parameter Expected setSamplingMode(SamplingMode value) { return sampling_mode_.set(value); } // Add a value to receivers parameter Expected addReceiver(Handle value) { auto rxs = receivers_.get(); auto result = rxs.push_back(value); if (!result) { return Unexpected(GXF_OUT_OF_MEMORY); } return receivers_.set(rxs); } // Add a value to min_sizes parameter Expected addMinSize(size_t value) { auto min_sizes = min_sizes_.get(); auto result = min_sizes.push_back(value); if (!result) { return Unexpected(GXF_OUT_OF_MEMORY); } return min_sizes_.set(min_sizes); } private: Parameter, kMaxComponents>> receivers_; Parameter min_size_; Parameter min_sum_; SchedulingConditionType current_state_; // The current state of the scheduling term int64_t last_state_change_; // timestamp when the state changed the last time Parameter> min_sizes_; Parameter sampling_mode_; }; // A scheduling term which tries to wait for specified number of messages in receiver. // When the first message in the queue mature after specified delay since arrival it would fire // regardless. class ExpiringMessageAvailableSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; private: Parameter max_batch_size_; Parameter max_delay_ns_; Parameter> receiver_; // The receiver to check Parameter> clock_; }; // A scheduling term which acts as a boolean AND term to control execution of the // entity class BooleanSchedulingTerm : public SchedulingTerm { public: // Enable entity execution Expected enable_tick(); // Disable entity execution Expected disable_tick(); // Returns true if the tick is enabled. bool checkTickEnabled() const; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t dt) override; private: Parameter enable_tick_; }; // A Behavior Tree (BT) scheduling term which is referenced by the BT entity // itself and the entity's parent (if any) used to schedule the entity itself or // its child entities (if any) in BT class BTSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t dt) override; // called by the entity's codelet (start/stop the entity itself) or the parent // entity's codelet (start/stop the child) in BT gxf_result_t set_condition(SchedulingConditionType type); private: Parameter is_root_; SchedulingConditionType scheduling_condition_type_{SchedulingConditionType::READY}; }; enum class AsynchronousEventState { READY = 0, // Init state, first tick is pending WAIT, // Request to async service yet to be sent, nothing to do but wait EVENT_WAITING, // Request sent to an async service, pending event done notification EVENT_DONE, // Event done notification received, entity ready to be ticked EVENT_NEVER, // Entity does not want to be ticked again, end of execution }; // A scheduling term which waits on an asynchronous event from the codelet which can happen outside // of the regular tick function. class AsynchronousSchedulingTerm : public SchedulingTerm { public: gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t dt) override; void setEventState(AsynchronousEventState state); AsynchronousEventState getEventState() const; private: AsynchronousEventState event_state_{AsynchronousEventState::READY}; mutable std::mutex event_state_mutex_; }; // A scheduling term which lets an entity maintain a specific execution (min) frequency // The scheduling term will also monitor messages incoming via multiple receivers and // switch to READY state if any messages are available class MessageAvailableFrequencyThrottler : public SchedulingTerm { public: gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t timestamp) override; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t update_state_abi(int64_t timestamp) override; private: Expected last_run_timestamp_ = Unexpected{GXF_UNINITIALIZED_VALUE}; Parameter execution_frequency_text_; Parameter, kMaxComponents>> receivers_; Parameter min_sum_; Parameter> min_sizes_; Parameter sampling_mode_; int64_t message_recess_period_; int64_t execution_frequency_; SchedulingConditionType current_state_; // The current state of the scheduling term int64_t last_state_change_; // timestamp when the state changed the last time }; // A scheduling term which waits until a given number of blocks are // available in a pool. This can be used to force a codelet to wait // until a minimum number of its in-flight buffers have returned from // downstream consumers. class MemoryAvailableSchedulingTerm : public SchedulingTerm { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t check_abi(int64_t timestamp, SchedulingConditionType* type, int64_t* target_timestamp) const override; gxf_result_t onExecute_abi(int64_t dt) override; gxf_result_t update_state_abi(int64_t timestamp) override; private: bool is_available() const; Parameter> allocator_; Parameter min_bytes_parameter_; Parameter min_blocks_parameter_; // actual minimum number of bytes, computed from parameters uint64_t min_bytes_; SchedulingConditionType current_state_; // The current state of the scheduling term int64_t last_state_change_; // timestamp when the state changed the last time }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_SCHEDULING_TERMS_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/system.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_CORE_SYSTEM_HPP #define NVIDIA_GXF_CORE_SYSTEM_HPP #include "gxf/core/component.hpp" namespace nvidia { namespace gxf { // Component interface for systems which are run as part of the application run cycle. class System : public Component { public: virtual ~System() = default; virtual gxf_result_t schedule_abi(gxf_uid_t eid) = 0; virtual gxf_result_t unschedule_abi(gxf_uid_t eid) = 0; virtual gxf_result_t runAsync_abi() = 0; virtual gxf_result_t stop_abi() = 0; virtual gxf_result_t wait_abi() = 0; virtual gxf_result_t event_notify_abi(gxf_uid_t eid, gxf_event_t event) = 0; Expected schedule(const Entity& entity); Expected unschedule(const Entity& entity); Expected runAsync(); Expected stop(); Expected wait(); Expected event_notify(gxf_uid_t eid, gxf_event_t event); }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/tensor.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include #include #include "common/byte.hpp" #include "dlpack/dlpack.h" #include "gxf/core/component.hpp" #include "gxf/core/expected.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/complex.hpp" #include "gxf/std/dlpack_utils.hpp" #include "gxf/std/memory_buffer.hpp" namespace nvidia { namespace gxf { // Type of parameters and other primitives enum class PrimitiveType : int32_t { kCustom, kInt8, kUnsigned8, kInt16, kUnsigned16, kInt32, kUnsigned32, kInt64, kUnsigned64, kFloat32, kFloat64, kComplex64, kComplex128, kFloat16, }; // Returns the size of each element of specific PrimitiveType as number of bytes. // Returns 0 for kCustom. uint64_t PrimitiveTypeSize(PrimitiveType primitive); template struct PrimitiveTypeTraits; #define GXF_PRIMITIVE_TYPE_TRAITS(TYPE, ENUM) \ template <> struct PrimitiveTypeTraits { \ static constexpr PrimitiveType value = PrimitiveType::ENUM; \ static constexpr size_t size = sizeof(TYPE); \ }; \ GXF_PRIMITIVE_TYPE_TRAITS(int8_t, kInt8); GXF_PRIMITIVE_TYPE_TRAITS(uint8_t, kUnsigned8); GXF_PRIMITIVE_TYPE_TRAITS(int16_t, kInt16); GXF_PRIMITIVE_TYPE_TRAITS(uint16_t, kUnsigned16); GXF_PRIMITIVE_TYPE_TRAITS(int32_t, kInt32); GXF_PRIMITIVE_TYPE_TRAITS(uint32_t, kUnsigned32); GXF_PRIMITIVE_TYPE_TRAITS(int64_t, kInt64); GXF_PRIMITIVE_TYPE_TRAITS(uint64_t, kUnsigned64); GXF_PRIMITIVE_TYPE_TRAITS(__half, kFloat16); GXF_PRIMITIVE_TYPE_TRAITS(float, kFloat32); GXF_PRIMITIVE_TYPE_TRAITS(double, kFloat64); GXF_PRIMITIVE_TYPE_TRAITS(complex64, kComplex64); GXF_PRIMITIVE_TYPE_TRAITS(complex128, kComplex128); // Type to hold the shape of a tensor class Shape { public: // The maximum possible rank of the tensor. static constexpr uint32_t kMaxRank = 8; // Initializes an empty rank-0 tensor. Shape() : rank_(0) {} // Initializes a shape object with the given dimensions. Shape(std::initializer_list dimensions) : rank_(0) { for (int32_t dimension : dimensions) { if (rank_ == kMaxRank) { return; } dimensions_[rank_++] = dimension; } } // Creates shape from vector Shape(const std::vector& dimensions) : rank_(0) { for (int32_t dimension : dimensions) { if (rank_ == kMaxRank) { return; } dimensions_[rank_++] = dimension; } } // Creates shape from array Shape(const std::array& dims, uint32_t rank) : rank_(rank), dimensions_(dims) { } // Creates shape from array with correct rank template Shape(const std::array& dims) : rank_(N) { static_assert(N < kMaxRank, "Invalid rank"); for (size_t i = 0; i < N; i++) { dimensions_[i] = dims[i]; } } // The rank of the tensor uint32_t rank() const { return rank_; } // The total number of elements in the tensor. Note: this is not the same as the number of bytes // required in memory. uint64_t size() const { uint64_t element_count = 1; for (size_t i = 0; i < rank_; i++) { element_count *= dimensions_[i]; } return rank_ == 0 ? 0 : element_count; } // Gets the i-th dimension of the tensor. // Special cases: // If the rank is 0 the function always returns 0. // If 'index' is greater or equal than the rank the function returns 1. int32_t dimension(uint32_t index) const { if (rank_ == 0) { return 0; } else if (index >= rank_) { return 1; } else { return dimensions_[index]; } } bool operator== (const Shape& other) const { if (rank_ != other.rank_) { return false; } for (uint32_t i = 0; i < rank_; ++i) { if (dimensions_[i] != other.dimensions_[i]) { return false; } } return true; } bool operator!= (const Shape& other) const { return !(*this == other); } // Check whether shape is valid bool valid() const { for (uint32_t i = 0; i < rank_; ++i) { if (dimensions_[i] <= 0) { return false; } } return true; } private: uint32_t rank_ = 0; std::array dimensions_; }; /** * @brief Class that wraps a DLManagedTensor with a memory data reference. * * This class is used to wrap a DLManagedTensor (`tensor`) with a shared pointer to the memory * data (`memory_ref`). This class also holds shape and strides data in the integer type needed by * the DLTensor object since this does not exist as contiguous int64_t on the Tensor object * itself. It should also be noted that DLPack `dl_strides` stored here are in number of elements * while those returned by `Tensor::stride` are in bytes rather than elements. * * The DLPack protocol is designed so that the producer (GXF in the case of `toDLPack` or * `toDLManagedTensorContext`) continues to own the data. When the borrowing framework no longer * needs the tensor, it should call the deleter to notify the producer that the resource is no * longer needed. * * See: https://dmlc.github.io/dlpack/latest/c_api.html#_CPPv415DLManagedTensor */ struct DLManagedTensorContext { DLManagedTensor tensor; ///< The DLManagedTensor to wrap. std::shared_ptr memory_ref; ///< The memory data reference. std::vector dl_shape; ///< Shape of the DLTensor. std::vector dl_strides; ///< Strides of the DLTensor. }; /** * @brief Class to wrap the deleter of a DLManagedTensor. * * This class is used with DLManagedTensorContext class to wrap the DLManagedTensor. * * A shared pointer to this class in DLManagedTensorContext class is used as the deleter of the * DLManagedTensorContext::memory_ref. * * When the last reference to the DLManagedTensorContext object is released, * DLManagedTensorContext::memory_ref will also be destroyed, which will call the deleter function * of the DLManagedTensor object. This allows setting release_func to nullptr when calling * wrapTensor within fromDLPack. * */ class DLManagedMemoryBuffer { public: explicit DLManagedMemoryBuffer(DLManagedTensor* self); ~DLManagedMemoryBuffer(); private: DLManagedTensor* self_ = nullptr; }; // A component which holds a single tensor. Multiple tensors can be added to one // entity to create a map of tensors. The component name can be used as key. class Tensor { public: typedef std::array stride_array_t; Tensor() = default; ~Tensor() { memory_buffer_.freeBuffer(); // FIXME(V2) error code? dl_ctx_.reset(); element_count_ = 0; shape_ = Shape(); } Tensor(const Tensor&) = delete; Tensor(Tensor&& other) { *this = std::move(other); } // zero-copy initialization from an existing DLPack DLManagedTensor (C API struct) explicit Tensor(const DLManagedTensor* dl_managed_tensor_ptr); // zero-copy initialization from an existing DLManagedTensorContext (C++-style DLPack wrapper) explicit Tensor(std::shared_ptr dl_ctx); Tensor& operator=(const Tensor&) = delete; Tensor& operator=(Tensor&& other) { shape_ = other.shape_; element_count_ = other.element_count_; element_type_ = other.element_type_; bytes_per_element_ = other.bytes_per_element_; strides_ = std::move(other.strides_); memory_buffer_ = std::move(other.memory_buffer_); dl_ctx_ = std::move(other.dl_ctx_); return *this; } // The type of memory where the tensor data is stored. MemoryStorageType storage_type() const { return memory_buffer_.storage_type(); } // The shape of the dimensions holds the rank and the dimensions. const Shape& shape() const { return shape_; } // The rank of the tensor. uint32_t rank() const { return shape_.rank(); } // The scalar type of elements stored in the tensor PrimitiveType element_type() const { return element_type_; } // Number of bytes stored per element uint64_t bytes_per_element() const { return bytes_per_element_; } // Total number of elements stored in the tensor. uint64_t element_count() const { return element_count_; } // Size of tensor contents in bytes size_t size() const { return memory_buffer_.size(); } // Raw pointer to the first byte of elements stored in the tensor. byte* pointer() const { return memory_buffer_.pointer(); } // Move the memory buffer MemoryBuffer move_buffer() { return std::move(memory_buffer_); } // Gets a pointer to the first element stored in this tensor. Requested type must match the // tensor element type. template Expected data() { if (element_type_ != PrimitiveType::kCustom && PrimitiveTypeTraits::value != element_type_) { return Unexpected{GXF_INVALID_DATA_FORMAT}; } return reinterpret_cast(memory_buffer_.pointer()); } // Gets a pointer to the first element stored in this tensor. Requested type must match the // tensor element type. template Expected data() const { if (element_type_ != PrimitiveType::kCustom && PrimitiveTypeTraits::value != element_type_) { return Unexpected{GXF_INVALID_DATA_FORMAT}; } return reinterpret_cast(memory_buffer_.pointer()); } // Changes the shape and type of the tensor. Uses a primitive type and dense memory layot. // Memory will be allocated with the given allocator. template Expected reshape(const Shape& shape, MemoryStorageType storage_type, Handle allocator) { return reshapeCustom(shape, PrimitiveTypeTraits::value, PrimitiveTypeTraits::size, Unexpected{GXF_UNINITIALIZED_VALUE}, storage_type, allocator); } // Changes the shape and type of the tensor. Memory will be allocated with the given allocator // strides: The number of bytes that each slide takes for each dimension (alignment). // Use ComputeStrides() to calculate it. Expected reshapeCustom(const Shape& shape, PrimitiveType element_type, uint64_t bytes_per_element, Expected strides, MemoryStorageType storage_type, Handle allocator); // Type of the callback function to release memory passed to the tensor using the // wrapMemory method using release_function_t = MemoryBuffer::release_function_t; // Wrap existing memory inside the tensor. A callback function of type release_function_t // may be passed that will be called when the Tensor wants to release the memory. Expected wrapMemory(const Shape& shape, PrimitiveType element_type, uint64_t bytes_per_element, Expected strides, MemoryStorageType storage_type, void* pointer, release_function_t release_func, bool reset_dlpack = true); // Wraps an existing memory buffer element into the current tensor Expected wrapMemoryBuffer(const Shape& shape, PrimitiveType element_type, uint64_t bytes_per_element, Expected strides, MemoryBuffer memory_buffer); // Permute the axes of a tensor. // Number of axes must match rank of tensor. // Note that since no data is moved, permuting a tensor can be // detrimental to performance (data not accessed from the same cache line). Expected permute(const std::initializer_list& axes); // Attempts to reshape the array in memory by modifying the strides // Assumes tensor data is stored in row-major order. // The product of the element of the new shape must equal the product // of the tensor's dimensions // Adapted from Numpy: // https://github.com/numpy/numpy/blob/45bc13e6d922690eea43b9d807d476e0f243f836/ // numpy/core/src/multiarray/shape.c#L371 Expected noCopyReshape(const std::initializer_list& new_shape); // Insert singleton dimension at specified dimension Expected insertSingletonDim(uint32_t dimension); // Is tensor memory access contiguous? Expected isContiguous(); // The size of data in bytes uint64_t bytes_size() { return shape_.dimension(0) * strides_[0]; } // The stride of specified rank in bytes uint64_t stride(uint32_t index) const { if (index >= shape_.rank()) { return 0; } return strides_[index]; } // Get a new DLManagedTensor* corresponding to the Tensor data. // An alternative is to use toDLManagedTensorContext instead which returns a shared pointer // that will automatically clean up resources once its reference count goes to zero. Expected toDLPack(); /** * @brief Get the internal DLManagedTensorContext of the Tensor. * * @return A shared pointer to the Tensor's DLManagedTensorContext. */ Expected&> toDLManagedTensorContext() { if (dl_ctx_ == nullptr) { auto status = initializeDLContext(); if (!status) { GXF_LOG_ERROR( "Failed to initialize DLManagedTensorContext with code: %s, returning nullptr", GxfResultStr(status.error())); ForwardError(status); } } return dl_ctx_; } // Wrap an existing DLPack managed tensor as a Tensor. Expected fromDLPack(const DLManagedTensor* dl_managed_tensor_ptr); // Wrap an existing shared C++ DLManagedTensorContext as a Tensor. Expected fromDLPack(std::shared_ptr dl_ctx); protected: // This member will be populated when memory_buffer_ is initialized or updated, allowing it to // be used to provide the DLPack interface. std::shared_ptr dl_ctx_; ///< The DLManagedTensorContext object. private: Shape shape_; uint64_t element_count_ = 0; PrimitiveType element_type_ = PrimitiveType::kUnsigned8; uint64_t bytes_per_element_ = 1; stride_array_t strides_; MemoryBuffer memory_buffer_; /** * @brief Get DLDevice object from the GXF Tensor. * * @return DLDevice object. */ Expected device() const; // populate DLPack data structures corresponding to the current Tensor Expected initializeDLContext(); // If dl_ctx_ has already been initialized, reset it and initialize a new one Expected updateDLContext(); // call wrapTensor using data from an existing DLManagedTensor Expected wrapDLPack(const DLManagedTensor* dl_managed_tensor_ptr, MemoryBuffer::release_function_t release_func = nullptr); }; // Helper function to compute strides from Tensor shape, element size and non-trivial // alignment step size for row dimension. // The third rank from the end is assumed to be the row dimension. Expected ComputeRowStrides(const Shape& shape, uint32_t row_step_size, const uint32_t bytes_per_element); // Helper function to compute trivial strides from Tensor shape and element size Tensor::stride_array_t ComputeTrivialStrides(const Shape& shape, const uint32_t bytes_per_element); // Helper function to compute strides from steps (minimal number of bytes per slice on each rank) Tensor::stride_array_t ComputeStrides(const Shape& shape, const Tensor::stride_array_t& stride_steps); // Type to description a tensor used by 'CreateTensorMap' struct TensorDescription { std::string name; MemoryStorageType storage_type; Shape shape; PrimitiveType element_type; uint64_t bytes_per_element; // array providing number of bytes for each slice on each rank Expected strides = Unexpected{GXF_UNINITIALIZED_VALUE}; }; // Creates a new entity with a collection of named tensors Expected CreateTensorMap(gxf_context_t context, Handle pool, std::initializer_list descriptions, bool activate = true); // Determine tensor shape from a DLTensor struct Expected ShapeFromDLTensor(const DLTensor* dl_tensor); // Determine tensor strides from a DLTensor struct Expected StridesFromDLTensor(const DLTensor* dl_tensor); // Determine the tensor memory storage type from a DLTensor struct Expected MemoryStorageTypeFromDLTensor(const DLTensor* dl_tensor); // Determine the tensor primitive data type from a DLDataType struct Expected PrimitiveTypeFromDLDataType(const DLDataType& dtype); // Convert PrimitiveType to its corresponding DLDataType Expected PrimitiveTypeToDLDataType(const PrimitiveType& element_type, uint16_t lanes = 1); } // namespace gxf } // namespace nvidia ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/timestamp.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_TIMESTAMP_HPP #define NVIDIA_GXF_STD_TIMESTAMP_HPP #include #include #include "common/fixed_vector.hpp" #include "gxf/core/expected.hpp" namespace nvidia { namespace gxf { // Contains timing information for the data in a message. All times are relative to the global GXF // clock and in nanoseconds. struct Timestamp { // The timestamp in nanoseconds at which the message was published into the system. int64_t pubtime; // The timestamp in nanoseconds at the message was acquired. This usually refers to the timestamp // of the original sensor data which created the message. int64_t acqtime; }; enum class TimeDomainID : uint8_t { // Specifies various sources of timestamp TSC = 0, NTP, PTP, TIME_DOMAIN_COUNT // Used to determine the maximum no of timestamp sources available }; static constexpr ssize_t MAX_TIME_DOMAINS = static_cast(TimeDomainID::TIME_DOMAIN_COUNT); // Associate timestamp with its source using MultiSourceTimestamp = FixedVector, MAX_TIME_DOMAINS>; // This function retrieves the timestamp corresponding to the time domain ID Expected getTimestamp(MultiSourceTimestamp const& timestamps, TimeDomainID const& timeDomainId); } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_TIMESTAMP_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/topic.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_TOPIC_HPP #define NVIDIA_GXF_STD_TOPIC_HPP #include #include #include "gxf/std/receiver.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace gxf { // Class to add transmitters/receivers to a topic channel. class Topic : public Component { public: gxf_result_t registerInterface(Registrar* registrar) override; // Get topic name. std::string getTopicName() const { return topic_name_.get().empty() ? std::string(name()) : topic_name_; } // Get all transmitters in this topic. std::vector> getTransmitters() const { return transmitters_.get(); } // Get all receivers in this topic. std::vector> getReceivers() const { return receivers_.get(); } private: Parameter topic_name_; Parameter>> receivers_; Parameter>> transmitters_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/transmitter.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_TRANSMITTER_HPP #define NVIDIA_GXF_STD_TRANSMITTER_HPP #include "gxf/std/queue.hpp" namespace nvidia { namespace gxf { // Interface for publishing entities. class Transmitter : public Queue { public: // Publishes an entity virtual gxf_result_t publish_abi(gxf_uid_t uid) = 0; // The total number of entities which have previously been published and were moved out of the // main stage. virtual size_t back_size_abi() = 0; // Moves entities which were published recently out of the main stage. virtual gxf_result_t sync_abi() = 0; virtual gxf_result_t sync_io_abi() { return GXF_SUCCESS; } virtual gxf_result_t pop_io_abi(gxf_uid_t* uid) { return GXF_NOT_IMPLEMENTED; } Expected publish(const Entity& other); Expected publish(Entity& other, const int64_t acq_timestamp); size_t back_size(); Expected sync(); Expected sync_io(); }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/unbounded_allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_UNBOUNDED_ALLOCATOR_HPP_ #define NVIDIA_GXF_STD_UNBOUNDED_ALLOCATOR_HPP_ #include #include #include "gxf/std/allocator.hpp" namespace nvidia { namespace gxf { // An allocator which uses cudaMalloc/cudaMallocHost dynamically without a pool. Does not provide // bounded execution times. class UnboundedAllocator : public Allocator { public: UnboundedAllocator() = default; ~UnboundedAllocator() = default; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t is_available_abi(uint64_t size) override; gxf_result_t allocate_abi(uint64_t size, int32_t storage_type, void** pointer) override; gxf_result_t free_abi(void* pointer) override; private: // Mutex to protect cuda_blocks_ std::mutex mutex_; // Remember the blocks so that we know how to delete them std::set cuda_blocks_; std::set cuda_host_blocks_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_UNBOUNDED_ALLOCATOR_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/vault.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_VAULT_HPP_ #define NVIDIA_GXF_STD_VAULT_HPP_ #include #include #include #include #include "gxf/core/component.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" namespace nvidia { namespace gxf { // Receives messages, stores them and provides thread-safe access to them. class Vault : public Codelet { public: using CallbackType = std::function; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t start() override; gxf_result_t tick() override; gxf_result_t deinitialize() override; gxf_result_t setCallback(CallbackType callback); // Waits until at least the given number of entities have arrived, stores them in the vault, // and returns their UIDs. std::vector storeBlocking(size_t count); // Waits until at least the given number of entities have arrived, stores them in the vault, // and returns their UIDs or times out within a targeted duration (nanoseconds). std::vector storeBlockingFor(size_t count, int64_t duration_ns); // Tries to grab at most specified number of entities and return without waiting. std::vector store(size_t max_count); // Removes the given entities from the vault void free(const std::vector& entities); private: // Stores entities assuming lock std::vector storeImpl(size_t max_count); Parameter> source_; Parameter max_waiting_count_; Parameter drop_waiting_; Parameter callback_address_; Parameter enable_callback_; std::vector entities_waiting_; std::vector entities_in_vault_; std::mutex mutex_; std::condition_variable condition_variable_; bool alive_; std::unique_ptr callback_{ nullptr }; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/std/yaml_file_loader.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STD_YAML_FILE_LOADER_HPP_ #define NVIDIA_GXF_STD_YAML_FILE_LOADER_HPP_ #include #include #include #include #include #include "common/fixed_vector.hpp" #include "common/yaml_parser.hpp" #include "gxf/core/entity.hpp" #include "gxf/core/expected.hpp" #include "gxf/core/gxf.h" #include "yaml-cpp/yaml.h" namespace YAML { class Node; } namespace nvidia { namespace gxf { class ParameterStorage; // Loads a GXF file and creates entities // Components will be initialized in the order they are specified in the YAML file and // deinitialized in reverse-initialization order class YamlFileLoader { public: // Sets the mandatory parameter storage where parameters loaded from YAML are stored. void setParameterStorage(std::shared_ptr parameter_storage) { parameter_storage_ = parameter_storage; } void setFileRoot(const std::string& root) { root_ = root; } // Load GXF Graph from file. Expected loadFromFile(gxf_context_t context, const std::string& filename, const std::string& entity_prefix, const char* parameters_override_string[], const uint32_t num_overrides, gxf_uid_t parent_eid = kNullUid, const YAML::Node& prerequisites = YAML::Node(YAML::NodeType::Null)); // Load GXF Graph from string. Expected loadFromString(gxf_context_t context, const std::string& text, const std::string& entity_prefix, const char* parameters_override_string[], const uint32_t num_overrides); // Load GXF Graph from parsed YAML graph. Expected load(gxf_context_t context, const FixedVectorBase& nodes, std::string entity_prefix, gxf_uid_t parent_eid, const char* parameters_override_string[], const uint32_t num_overrides, const YAML::Node& prerequisites); // Save GXF Graph to YAML file. Expected saveToFile(gxf_context_t context, const std::string& filename); private: // Finds existing entity or creates a new one Expected findOrCreateEntity( gxf_context_t context, const Expected& entity_name); // Creates a new component in an entity by typename Expected addComponent(gxf_context_t context, gxf_uid_t eid, const char* type); // Finds a component in an entity by name Expected findComponent(gxf_context_t context, gxf_uid_t eid, const char* name); // Sets the parameters of a component Expected setParameters(gxf_context_t context, gxf_uid_t handle, const std::string& prefix, const YAML::Node& parameters); // Add a component to an entity's interface mapping Expected addComponentToInterface(gxf_context_t context, gxf_uid_t eid, const std::string& entity_prefix, const std::string& interface_name, const std::string& tag); Expected populateEntityGroups(gxf_context_t context, const FixedVectorBase& nodes, const std::string& entity_prefix); std::shared_ptr parameter_storage_ = nullptr; std::string root_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STD_YAML_FILE_LOADER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/stream/stream_nvsci.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STREAM_STREAM_NVSCI_HPP_ #define NVIDIA_GXF_STREAM_STREAM_NVSCI_HPP_ #include #include "gxf/core/component.hpp" #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { enum class SyncType { GXF_STREAM_SIGNALER_NONE = 0, // Invalid value for signaler GXF_STREAM_SIGNALER_CUDA, // Indicates CUDA is the signaler. // Used to indicate when some CUDA job is done. GXF_STREAM_WAITER_NONE, // Invalid value for waiter GXF_STREAM_WAITER_CUDA, // Indicates CUDA is the waiter. // Used to wait on some CUDA job to be completed. }; struct Stream : public Component { virtual ~Stream() = default; // Allocates a nvsci sync object. virtual gxf_result_t allocate_sync_object(SyncType signalerList, SyncType waiterList, void** syncObj) { return GXF_NOT_IMPLEMENTED; } // Signal semaphore with cuda stream virtual gxf_result_t signalSemaphore() { return GXF_NOT_IMPLEMENTED; } // Wait semaphore with cuda stream virtual gxf_result_t waitSemaphore() { return GXF_NOT_IMPLEMENTED; } // Set cuda stream for the give sync type virtual gxf_result_t setCudaStream(SyncType syncType, cudaStream_t stream) { return GXF_NOT_IMPLEMENTED; } // Imports the semaphore which will be used for signalling/waiting based on the sync type // Streams preserves the semaphore internally and is not exposed to the clients virtual gxf_result_t importSemaphore(SyncType syncType) { return GXF_NOT_IMPLEMENTED; } }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STREAM_STREAM_NVSCI_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/stream/stream_nvscisync.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STREAM_STREAM_NVSCISYNC_HPP_ #define NVIDIA_GXF_STREAM_STREAM_NVSCISYNC_HPP_ #include #include "gxf/core/component.hpp" #include "gxf/core/gxf.h" #include "gxf/stream/stream_nvsci.hpp" namespace nvidia { namespace gxf { class StreamSync: public Stream { public: StreamSync() = default; ~StreamSync() = default; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t allocate_sync_object(SyncType signaler, SyncType waiter, void** syncObj) override; gxf_result_t signalSemaphore() override; gxf_result_t waitSemaphore() override; gxf_result_t setCudaStream(SyncType syncType, cudaStream_t stream) override; gxf_result_t importSemaphore(SyncType syncType) override; private: gxf_result_t importSemaphore(cudaExternalSemaphore_t* semaphore, SyncType syncType); NvSciSyncModule sync_module_{nullptr}; NvSciSyncAttrList attr_list_{nullptr}; NvSciSyncAttrList reconciled_attr_list_{nullptr}; NvSciSyncObj sync_obj_{nullptr}; NvSciSyncFence* fence_; cudaExternalSemaphore_t signaler_semaphore_; cudaExternalSemaphore_t waiter_semaphore_; cudaStream_t signaler_cuda_stream_{}; cudaStream_t waiter_cuda_stream_{}; bool is_signaler_semaphore_imported_{false}; bool is_waiter_semaphore_imported_{false}; int32_t num_gpus_{0}; Parameter signaler_device_id_; Parameter waiter_device_id_; Parameter signaler_; Parameter waiter_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STREAM_STREAM_NVSCISYNC_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/stream/stream_sync_id.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STREAM_STREAM_SYNC_ID_HPP_ #define NVIDIA_GXF_STREAM_STREAM_SYNC_ID_HPP_ #include "gxf/core/gxf.h" namespace nvidia { namespace gxf { // The Structure indicates stream sync component ID. // Message entity carrying StreamSyncId indicates the ID of stream sync. The handle could // be deduced by Handle::Create(context, stream_sync_cid). struct StreamSyncId { // component id of StreamSync gxf_uid_t stream_sync_cid; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STREAM_STREAM_SYNC_ID_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/stream/tests/test_gxf_stream_sync_cuda_helper.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_STREAM_TESTS_TEST_STREAM_CUDA_HELPER_HPP #define NVIDIA_GXF_STREAM_TESTS_TEST_STREAM_CUDA_HELPER_HPP #include #include #include #include #include #include "common/assert.hpp" #include "gxf/cuda/cuda_common.hpp" #include "gxf/cuda/cuda_stream.hpp" #include "gxf/cuda/cuda_stream_id.hpp" #include "gxf/cuda/cuda_stream_pool.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/tensor.hpp" #include "gxf/std/transmitter.hpp" #include "gxf/stream/stream_nvsci.hpp" #include "gxf/stream/stream_nvscisync.hpp" #include "gxf/stream/stream_sync_id.hpp" #define CHECK_CUBLUS_ERROR(cu_result, fmt, ...) \ do { \ cublasStatus_t err = (cu_result); \ if (err != CUBLAS_STATUS_SUCCESS) { \ GXF_LOG_ERROR(fmt ", cublas_error: %d", ##__VA_ARGS__, (int)err); \ return Unexpected{GXF_FAILURE}; \ } \ } while (0) namespace nvidia { namespace gxf { namespace stream { namespace test { constexpr static const char* kStreamName0 = "CudaStream0"; constexpr static int kDefaultDevId = 0; static const Shape kInitTensorShape{1024, 2048}; // The base class with cuda stream utils class StreamBasedOpsNew : public Codelet { public: static Expected> getStream(Entity& message) { auto stream_id = message.get(); GXF_ASSERT(stream_id, "failed to find cudastreamid"); auto stream = Handle::Create(stream_id.value().context(), stream_id.value()->stream_cid); GXF_ASSERT(stream, "create cudastream from cid failed"); GXF_ASSERT(stream.value(), "cudastream handle is null"); return stream; } static Expected addStream(Entity& message, Handle& stream, const char* name = nullptr) { auto stream_id = message.add(name); GXF_ASSERT(stream_id, "failed to add cudastreamid"); stream_id.value()->stream_cid = stream.cid(); GXF_ASSERT(stream_id.value()->stream_cid != kNullUid, "stream_cid is null"); return Success; } static Expected> getStreamSync(Entity& message) { auto streamSync = message.get(); GXF_ASSERT(streamSync, "Failed to find StreamSync"); auto stream_sync = Handle::Create(streamSync.value().context(), streamSync.value()->stream_sync_cid); GXF_ASSERT(stream_sync, "Create StreamSync from cid failed"); GXF_ASSERT(stream_sync.value(), "StreamSync handle is null"); return stream_sync; } static Expected addStreamSync(Entity& message, Handle& streamSync, const char* name = nullptr) { auto stream_sync_id = message.add(name); GXF_ASSERT(stream_sync_id, "Failed to add StreamSyncId"); stream_sync_id.value()->stream_sync_cid = streamSync.cid(); GXF_ASSERT(stream_sync_id.value()->stream_sync_cid != kNullUid, "stream_sync_cid is null"); return Success; } static Expected> addTensor(Entity& message, Handle pool, const TensorDescription& description) { GXF_ASSERT(pool, "pool is not set"); auto tensor = message.add(description.name.c_str()); GXF_ASSERT(tensor, "failed to add message tensor"); const uint64_t bytes_per_element = description.element_type == PrimitiveType::kCustom ? description.bytes_per_element : PrimitiveTypeSize(description.element_type); auto result = tensor.value()->reshapeCustom(description.shape, description.element_type, bytes_per_element, description.strides, description.storage_type, pool); GXF_ASSERT(result, "reshape tensor:%s failed", description.name.c_str()); return tensor; } }; // Generate cuda tensor map with cudastreams for transmitter cuda_tx, // Generate host tensor map for transmitter host_tx class StreamTensorGeneratorNew : public StreamBasedOpsNew { public: gxf_result_t initialize() override { GXF_ASSERT(stream_pool_.get(), "stream pool is not set"); auto stream = stream_pool_->allocateStream(); GXF_ASSERT(stream, "allocating stream failed"); stream_ = std::move(stream.value()); GXF_ASSERT(stream_->stream(), "allocated stream is not initialized."); stream_sync = stream_sync_.get(); void *syncObj{nullptr}; GXF_ASSERT_SUCCESS(stream_sync->allocate_sync_object(static_cast(signaler_.get()), static_cast(waiter_.get()), reinterpret_cast(&syncObj))); GXF_ASSERT(syncObj, "syncObj is null"); GXF_ASSERT_SUCCESS(stream_sync->setCudaStream(static_cast(signaler_.get()), stream_->stream().value())); GXF_ASSERT_SUCCESS(stream_sync->setCudaStream(static_cast(waiter_.get()), stream_->stream().value())); return GXF_SUCCESS; } gxf_result_t tick() override { Expected maybe_dev_msg = Entity::New(context()); GXF_ASSERT(maybe_dev_msg, "New dev message failed"); auto& dev_msg = maybe_dev_msg.value(); Expected maybe_host_msg = Entity::New(context()); GXF_ASSERT(maybe_host_msg, "New host message failed"); auto& host_msg = maybe_host_msg.value(); auto ret = addStream(dev_msg, stream_, kStreamName0); GXF_ASSERT(ret, "stream tensor generator adding stream failed"); auto sync_ret = addStreamSync(dev_msg, stream_sync, "nvidia::gxf::StreamSync"); GXF_ASSERT_TRUE(sync_ret.has_value()); auto maybe_stream_sync = getStreamSync(dev_msg); GXF_ASSERT_TRUE(maybe_stream_sync.has_value()); ret = createTensors(dev_msg, host_msg, stream_->stream().value()); GXF_ASSERT(ret, "creating tensors failed"); GXF_ASSERT(stream_, "stream is not allocated"); maybe_stream_sync.value()->signalSemaphore(); ret = cuda_tx_->publish(dev_msg); if (!ret) { GXF_LOG_ERROR("stream tensor generator publishing cuda tensors failed"); return ToResultCode(ret); } if (host_tx_.get()) { ret = host_tx_->publish(host_msg); if (!ret) { GXF_LOG_ERROR("stream tensor generator publishing cuda tensors failed"); return ToResultCode(ret); } } return GXF_SUCCESS; } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(cuda_tx_, "cuda_tx", "transmitter of cuda tensors", ""); result &= registrar->parameter(host_tx_, "host_tx", "transmitter of host tensors", "", Handle()); result &= registrar->parameter(cuda_tensor_pool_, "cuda_tensor_pool", "Cuda Tensor Pool", ""); result &= registrar->parameter(host_tensor_pool_, "host_tensor_pool", "Host Tensor Pool", ""); result &= registrar->parameter(stream_pool_, "stream_pool", "Cuda Stream Pool", ""); result &= registrar->parameter(stream_sync_, "stream_sync", "Synchronization object across CUDA codelets", ""); result &= registrar->parameter(signaler_, "signaler", "Signaler type", "Defines the signaler type. Cuda Signaler (2)", static_cast(SyncType::GXF_STREAM_SIGNALER_CUDA)); result &= registrar->parameter(waiter_, "waiter", "Waiter type", "Defines the waiter type. Cuda Waiter (6)", static_cast(SyncType::GXF_STREAM_WAITER_CUDA)); return ToResultCode(result); } private: Expected createTensors(Entity& dev_msg, Entity& host_msg, cudaStream_t stream) { Shape shape = kInitTensorShape; for (size_t i = 0; i < 2; ++i) { TensorDescription dev_desc{"cuda_tensor", MemoryStorageType::kDevice, shape, PrimitiveType::kFloat32}; auto cuda_tensor_ret = addTensor(dev_msg, cuda_tensor_pool_, dev_desc); GXF_ASSERT(cuda_tensor_ret, "Generator dev message adding tensor failed."); auto& cuda_tensor = cuda_tensor_ret.value(); Expected cuda_data = cuda_tensor->data(); if (!cuda_data) { return ForwardError(cuda_data); } TensorDescription host_desc{"host_tensor", MemoryStorageType::kHost, shape, PrimitiveType::kFloat32}; auto host_tensor_ret = addTensor(host_msg, host_tensor_pool_, host_desc); GXF_ASSERT(host_tensor_ret, "Generator host message adding tensor failed."); auto& host_tensor = host_tensor_ret.value(); Expected host_data = host_tensor->data(); if (!host_data) { return ForwardError(host_data); } for (size_t j = 0; j < shape.size(); ++j) { host_data.value()[j] = (j % 100) + 1.0f; } cudaError_t error = cudaMemcpyAsync(cuda_data.value(), host_data.value(), cuda_tensor->size(), cudaMemcpyHostToDevice, stream); CHECK_CUDA_ERROR(error, "StreamTensorGeneratorNew cuda memory cpy H2D failed."); } return Success; } Parameter> cuda_tx_; Parameter> host_tx_; Parameter> cuda_tensor_pool_; Parameter> host_tensor_pool_; Parameter> stream_pool_; Parameter> stream_sync_; Parameter signaler_; Parameter waiter_; Handle stream_; Handle stream_sync; }; // Dot product execution base class class DotProductExeNew { private: Handle rx_; Handle tx_; Handle tensor_pool_; public: DotProductExeNew() = default; virtual ~DotProductExeNew() = default; void setEnv(const Handle& rx, const Handle& tx, const Handle& pool) { rx_ = rx; tx_ = tx; tensor_pool_ = pool; } virtual Expected dotproduct_i(float* in0, float* in1, float* out, int32_t row, int32_t column, Entity& in_msg, Entity& out_msg) = 0; Expected executeNew(Entity in_msg, const char* out_tensor_name = "") { GXF_ASSERT(rx_ && tx_ && tensor_pool_, "dotproduct received empty in_msg"); // get tensors auto in_tensors = in_msg.findAllHeap(); GXF_ASSERT(in_tensors, "failed to find Tensors in in_msg"); GXF_ASSERT(in_tensors->size() == 2, "doesn't find Tensors in in_msg"); GXF_ASSERT(in_tensors->at(0).value()->rank() == 2, "Input tensor rank is not 2"); int32_t column = in_tensors->at(0).value()->shape().dimension(1); int32_t row = in_tensors->at(0).value()->shape().dimension(0); MemoryStorageType mem_type = in_tensors->at(0).value()->storage_type(); PrimitiveType data_type = in_tensors->at(0).value()->element_type(); float* in_data[2] = {nullptr}; for (size_t i = 0; i < in_tensors->size(); ++i) { GXF_ASSERT(in_tensors->at(i).value(), "Input Tensor Handle is empty"); GXF_ASSERT(in_tensors->at(i).value()->rank() == 2, "Input tensor rank is not 2"); in_data[i] = ValuePointer(in_tensors->at(i).value()->pointer()); } Expected output = Entity::New(in_msg.context()); GXF_ASSERT(output, "Creating dotproduct output tensor failed."); Shape out_shape{row}; GXF_ASSERT(out_shape.rank() == 1 && out_shape.size() == static_cast(row), "output_shape is not correct"); TensorDescription outDesc{out_tensor_name, mem_type, out_shape, data_type}; auto out_tensor = StreamBasedOpsNew::addTensor(output.value(), tensor_pool_, outDesc); GXF_ASSERT(out_tensor && out_tensor.value(), "cuda dotproduct output tensor is not found"); float* out_data = ValuePointer(out_tensor.value()->pointer()); auto ret = dotproduct_i(in_data[0], in_data[1], out_data, row, column, in_msg, output.value()); GXF_ASSERT(ret, "dotproduct execute with implementation failed"); ret = tx_->publish(output.value()); GXF_ASSERT(ret, "dotproduct publishing tensors failed"); return ret; } }; // Cublas Dot product Operators class CublasDotProductNew : public StreamBasedOpsNew { public: // Culblas dot production execution class class CublasDotProductExe : public DotProductExeNew { private: cublasHandle_t handle_ = nullptr; CublasDotProductNew* codelet_ = nullptr; public: CublasDotProductExe(CublasDotProductNew* codelet) : codelet_(codelet) {} ~CublasDotProductExe() { if (handle_) { cublasDestroy(handle_); } } Expected dotproduct_i(float* in0, float* in1, float* out, int32_t row, int32_t column, Entity& in_msg, Entity& out_msg) override { // locate stream auto maybe_stream = StreamBasedOpsNew::getStream(in_msg); GXF_ASSERT(maybe_stream && maybe_stream.value(), "get stream from in_msg failed"); auto& stream = maybe_stream.value(); auto ret = StreamBasedOpsNew::addStream(out_msg, stream); GXF_ASSERT(ret, "adding cudastream into dotproduct output message failed."); int gpu_id = stream->dev_id(); if (gpu_id >= 0) { CHECK_CUDA_ERROR(cudaSetDevice(gpu_id), "failed to set deviceid: %d", gpu_id); } if (!handle_) { CHECK_CUBLUS_ERROR(cublasCreate(&handle_), "failed to create cublas handle"); } auto custream_id = stream->stream(); GXF_ASSERT(custream_id, "cudastream id is invalid"); CHECK_CUBLUS_ERROR(cublasSetStream(handle_, custream_id.value()), "cublas set stream failed"); for (int i = 0; i < row; ++i) { CHECK_CUBLUS_ERROR( cublasSdot(handle_, column, in0 + column * i, 1, in1 + column * i, 1, out + i), "cublasSdot failed on row :%d", i); } return ret; } }; CublasDotProductNew() : exec_(this) {} gxf_result_t initialize() override { GXF_ASSERT(tensor_pool_.get() && rx_.get() && tx_.get(), "params not set"); exec_.setEnv(rx_.get(), tx_.get(), tensor_pool_.get()); return GXF_SUCCESS; } // gxf_result_t start() override { return ToResultCode(initOpsEvent()); } gxf_result_t tick() override { Expected in_msg = rx_->receive(); auto maybe_stream_sync = getStreamSync(in_msg.value()); GXF_ASSERT_TRUE(maybe_stream_sync.has_value()); maybe_stream_sync.value()->waitSemaphore(); auto ret = exec_.executeNew(in_msg.value(), "cublasdotproduct_tensor"); return ToResultCode(ret); } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(tx_, "tx", "transmitter of tensors", ""); result &= registrar->parameter(rx_, "rx", "receiver of tensors", ""); result &= registrar->parameter(tensor_pool_, "tensor_pool", "Tensor Pool", ""); return ToResultCode(result); } private: Parameter> tx_; Parameter> rx_; Parameter> tensor_pool_; CublasDotProductExe exec_; }; // CPU Dot product Operators class HostDotProductNew : public Codelet { public: // CPU dot production execution class class HostDotProductExeNew : public DotProductExeNew { public: HostDotProductExeNew() = default; ~HostDotProductExeNew() = default; Expected dotproduct_i(float* in0, float* in1, float* out, int32_t row, int32_t column, Entity& in_msg, Entity& out_msg) override { for (int i = 0; i < row; ++i) { float sum = 0.0; float* x = in0 + column * i; float* y = in1 + column * i; for (int j = 0; j < column; ++j) { sum += x[j] * y[j]; } out[i] = sum; } return Success; } }; gxf_result_t initialize() override { GXF_ASSERT(tensor_pool_.get() && rx_.get() && tx_.get(), "params not set"); exec_.setEnv(rx_.get(), tx_.get(), tensor_pool_.get()); return GXF_SUCCESS; } gxf_result_t tick() override { Expected in_msg = rx_->receive(); auto ret = exec_.executeNew(in_msg.value(), "host_dotproduct_tensor"); return ToResultCode(ret); } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(tx_, "tx", "transmitter of tensors", ""); result &= registrar->parameter(rx_, "rx", "receiver of tensors", ""); result &= registrar->parameter(tensor_pool_, "tensor_pool", "Tensor Pool", ""); return ToResultCode(result); } private: Parameter> tx_; Parameter> rx_; Parameter> tensor_pool_; HostDotProductExeNew exec_; }; // Stream based Memory copy from device to host class MemCpy2HostNew : public StreamBasedOpsNew { public: gxf_result_t tick() override { auto in = rx_->receive(); GXF_ASSERT(in, "rx received empty message"); auto maybe_tensor = in.value().get(); GXF_ASSERT(maybe_tensor, "tensor not found"); auto& in_tensor = maybe_tensor.value(); byte* in_data = in_tensor->pointer(); Expected out_msg = Entity::New(context()); TensorDescription out_desc{in_tensor.name(), MemoryStorageType::kHost, in_tensor->shape(), in_tensor->element_type()}; auto maybe_out_tensor = addTensor(out_msg.value(), tensor_pool_, out_desc); GXF_ASSERT(maybe_out_tensor, "Memcpy host message adding tensor failed."); auto& out_tensor = maybe_out_tensor.value(); byte* out_data = out_tensor->pointer(); auto maybe_stream = getStream(in.value()); GXF_ASSERT(maybe_stream && maybe_stream.value(), "get stream from in failed"); auto& stream = maybe_stream.value(); auto ret = addStream(out_msg.value(), stream); GXF_ASSERT(ret, "adding cudastream into memcpy output message failed."); // wrap cuda operations since CHECK_CUDA_ERROR return Expected ret = [&, this]() -> Expected { int gpu_id = stream->dev_id(); if (gpu_id >= 0) { CHECK_CUDA_ERROR(cudaSetDevice(gpu_id), "failed to set deviceid: %d", gpu_id); } cudaError_t error = cudaMemcpyAsync(out_data, in_data, in_tensor->size(), cudaMemcpyDeviceToHost, stream->stream().value()); CHECK_CUDA_ERROR(error, "CUDA memory cpy to host failed."); return Success; }(); GXF_ASSERT(ret, "CUDA memory cpy to host failed."); ret = tx_->publish(out_msg.value()); GXF_ASSERT(ret, "memcpy_to_host publishing tensors failed"); return ToResultCode(ret); } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(tx_, "tx", "transmitter of tensors", ""); result &= registrar->parameter(rx_, "rx", "receiver of tensors", ""); result &= registrar->parameter(tensor_pool_, "tensor_pool", "Tensor output pool", ""); return ToResultCode(result); } private: Parameter> tx_; Parameter> rx_; Parameter> tensor_pool_; }; // Equal verification class VerifyEqualNew : public Codelet { public: gxf_result_t tick() override { GXF_LOG_DEBUG("verifying frame: %d", count_++); auto in0 = rx0_->receive(); GXF_ASSERT(in0, "rx0 received empty message"); auto in1 = rx1_->receive(); GXF_ASSERT(in1, "rx1 received empty message"); // get tensors auto maybe_tensor0 = in0.value().get(); GXF_ASSERT(maybe_tensor0, "tensor0 not found"); auto maybe_tensor1 = in1.value().get(); GXF_ASSERT(maybe_tensor1, "tensor1 not found"); auto& tensor0 = maybe_tensor0.value(); auto& tensor1 = maybe_tensor1.value(); GXF_ASSERT(std::string(tensor0.name()) != std::string(tensor1.name()), "2 tensor name should not same"); GXF_ASSERT(tensor0->shape() == tensor1->shape(), "2 tensors' shape not matched"); GXF_ASSERT(tensor0->element_type() == tensor1->element_type(), "2 tensor's element type not matched"); GXF_ASSERT(tensor0->storage_type() == tensor1->storage_type(), "2 tensor's storage_type not matched"); GXF_ASSERT(tensor0->storage_type() == MemoryStorageType::kHost, "very tensor storage_type is not from host"); float* data0 = tensor0->data().value(); float* data1 = tensor1->data().value(); uint64_t count = tensor0->element_count(); for (uint64_t i = 0; i < count; ++i) { GXF_ASSERT(fequal(data0[i], data1[i]), "data0[%d]: %f but data1: %f.", static_cast(i), data0[i], data1[i]); } return GXF_SUCCESS; } gxf_result_t registerInterface(Registrar* registrar) override { Expected result; result &= registrar->parameter(rx0_, "rx0", "receiver0 of tensors", ""); result &= registrar->parameter(rx1_, "rx1", "receiver1 of tensors", ""); return ToResultCode(result); } private: bool fequal(float a, float b) { if (fabs(a - b) <= std::numeric_limits::epsilon()) return true; return false; } Parameter> rx0_; Parameter> rx1_; int32_t count_ = 0; }; } // namespace test } // namespace stream } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_STREAM_TESTS_TEST_STREAM_CUDA_HELPER_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/ucx/ucx_common.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_UCX_UCX_COMMON_HPP_ #define NVIDIA_GXF_UCX_UCX_COMMON_HPP_ #include /* inet_addr */ #include #include #include "gxf/std/allocator.hpp" #define DEFAULT_UCX_PORT 13337U #define TEST_AM_ID 0 #define WORKER_PROGRESS_ITERATIONS 5 namespace nvidia { namespace gxf { typedef struct _ucx_am_data_desc { volatile int complete; void *desc; volatile size_t msg_length; volatile size_t header_length; void *recv_buf; void *header; volatile size_t num_of_comps; bool receiving_message; ucs_memory_type_t mem_type; } ucx_am_data_desc; /** * Stream request context. Holds a value to indicate whether or not the * request is completed. */ typedef struct test_req { int complete; char *header; } test_req_t; typedef enum { INIT, CONNECTED, RESET, CLOSED, RECEIVE_MESSAGE } ConnState; #define CHECK_RETURN_FAILURE(value) \ if ((value) != GXF_SUCCESS) return (value); typedef struct UcxTransmitterSendContext { Entity entity; ucp_worker_h ucp_worker; void* request; test_req_t* ctx; int index; } UcxTransmitterSendContext_; /** * Set an address for the server to listen on - INADDR_ANY on a well known port. */ void set_sock_addr(const char* address_str, int port, struct sockaddr_storage* saddr); void ep_close(ucp_worker_h ucp_worker, ucp_ep_h ep, uint32_t mode); gxf_result_t init_worker(ucp_context_h ucp_context, ucp_worker_h* ucp_worker); ucs_memory_type_t ucx_mem_type(MemoryStorageType gxf_mem_type); ucs_status_t request_wait(ucp_worker_h ucp_worker, void* request, test_req_t* ctx); gxf_result_t request_finalize(ucp_worker_h ucp_worker, void* request, test_req_t* ctx); ucs_status_t request_wait_once(ucp_worker_h ucp_worker, void* request, test_req_t* ctx); ucs_status_t process_request(ucp_worker_h ucp_worker, void* req); } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_EXTENSIONS_UCX_UCX_COMMON_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/ucx/ucx_component_serializer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_UCX_COMPONENT_SERIALIZER_HPP_ #define NVIDIA_GXF_SERIALIZATION_UCX_COMPONENT_SERIALIZER_HPP_ #include "common/endian.hpp" #include "gxf/multimedia/audio.hpp" #include "gxf/multimedia/video.hpp" #include "gxf/serialization/component_serializer.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/eos.hpp" #include "gxf/std/tensor.hpp" #include "gxf/std/timestamp.hpp" namespace nvidia { namespace gxf { // Serializer that supports serializaing Timestamps, Tensors, Video Buffer, // Audio Buffer and integer components // Valid for sharing data between devices with the same endianness class UcxComponentSerializer : public ComponentSerializer { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override { return GXF_SUCCESS; } private: // Configures all serializer functions Expected configureSerializers(); // Configures all deserializer functions Expected configureDeserializers(); // Serializes a nvidia::gxf::Timestamp Expected serializeTimestamp(Timestamp timestamp, Endpoint* endpoint); // Deserializes a nvidia::gxf::Timestamp Expected deserializeTimestamp(Endpoint* endpoint); // Serializes a nvidia::gxf::Tensor Expected serializeTensor(const Tensor& tensor, Endpoint* endpoint); // Deserializes a nvidia::gxf::Tensor Expected deserializeTensor(Endpoint* endpoint); // Serializes a nvidia::gxf::VideoBuffer Expected serializeVideoBuffer(const VideoBuffer& videoBuffer, Endpoint* endpoint); // Deserializes a nvidia::gxf::VideoBuffer Expected deserializeVideoBuffer(Endpoint* endpoint); // Serializes a nvidia::gxf::AudioBuffer Expected serializeAudioBuffer(const AudioBuffer& audioBuffer, Endpoint* endpoint); // Deserializes a nvidia::gxf::AudioBuffer Expected deserializeAudioBuffer(Endpoint* endpoint); // Serializes a nvidia::gxf::EndOfStream Expected serializeEndOfStream(EndOfStream& eos, Endpoint* endpoint); // Deserializes a nvidia::gxf::EndOfStream Expected deserializeEndOfStream(Endpoint* endpoint); // Serializes an integer template Expected serializeInteger(T value, Endpoint* endpoint) { if (!endpoint) { return Unexpected{GXF_ARGUMENT_NULL}; } T encoded = EncodeLittleEndian(value); return endpoint->writeTrivialType(&encoded); } // Deserializes an integer template Expected deserializeInteger(Endpoint* endpoint) { if (!endpoint) { return Unexpected{GXF_ARGUMENT_NULL}; } T encoded; return endpoint->readTrivialType(&encoded) .and_then([&]() { return DecodeLittleEndian(encoded); }); } Parameter> allocator_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_STD_COMPONENT_SERIALIZER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/ucx/ucx_context.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_UCX_UCX_ROUTER_HPP_ #define NVIDIA_GXF_UCX_UCX_ROUTER_HPP_ #include #include #include #include #include #include #include #include "gxf/std/network_context.hpp" #include "gxf/std/queue.hpp" #include "ucx_common.hpp" #include "ucx_receiver.hpp" #include "ucx_transmitter.hpp" #define kMaxRxContexts 1024 namespace nvidia { namespace gxf { typedef struct ucx_server_ctx { volatile ucp_conn_request_h conn_request; ucp_listener_h listener; ucp_worker_h listener_worker; int listener_fd; ///< epoll fd used only when enable_async_ == true } ucx_server_ctx_t; typedef struct UcxReceiverContext { UcxReceiver *rx; ucx_server_ctx_t server_context; ucp_ep_h ep; ConnState conn_state; ucx_am_data_desc am_data_desc; FixedVector, kMaxRxContexts> headers; ucp_worker_h ucp_worker; int worker_fd; ///< epoll fd used only when enable_async_ == true int index; } UcxReceiverContext_; typedef struct UcxTransmitterContext { UcxTransmitter *tx; ucp_ep_h ep; ucp_worker_h ucp_worker; bool connection_closed; int index; } UcxTransmitterContext_; typedef struct ConnManager { int total; int connected; int closed; } ConnManager_; // The class which initializes UCX context and connection worker class UcxContext : public NetworkContext { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; Expected addRoutes(const Entity& entity) override; Expected removeRoutes(const Entity& entity) override; private: gxf_result_t init_context(); gxf_result_t init_tx(Handle tx); gxf_result_t init_rx(Handle rx); /// @brief start server for the case with enable_async_ == false void start_server(); gxf_result_t am_desc_to_iov(std::shared_ptr rx_context); void destroy_rx_contexts(); void destroy_tx_contexts(); // The remaining methods are specific to the case with enable_async_ == true /// @brief start server for the case with enable_async_ == true void start_server_async_queue(); /// @brief method run by tx_thread_ when enable_async_ == true void poll_queue(); gxf_result_t wait_for_event(); ///< primary function called by start_server_async_queue gxf_result_t epoll_add_worker(std::shared_ptr rx_context, bool is_listener); gxf_result_t progress_work(std::shared_ptr rx_context); gxf_result_t server_create_ep(std::shared_ptr rx_context); gxf_result_t init_connection(std::shared_ptr rx_context); gxf_result_t handle_connections_after_recv(); gxf_result_t gxf_arm_worker(std::shared_ptr rx_context, bool is_listener); void copy_header_to_am_desc(std::shared_ptr rx_context); bool close_server_loop_; FixedVector, kMaxRxContexts> rx_contexts_; FixedVector, kMaxRxContexts> tx_contexts_; ucp_context_h ucp_context_; Parameter> entity_serializer_; Parameter reconnect_; Resource> gpu_device_; Parameter cpu_data_only_; Parameter enable_async_; int32_t dev_id_ = 0; std::thread t_; ///< server thread used only when enable_async_ == false // The following data members are only used when enable_async_ == true ConnManager rx_conns_ = {0}; std::thread rx_thread_; ///< async receiver thread used only when enable_async_ == true std::thread tx_thread_; ///< async transmitter thread used only when enable_async_ == true std::list pending_send_requests_; std::mutex mtx_; std::condition_variable cv_; bool areTransmittersDone = false; int epoll_fd_; int efd_signal_; }; } // namespace gxf } // namespace nvidia #endif ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/ucx/ucx_entity_serializer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_UCX_ENTITY_SERIALIZER_HPP_ #define NVIDIA_GXF_SERIALIZATION_UCX_ENTITY_SERIALIZER_HPP_ #define kMaxTempComponents 1024 #include #include "common/fixed_vector.hpp" #include "gxf/core/gxf.h" #include "gxf/serialization/component_serializer.hpp" #include "gxf/serialization/entity_serializer.hpp" #include "gxf/serialization/tid_hash.hpp" namespace nvidia { namespace gxf { // Serializes and deserializes entities with the provided component serializers // Little-endian is used over big-endian for better performance on x86 and arm platforms // Entities are serialized in the following format: // // | Entity Header | Component Header | Component Metadata | Component Header | ... | ... | // // Components will be serialized in the order they are added to the entity // Components without serializers will be skipped // Each component will be preceded by a component header and the name of the component // The component itself will be serialized with a component serializer // An entity header will be added at the beginning class UcxEntitySerializer : public EntitySerializer { public: #pragma pack(push, 1) // Header preceding entities struct EntityHeader { uint64_t serialized_size; // Size of the serialized entity in bytes uint64_t sequence_number; // Sequence number of the message uint64_t component_count; // Number of components in the entity }; #pragma pack(pop) #pragma pack(push, 1) // Header preceding components struct ComponentHeader { uint64_t serialized_size; // Size of the serialized component in bytes gxf_tid_t tid; // Type ID of the component char name[kMaxComponentNameSize]; // Component name }; #pragma pack(pop) gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override { return GXF_SUCCESS; } gxf_result_t deinitialize() override { return GXF_SUCCESS; } gxf_result_t serialize_entity_abi(gxf_uid_t eid, Endpoint* endpoint, uint64_t* size) override; gxf_result_t deserialize_entity_abi(gxf_uid_t eid, Endpoint* endpoint) override; Expected deserialize_entity_header_abi(Endpoint* endpoint) override; Expected add_serializer(const Handle& serializer); private: // Structure used to organize serializable components struct ComponentEntry; using ComponentSerializerList = FixedVector, kMaxTempComponents>; // Populates a list of component entries using a list of component handles Expected> createComponentEntries( const FixedVector& components); // Serializes a list of components and writes them to an endpoint // Returns the total number of bytes serialized Expected serializeComponents(const FixedVector& entries, Endpoint* endpoint); // Reads from an endpoint and deserializes a list of components Expected deserializeComponents(size_t component_count, Entity entity, Endpoint* endpoint); // Searches for a component serializer that supports the given type ID // Uses the first valid serializer found and caches it for subsequent lookups // Returns an Unexpected if no valid serializer is found Expected> findComponentSerializer(gxf_tid_t tid); Parameter component_serializers_; Parameter verbose_warning_; // Table that caches type ID with a valid component serializer std::unordered_map, TidHash> serializer_cache_; // Sequence number for outgoing messages uint64_t outgoing_sequence_number_{0}; // Sequence number for incoming messages uint64_t incoming_sequence_number_{0}; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_STD_ENTITY_SERIALIZER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/ucx/ucx_receiver.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #include #include #include #include #include #include #include #include #include #include #include "gxf/std/gems/staging_queue/staging_queue.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/resources.hpp" #include "ucx_common.hpp" #include "ucx_serialization_buffer.hpp" #ifndef NVIDIA_GXF_UCX_UCX_RECEIVER_HPP_ #define NVIDIA_GXF_UCX_UCX_RECEIVER_HPP_ namespace nvidia { namespace gxf { // Codelet that functions as a receiver on a UCX connection class UcxReceiver : public Receiver { public: using queue_t = ::gxf::staging_queue::StagingQueue; gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t init_context(ucp_worker_h ucp_worker, ucx_am_data_desc* am_data_desc, int fd, bool cpu_data_only, bool enable_async); gxf_result_t pop_abi(gxf_uid_t* uid) override; gxf_result_t push_abi(gxf_uid_t other) override; gxf_result_t peek_abi(gxf_uid_t* uid, int32_t index) override; gxf_result_t peek_back_abi(gxf_uid_t* uid, int32_t index) override; size_t capacity_abi() override; size_t size_abi() override; gxf_result_t receive_abi(gxf_uid_t* uid) override; size_t back_size_abi() override; gxf_result_t sync_abi() override; gxf_result_t sync_io_abi() override; gxf_result_t wait_abi() override; const char* get_addr(); int get_port(); Expected set_serialization_buffer(Handle buffer); Expected set_port(int port); Parameter capacity_; Parameter policy_; Parameter address_; Parameter port_; Resource> gpu_device_; Parameter> buffer_; private: gxf_result_t receive_message(); /// @brief finalize request when enable_async_ == false gxf_result_t request_finalize_sync(ucp_worker_h ucp_worker, test_req_t* request, test_req_t* ctx); ucp_worker_h ucp_worker_; ucx_am_data_desc* am_data_desc_; std::unique_ptr queue_; int32_t dev_id_ = 0; int efd_signal_; bool cpu_data_only_ = false; std::list> requests; int enable_async_ = true; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_EXTENSIONS_UCX_UCX_RECEIVER_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/ucx/ucx_serialization_buffer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #ifndef NVIDIA_GXF_SERIALIZATION_UCX_SERIALIZATION_BUFFER_HPP_ #define NVIDIA_GXF_SERIALIZATION_UCX_SERIALIZATION_BUFFER_HPP_ #include #include #include "gxf/serialization/endpoint.hpp" #include "gxf/std/allocator.hpp" #include "gxf/std/memory_buffer.hpp" #include "ucp/api/ucp.h" namespace nvidia { namespace gxf { // Buffer to hold serialized data class UcxSerializationBuffer : public Endpoint { public: gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override { return ToResultCode(buffer_.freeBuffer()); } gxf_result_t write_abi(const void* data, size_t size, size_t* bytes_written) override; gxf_result_t read_abi(void* data, size_t size, size_t* bytes_read) override; gxf_result_t write_ptr_abi(const void* pointer, size_t size, MemoryStorageType type) override; // Resizes the buffer gxf::Expected resize(size_t size); // Set allocator Expected set_allocator(Handle allocator); // Returns a read-only pointer to buffer data const byte* data() const { return buffer_.pointer(); } const ucp_dt_iov_t* iov_buffer() const { return iov_buffers_.data(); } const size_t iov_buffer_size() const { return iov_buffers_.size(); } const ucs_memory_type_t mem_type() const {return mem_type_; } // Returns the capacity of the buffer size_t capacity() const { return buffer_.size(); } // Returns the number of bytes written to the buffer size_t size() const; // Resets buffer for sequential access void reset(); uint64_t sequence_number_ = 0; private: Parameter> allocator_; Parameter buffer_size_; // Vector for ucp_dt_iov_t std::vector iov_buffers_; // UCX memory type of component ucs_memory_type_t mem_type_; // Data buffer MemoryBuffer buffer_; // Offset for sequential writes size_t write_offset_; // Offset for sequential reads size_t read_offset_; // Mutex to guard concurrent access mutable std::mutex mutex_; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_SERIALIZATION_UCX_SERIALIZATION_BUFFER_HPP_ ================================================ FILE: isaac_ros_gxf/gxf/core/include/gxf/ucx/ucx_transmitter.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #include #include #include #include #include #include #include #include "ucp/api/ucp.h" #include "gxf/std/gems/staging_queue/staging_queue.hpp" #include "gxf/std/resources.hpp" #include "gxf/std/transmitter.hpp" #include "ucx_common.hpp" #include "ucx_entity_serializer.hpp" #include "ucx_serialization_buffer.hpp" #ifndef NVIDIA_GXF_UCX_UCX_TRANSMITTER_HPP_ #define NVIDIA_GXF_UCX_UCX_TRANSMITTER_HPP_ namespace nvidia { namespace gxf { // Codelet that functions as a transmitter in a UCX connection class UcxTransmitter : public Transmitter { public: using queue_t = ::gxf::staging_queue::StagingQueue; gxf_result_t init_context(ucp_context_h ucp_context, Handle serializer, ucp_worker_h ucp_worker, ucp_ep_h* ep, bool* connection_closed_p, bool reconnect, bool cpu_data_only, bool enable_async, std::list* send_queue, std::condition_variable* cv, std::mutex* mtx); gxf_result_t registerInterface(Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; gxf_result_t pop_abi(gxf_uid_t* uid) override; gxf_result_t pop_io_abi(gxf_uid_t* uid) override; gxf_result_t push_abi(gxf_uid_t other) override; gxf_result_t peek_abi(gxf_uid_t* uid, int32_t index) override; size_t capacity_abi() override; size_t size_abi() override; gxf_result_t publish_abi(gxf_uid_t uid) override; size_t back_size_abi() override; gxf_result_t sync_abi() override; gxf_result_t sync_io_abi() override; Expected set_port(int port); Expected set_serialization_buffer(Handle buffer); Parameter capacity_; Parameter policy_; private: gxf_result_t send_am(Entity& entity); gxf_result_t create_client_connection(); gxf_result_t create_client_connection_with_retries(); gxf_result_t check_connection_and_connect(); ucp_worker_h ucp_worker_; ucp_ep_h* ep_; Parameter receiver_address_; Parameter local_address_; Parameter port_; Parameter local_port_; Parameter maximum_connection_retries_; Resource> gpu_device_; int32_t dev_id_ = 0; Parameter> buffer_; Handle entity_serializer_; std::unique_ptr queue_; bool* connection_closed_p_; bool reconnect_; bool cpu_data_only_; std::list* send_queue_; std::condition_variable* cv_; std::mutex* mtx_; int index = 0; int* id_; int enable_async_ = true; }; } // namespace gxf } // namespace nvidia #endif // NVIDIA_GXF_EXTENSIONS_UCX_UCX_TRANSMITTER_HPP ================================================ FILE: isaac_ros_gxf/gxf/core/include/third_party/LICENSE.txt ================================================ ================================================================================ This project uses the following software and the following licensing terms apply to all the extensions and its associated files used to interact with the graph composer tools suite that includes composer, registry, container builder and gxe. ================================================================================ python 3.6.9 (Provided under following license) ================================================================================ Python was created in the early 1990s by Guido van Rossum at Stichting Mathematisch Centrum (CWI, see https://www.cwi.nl/) in the Netherlands as a successor of a language called ABC. Guido remains Python’s principal author, although it includes many contributions from others. In 1995, Guido continued his work on Python at the Corporation for National Research Initiatives (CNRI, see https://www.cnri.reston.va.us/) in Reston, Virginia where he released several versions of the software. In May 2000, Guido and the Python core development team moved to BeOpen.com to form the BeOpen PythonLabs team. In October of the same year, the PythonLabs team moved to Digital Creations (now Zope Corporation; see https://www.zope.org/). In 2001, the Python Software Foundation (PSF, see https://www.python.org/psf/) was formed, a non-profit organization created specifically to own Python-related Intellectual Property. Zope Corporation is a sponsoring member of the PSF. All Python releases are Open Source (see https://opensource.org/ for the Open Source Definition). Historically, most, but not all, Python releases have also been GPL-compatible; the table below summarizes the various releases. Release Derived Year Owner GPL- from compatible? (1) 0.9.0 thru 1.2 1991-1995 CWI yes 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes 1.6 1.5.2 2000 CNRI no 2.0 1.6 2000 BeOpen.com no 1.6.1 1.6 2001 CNRI yes (2) 2.1 2.0+1.6.1 2001 PSF no 2.0.1 2.0+1.6.1 2001 PSF yes 2.1.1 2.1+2.0.1 2001 PSF yes 2.1.2 2.1.1 2002 PSF yes 2.1.3 2.1.2 2002 PSF yes 2.2 and above 2.1.1 2001-now PSF yes Note GPL-compatible doesn’t mean that we’re distributing Python under the GPL. All Python licenses, unlike the GPL, let you distribute a modified version without making your changes open source. The GPL-compatible licenses make it possible to combine Python with other software that is released under the GPL; the others don’t. Thanks to the many outside volunteers who have worked under Guido’s direction to make these releases possible. Terms and conditions for accessing or otherwise using Python PSF LICENSE AGREEMENT FOR PYTHON 3.6.13 1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and the Individual or Organization ("Licensee") accessing and otherwise using Python 3.6.13 software in source or binary form and its associated documentation. 2. Subject to the terms and conditions of this License Agreement, PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python 3.6.13 alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of copyright, i.e., "Copyright © 2001-2021 Python Software Foundation; All Rights Reserved" are retained in Python 3.6.13 alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or incorporates Python 3.6.13 or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to Python 3.6.13. 4. PSF is making Python 3.6.13 available to Licensee on an "AS IS" basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 3.6.13 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 3.6.13 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 3.6.13, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 6. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 7. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between PSF and Licensee. This License Agreement does not grant permission to use PSF trademarks or trade name in a trademark sense to endorse or promote products or services of Licensee, or any third party. 8. By copying, installing or otherwise using Python 3.6.13, Licensee agrees to be bound by the terms and conditions of this License Agreement. BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0 BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1 1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the Individual or Organization ("Licensee") accessing and otherwise using this software in source or binary form and its associated documentation ("the Software"). 2. Subject to the terms and conditions of this BeOpen Python License Agreement, BeOpen hereby grants Licensee a non-exclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use the Software alone or in any derivative version, provided, however, that the BeOpen Python License is retained in the Software, alone or in any derivative version prepared by Licensee. 3. BeOpen is making the Software available to Licensee on an "AS IS" basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 5. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 6. This License Agreement shall be governed by and interpreted in all respects by the law of the State of California, excluding conflict of law provisions. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between BeOpen and Licensee. This License Agreement does not grant permission to use BeOpen trademarks or trade names in a trademark sense to endorse or promote products or services of Licensee, or any third party. As an exception, the "BeOpen Python" logos available at http://www.pythonlabs.com/logos.html may be used according to the permissions granted on that web page. 7. By copying, installing or otherwise using the software, Licensee agrees to be bound by the terms and conditions of this License Agreement. CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1 1. This LICENSE AGREEMENT is between the Corporation for National Research Initiatives, having an office at 1895 Preston White Drive, Reston, VA 20191 ("CNRI"), and the Individual or Organization ("Licensee") accessing and otherwise using Python 1.6.1 software in source or binary form and its associated documentation. 2. Subject to the terms and conditions of this License Agreement, CNRI hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python 1.6.1 alone or in any derivative version, provided, however, that CNRI's License Agreement and CNRI's notice of copyright, i.e., "Copyright © 1995-2001 Corporation for National Research Initiatives; All Rights Reserved" are retained in Python 1.6.1 alone or in any derivative version prepared by Licensee. Alternately, in lieu of CNRI's License Agreement, Licensee may substitute the following text (omitting the quotes): "Python 1.6.1 is made available subject to the terms and conditions in CNRI's License Agreement. This Agreement together with Python 1.6.1 may be located on the Internet using the following unique, persistent identifier (known as a handle): 1895.22/1013. This Agreement may also be obtained from a proxy server on the Internet using the following URL: http://hdl.handle.net/1895.22/1013."; 3. In the event Licensee prepares a derivative work that is based on or incorporates Python 1.6.1 or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to Python 1.6.1. 4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS" basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 6. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 7. This License Agreement shall be governed by the federal intellectual property law of the United States, including without limitation the federal copyright law, and, to the extent such U.S. federal law does not apply, by the law of the Commonwealth of Virginia, excluding Virginia's conflict of law provisions. Notwithstanding the foregoing, with regard to derivative works based on Python 1.6.1 that incorporate non-separable material that was previously distributed under the GNU General Public License (GPL), the law of the Commonwealth of Virginia shall govern this License Agreement only as to issues arising under or with respect to Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between CNRI and Licensee. This License Agreement does not grant permission to use CNRI trademarks or trade name in a trademark sense to endorse or promote products or services of Licensee, or any third party. 8. By clicking on the "ACCEPT" button where indicated, or by copying, installing or otherwise using Python 1.6.1, Licensee agrees to be bound by the terms and conditions of this License Agreement. CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2 Copyright © 1991 - 1995, Stichting Mathematisch Centrum Amsterdam, The Netherlands. All rights reserved. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Stichting Mathematisch Centrum or CWI not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Licenses and Acknowledgements for Incorporated Software This section is an incomplete, but growing list of licenses and acknowledgements for third-party software incorporated in the Python distribution. Mersenne Twister The _random module includes code based on a download from http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/MT2002/emt19937ar.html. The following are the verbatim comments from the original code: A C-program for MT19937, with initialization improved 2002/1/26. Coded by Takuji Nishimura and Makoto Matsumoto. Before using, initialize the state by using init_genrand(seed) or init_by_array(init_key, key_length). Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura, All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The names of its contributors may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Any feedback is very welcome. http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space) Sockets The socket module uses the functions, getaddrinfo(), and getnameinfo(), which are coded in separate source files from the WIDE Project, http://www.wide.ad.jp/. Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Floating point exception control The source for the fpectl module includes the following notice: --------------------------------------------------------------------- / Copyright (c) 1996. \ | The Regents of the University of California. | | All rights reserved. | | | | Permission to use, copy, modify, and distribute this software for | | any purpose without fee is hereby granted, provided that this en- | | tire notice is included in all copies of any software which is or | | includes a copy or modification of this software and in all | | copies of the supporting documentation for such software. | | | | This work was produced at the University of California, Lawrence | | Livermore National Laboratory under contract no. W-7405-ENG-48 | | between the U.S. Department of Energy and The Regents of the | | University of California for the operation of UC LLNL. | | | | DISCLAIMER | | | | This software was prepared as an account of work sponsored by an | | agency of the United States Government. Neither the United States | | Government nor the University of California nor any of their em- | | ployees, makes any warranty, express or implied, or assumes any | | liability or responsibility for the accuracy, completeness, or | | usefulness of any information, apparatus, product, or process | | disclosed, or represents that its use would not infringe | | privately-owned rights. Reference herein to any specific commer- | | cial products, process, or service by trade name, trademark, | | manufacturer, or otherwise, does not necessarily constitute or | | imply its endorsement, recommendation, or favoring by the United | | States Government or the University of California. The views and | | opinions of authors expressed herein do not necessarily state or | | reflect those of the United States Government or the University | | of California, and shall not be used for advertising or product | \ endorsement purposes. / --------------------------------------------------------------------- Asynchronous socket services The asynchat and asyncore modules contain the following notice: Copyright 1996 by Sam Rushing All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Sam Rushing not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. SAM RUSHING DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SAM RUSHING BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Cookie management The http.cookies module contains the following notice: Copyright 2000 by Timothy O'Malley All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Timothy O'Malley not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. Timothy O'Malley DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL Timothy O'Malley BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Execution tracing The trace module contains the following notice: portions copyright 2001, Autonomous Zones Industries, Inc., all rights... err... reserved and offered to the public under the terms of the Python 2.2 license. Author: Zooko O'Whielacronx http://zooko.com/ mailto:zooko@zooko.com Copyright 2000, Mojam Media, Inc., all rights reserved. Author: Skip Montanaro Copyright 1999, Bioreason, Inc., all rights reserved. Author: Andrew Dalke Copyright 1995-1997, Automatrix, Inc., all rights reserved. Author: Skip Montanaro Copyright 1991-1995, Stichting Mathematisch Centrum, all rights reserved. Permission to use, copy, modify, and distribute this Python software and its associated documentation for any purpose without fee is hereby granted, provided that the above copyright notice appears in all copies, and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of neither Automatrix, Bioreason or Mojam Media be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. UUencode and UUdecode functions The uu module contains the following notice: Copyright 1994 by Lance Ellinghouse Cathedral City, California Republic, United States of America. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Lance Ellinghouse not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE CENTRUM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Modified by Jack Jansen, CWI, July 1995: - Use binascii module to do the actual line-by-line conversion between ascii and binary. This results in a 1000-fold speedup. The C version is still 5 times faster, though. - Arguments more compliant with Python standard XML Remote Procedure Calls The xmlrpc.client module contains the following notice: The XML-RPC client interface is Copyright (c) 1999-2002 by Secret Labs AB Copyright (c) 1999-2002 by Fredrik Lundh By obtaining, using, and/or copying this software and/or its associated documentation, you agree that you have read, understood, and will comply with the following terms and conditions: Permission to use, copy, modify, and distribute this software and its associated documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies, and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Secret Labs AB or the author not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. test_epoll The test_epoll module contains the following notice: Copyright (c) 2001-2006 Twisted Matrix Laboratories. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Select kqueue The select module contains the following notice for the kqueue interface: Copyright (c) 2000 Doug White, 2006 James Knight, 2007 Christian Heimes All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. SipHash24 The file Python/pyhash.c contains Marek Majkowski’ implementation of Dan Bernstein’s SipHash24 algorithm. The contains the following note: Copyright (c) 2013 Marek Majkowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Original location: https://github.com/majek/csiphash/ Solution inspired by code from: Samuel Neves (supercop/crypto_auth/siphash24/little) djb (supercop/crypto_auth/siphash24/little2) Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c) strtod and dtoa The file Python/dtoa.c, which supplies C functions dtoa and strtod for conversion of C doubles to and from strings, is derived from the file of the same name by David M. Gay, currently available from http://www.netlib.org/fp/. The original file, as retrieved on March 16, 2009, contains the following copyright and licensing notice: /**************************************************************** * * The author of this software is David M. Gay. * * Copyright (c) 1991, 2000, 2001 by Lucent Technologies. * * Permission to use, copy, modify, and distribute this software for any * purpose without fee is hereby granted, provided that this entire notice * is included in all copies of any software which is or includes a copy * or modification of this software and in all copies of the supporting * documentation for such software. * * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR LUCENT MAKES ANY * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE. * ***************************************************************/ OpenSSL The modules hashlib, posix, ssl, crypt use the OpenSSL library for added performance if made available by the operating system. Additionally, the Windows and Mac OS X installers for Python may include a copy of the OpenSSL libraries, so we include a copy of the OpenSSL license here: LICENSE ISSUES ============== The OpenSSL toolkit stays under a dual license, i.e. both the conditions of the OpenSSL License and the original SSLeay license apply to the toolkit. See below for the actual license texts. Actually both licenses are BSD-style Open Source licenses. In case of any license issues related to OpenSSL please contact openssl-core@openssl.org. OpenSSL License --------------- /* ==================================================================== * Copyright (c) 1998-2008 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"; * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * openssl-core@openssl.org. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.openssl.org/)"; * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This product includes cryptographic software written by Eric Young * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com). * */ Original SSLeay License ----------------------- /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */ expat The pyexpat extension is built using an included copy of the expat sources unless the build is configured --with-system-expat: Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd and Clark Cooper Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. libffi The _ctypes extension is built using an included copy of the libffi sources unless the build is configured --with-system-libffi: Copyright (c) 1996-2008 Red Hat, Inc and others. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ``Software''), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. zlib The zlib extension is built using an included copy of the zlib sources if the zlib version found on the system is too old to be used for the build: Copyright (C) 1995-2011 Jean-loup Gailly and Mark Adler This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Jean-loup Gailly Mark Adler jloup@gzip.org madler@alumni.caltech.edu cfuhash The implementation of the hash table used by the tracemalloc is based on the cfuhash project: Copyright (c) 2005 Don Owens All rights reserved. This code is released under the BSD license: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. libmpdec The _decimal module is built using an included copy of the libmpdec library unless the build is configured --with-system-libmpdec: Copyright (c) 2008-2016 Stefan Krah. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================ pybind11 2.5.0 (Provided under following license) ================================================================================ Copyright (c) 2016 Wenzel Jakob , All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Please also refer to the file CONTRIBUTING.md, which clarifies licensing of external contributions to this project including patches, pull requests, etc. ================================================================================ result (Provided under following license) ================================================================================ Copyright (C) 2015-2020 Danilo Bargen and contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ requests 2.25.1 (Provided under following license) ================================================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. ================================================================================ toml 0.10.2 (Provided under following license) ================================================================================ The MIT License Copyright 2013-2019 William Pearson Copyright 2015-2016 Julien Enselme Copyright 2016 Google Inc. Copyright 2017 Samuel Vasko Copyright 2017 Nate Prewitt Copyright 2017 Jack Evans Copyright 2019 Filippo Broggini Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ pyyaml 5.3.1 (Provided under following license) ================================================================================ Copyright (c) 2017-2020 Ingy döt Net Copyright (c) 2006-2016 Kirill Simonov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ packaging 20.9 (Provided under following license) ================================================================================ This software is made available under the terms of *either* of the licenses found in LICENSE.APACHE or LICENSE.BSD. Contributions to this software is made under the terms of *both* these licenses. Apache 2.0 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS BSD Copyright (c) Donald Stufft and individual contributors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================ urllib3 1.26.4 (Provided under following license) ================================================================================ MIT License Copyright (c) 2008-2020 Andrey Petrov and contributors (see CONTRIBUTORS.txt) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ idna 2.6 (Provided under following license) ================================================================================ Copyright (c) 2013-2017, Kim Davies. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holder nor the names of the contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Portions of the codec implementation and unit tests are derived from the Python standard library, which carries the Python Software Foundation License: Copyright (c) 2001-2014 Python Software Foundation; All Rights Reserved Portions of the unit tests are derived from the Unicode standard, which is subject to the Unicode, Inc. License Agreement: Copyright (c) 1991-2014 Unicode, Inc. All rights reserved. Distributed under the Terms of Use in . Permission is hereby granted, free of charge, to any person obtaining a copy of the Unicode data files and any associated documentation (the "Data Files") or Unicode software and any associated documentation (the "Software") to deal in the Data Files or Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, and/or sell copies of the Data Files or Software, and to permit persons to whom the Data Files or Software are furnished to do so, provided that (a) this copyright and permission notice appear with all copies of the Data Files or Software, (b) this copyright and permission notice appear in associated documentation, and (c) there is clear notice in each modified Data File or in the Software as well as in the documentation associated with the Data File(s) or Software that the data or software has been modified. THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE DATA FILES OR SOFTWARE. Except as contained in this notice, the name of a copyright holder shall not be used in advertising or otherwise to promote the sale, use or other dealings in these Data Files or Software without prior written authorization of the copyright holder. ================================================================================ certifi 2020.12.5 (Provided under following license) ================================================================================ This packge contains a modified version of ca-bundle.crt: ca-bundle.crt -- Bundle of CA Root Certificates Certificate data from Mozilla as of: Thu Nov 3 19:04:19 2011# This is a bundle of X.509 certificates of public Certificate Authorities (CA). These were automatically extracted from Mozilla's root certificates file (certdata.txt). This file can be found in the mozilla source tree: http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1# It contains the certificates in PEM format and therefore can be directly used with curl / libcurl / php_curl, or with an Apache+mod_ssl webserver for SSL client authentication. Just configure this file as the SSLCACertificateFile.# ***** BEGIN LICENSE BLOCK ***** This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ***** END LICENSE BLOCK ***** @(#) $RCSfile: certdata.txt,v $ $Revision: 1.80 $ $Date: 2011/11/03 15:11:58 $ ================================================================================ chardet 3.0.4 (Provided under following license) ================================================================================ GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ================================================================================ GLib (Provided under following license) ================================================================================ GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ================================================================================ GStreamer (Provided under following license) ================================================================================ GNU LIBRARY GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1991 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the library GPL. It is numbered 2 because it goes with version 2 of the ordinary GPL.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Library General Public License, applies to some specially designated Free Software Foundation software, and to any other libraries whose authors decide to use it. You can use it for your libraries, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library, or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link a program with the library, you must provide complete object files to the recipients so that they can relink them with the library, after making changes to the library and recompiling it. And you must show them these terms so they know their rights. Our method of protecting your rights has two steps: (1) copyright the library, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the library. Also, for each distributor's protection, we want to make certain that everyone understands that there is no warranty for this free library. If the library is modified by someone else and passed on, we want its recipients to know that what they have is not the original version, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that companies distributing free software will individually obtain patent licenses, thus in effect transforming the program into proprietary software. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License, which was designed for utility programs. This license, the GNU Library General Public License, applies to certain designated libraries. This license is quite different from the ordinary one; be sure to read it in full, and don't assume that anything in it is the same as in the ordinary license. The reason we have a separate public license for some libraries is that they blur the distinction we usually make between modifying or adding to a program and simply using it. Linking a program with a library, without changing the library, is in some sense simply using the library, and is analogous to running a utility program or application program. However, in a textual and legal sense, the linked executable is a combined work, a derivative of the original library, and the ordinary General Public License treats it as such. Because of this blurred distinction, using the ordinary General Public License for libraries did not effectively promote software sharing, because most developers did not use the libraries. We concluded that weaker conditions might promote sharing better. However, unrestricted linking of non-free programs would deprive the users of those programs of all benefit from the free status of the libraries themselves. This Library General Public License is intended to permit developers of non-free programs to use free libraries, while preserving your freedom as a user of such programs to change the free libraries that are incorporated in them. (We have not seen how to achieve this as regards changes in header files, but we have achieved it as regards changes in the actual functions of the Library.) The hope is that this will lead to faster development of free libraries. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, while the latter only works together with the library. Note that it is possible for a library to be covered by the ordinary General Public License rather than by this special one. GNU LIBRARY GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Library General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also compile or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. c) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. d) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Library General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! ================================================================================ docker 4.4.1 (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS Copyright 2016 Docker, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================================================ jinja 2.11.2 (Provided under following license) =============================================================================== Copyright 2007 Pallets Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================ markupsafe 1.1.1 (Provided under following license) =============================================================================== Copyright 2010 Pallets Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================ urllib3 1.26.2 (Provided under following license) =============================================================================== MIT License Copyright (c) 2008-2020 Andrey Petrov and contributors (see CONTRIBUTORS.txt) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ pyyaml 5.3.1 (Provided under following license) =============================================================================== Copyright (c) 2017-2021 Ingy döt Net Copyright (c) 2006-2016 Kirill Simonov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ typing 3.7.4.3 (Provided under following license) =============================================================================== A. HISTORY OF THE SOFTWARE ========================== Python was created in the early 1990s by Guido van Rossum at Stichting Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands as a successor of a language called ABC. Guido remains Python's principal author, although it includes many contributions from others. In 1995, Guido continued his work on Python at the Corporation for National Research Initiatives (CNRI, see http://www.cnri.reston.va.us) in Reston, Virginia where he released several versions of the software. In May 2000, Guido and the Python core development team moved to BeOpen.com to form the BeOpen PythonLabs team. In October of the same year, the PythonLabs team moved to Digital Creations (now Zope Corporation, see http://www.zope.com). In 2001, the Python Software Foundation (PSF, see http://www.python.org/psf/) was formed, a non-profit organization created specifically to own Python-related Intellectual Property. Zope Corporation is a sponsoring member of the PSF. All Python releases are Open Source (see http://www.opensource.org for the Open Source Definition). Historically, most, but not all, Python releases have also been GPL-compatible; the table below summarizes the various releases. Release Derived Year Owner GPL- from compatible? (1) 0.9.0 thru 1.2 1991-1995 CWI yes 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes 1.6 1.5.2 2000 CNRI no 2.0 1.6 2000 BeOpen.com no 1.6.1 1.6 2001 CNRI yes (2) 2.1 2.0+1.6.1 2001 PSF no 2.0.1 2.0+1.6.1 2001 PSF yes 2.1.1 2.1+2.0.1 2001 PSF yes 2.1.2 2.1.1 2002 PSF yes 2.1.3 2.1.2 2002 PSF yes 2.2 and above 2.1.1 2001-now PSF yes Footnotes: (1) GPL-compatible doesn't mean that we're distributing Python under the GPL. All Python licenses, unlike the GPL, let you distribute a modified version without making your changes open source. The GPL-compatible licenses make it possible to combine Python with other software that is released under the GPL; the others don't. (2) According to Richard Stallman, 1.6.1 is not GPL-compatible, because its license has a choice of law clause. According to CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1 is "not incompatible" with the GPL. Thanks to the many outside volunteers who have worked under Guido's direction to make these releases possible. B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON =============================================================== PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 -------------------------------------------- 1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and the Individual or Organization ("Licensee") accessing and otherwise using this software ("Python") in source or binary form and its associated documentation. 2. Subject to the terms and conditions of this License Agreement, PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python alone or in any derivative version, provided, however, that PSF's License Agreement and PSF's notice of copyright, i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are retained in Python alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or incorporates Python or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to Python. 4. PSF is making Python available to Licensee on an "AS IS" basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 6. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 7. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between PSF and Licensee. This License Agreement does not grant permission to use PSF trademarks or trade name in a trademark sense to endorse or promote products or services of Licensee, or any third party. 8. By copying, installing or otherwise using Python, Licensee agrees to be bound by the terms and conditions of this License Agreement. BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0 ------------------------------------------- BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1 1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the Individual or Organization ("Licensee") accessing and otherwise using this software in source or binary form and its associated documentation ("the Software"). 2. Subject to the terms and conditions of this BeOpen Python License Agreement, BeOpen hereby grants Licensee a non-exclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use the Software alone or in any derivative version, provided, however, that the BeOpen Python License is retained in the Software, alone or in any derivative version prepared by Licensee. 3. BeOpen is making the Software available to Licensee on an "AS IS" basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 5. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 6. This License Agreement shall be governed by and interpreted in all respects by the law of the State of California, excluding conflict of law provisions. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between BeOpen and Licensee. This License Agreement does not grant permission to use BeOpen trademarks or trade names in a trademark sense to endorse or promote products or services of Licensee, or any third party. As an exception, the "BeOpen Python" logos available at http://www.pythonlabs.com/logos.html may be used according to the permissions granted on that web page. 7. By copying, installing or otherwise using the software, Licensee agrees to be bound by the terms and conditions of this License Agreement. CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1 --------------------------------------- 1. This LICENSE AGREEMENT is between the Corporation for National Research Initiatives, having an office at 1895 Preston White Drive, Reston, VA 20191 ("CNRI"), and the Individual or Organization ("Licensee") accessing and otherwise using Python 1.6.1 software in source or binary form and its associated documentation. 2. Subject to the terms and conditions of this License Agreement, CNRI hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python 1.6.1 alone or in any derivative version, provided, however, that CNRI's License Agreement and CNRI's notice of copyright, i.e., "Copyright (c) 1995-2001 Corporation for National Research Initiatives; All Rights Reserved" are retained in Python 1.6.1 alone or in any derivative version prepared by Licensee. Alternately, in lieu of CNRI's License Agreement, Licensee may substitute the following text (omitting the quotes): "Python 1.6.1 is made available subject to the terms and conditions in CNRI's License Agreement. This Agreement together with Python 1.6.1 may be located on the Internet using the following unique, persistent identifier (known as a handle): 1895.22/1013. This Agreement may also be obtained from a proxy server on the Internet using the following URL: http://hdl.handle.net/1895.22/1013". 3. In the event Licensee prepares a derivative work that is based on or incorporates Python 1.6.1 or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to Python 1.6.1. 4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS" basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 6. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 7. This License Agreement shall be governed by the federal intellectual property law of the United States, including without limitation the federal copyright law, and, to the extent such U.S. federal law does not apply, by the law of the Commonwealth of Virginia, excluding Virginia's conflict of law provisions. Notwithstanding the foregoing, with regard to derivative works based on Python 1.6.1 that incorporate non-separable material that was previously distributed under the GNU General Public License (GPL), the law of the Commonwealth of Virginia shall govern this License Agreement only as to issues arising under or with respect to Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between CNRI and Licensee. This License Agreement does not grant permission to use CNRI trademarks or trade name in a trademark sense to endorse or promote products or services of Licensee, or any third party. 8. By clicking on the "ACCEPT" button where indicated, or by copying, installing or otherwise using Python 1.6.1, Licensee agrees to be bound by the terms and conditions of this License Agreement. ACCEPT CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2 -------------------------------------------------- Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam, The Netherlands. All rights reserved. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Stichting Mathematisch Centrum or CWI not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ================================================================================ yaml-cpp 0.6.3 (Provided under following license) =============================================================================== Copyright (c) 2008-2015 Jesse Beder. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ gflags 2.2.1 (Provided under following license) =============================================================================== Copyright (c) 2006, Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================ gtest 1.8.0 (Provided under following license) =============================================================================== Copyright 2008, Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================ rules_python 0.1.0 (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================================================ DCMI specification (Provided under following license) =============================================================================== Creative Commons Attribution 4.0 International Public License By exercising the Licensed Rights (defined below), You accept and agree to be bound by the terms and conditions of this Creative Commons Attribution 4.0 International Public License ("Public License"). To the extent this Public License may be interpreted as a contract, You are granted the Licensed Rights in consideration of Your acceptance of these terms and conditions, and the Licensor grants You such rights in consideration of benefits the Licensor receives from making the Licensed Material available under these terms and conditions. Section 1 – Definitions. Adapted Material means material subject to Copyright and Similar Rights that is derived from or based upon the Licensed Material and in which the Licensed Material is translated, altered, arranged, transformed, or otherwise modified in a manner requiring permission under the Copyright and Similar Rights held by the Licensor. For purposes of this Public License, where the Licensed Material is a musical work, performance, or sound recording, Adapted Material is always produced where the Licensed Material is synched in timed relation with a moving image. Adapter's License means the license You apply to Your Copyright and Similar Rights in Your contributions to Adapted Material in accordance with the terms and conditions of this Public License. Copyright and Similar Rights means copyright and/or similar rights closely related to copyright including, without limitation, performance, broadcast, sound recording, and Sui Generis Database Rights, without regard to how the rights are labeled or categorized. For purposes of this Public License, the rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. Effective Technological Measures means those measures that, in the absence of proper authority, may not be circumvented under laws fulfilling obligations under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, and/or similar international agreements. Exceptions and Limitations means fair use, fair dealing, and/or any other exception or limitation to Copyright and Similar Rights that applies to Your use of the Licensed Material. Licensed Material means the artistic or literary work, database, or other material to which the Licensor applied this Public License. Licensed Rights means the rights granted to You subject to the terms and conditions of this Public License, which are limited to all Copyright and Similar Rights that apply to Your use of the Licensed Material and that the Licensor has authority to license. Licensor means the individual(s) or entity(ies) granting rights under this Public License. Share means to provide material to the public by any means or process that requires permission under the Licensed Rights, such as reproduction, public display, public performance, distribution, dissemination, communication, or importation, and to make material available to the public including in ways that members of the public may access the material from a place and at a time individually chosen by them. Sui Generis Database Rights means rights other than copyright resulting from Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, as amended and/or succeeded, as well as other essentially equivalent rights anywhere in the world. You means the individual or entity exercising the Licensed Rights under this Public License. Your has a corresponding meaning. Section 2 – Scope. License grant. Subject to the terms and conditions of this Public License, the Licensor hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, irrevocable license to exercise the Licensed Rights in the Licensed Material to: reproduce and Share the Licensed Material, in whole or in part; and produce, reproduce, and Share Adapted Material. Exceptions and Limitations. For the avoidance of doubt, where Exceptions and Limitations apply to Your use, this Public License does not apply, and You do not need to comply with its terms and conditions. Term. The term of this Public License is specified in Section 6(a). Media and formats; technical modifications allowed. The Licensor authorizes You to exercise the Licensed Rights in all media and formats whether now known or hereafter created, and to make technical modifications necessary to do so. The Licensor waives and/or agrees not to assert any right or authority to forbid You from making technical modifications necessary to exercise the Licensed Rights, including technical modifications necessary to circumvent Effective Technological Measures. For purposes of this Public License, simply making modifications authorized by this Section 2(a)(4) never produces Adapted Material. Downstream recipients. Offer from the Licensor – Licensed Material. Every recipient of the Licensed Material automatically receives an offer from the Licensor to exercise the Licensed Rights under the terms and conditions of this Public License. No downstream restrictions. You may not offer or impose any additional or different terms or conditions on, or apply any Effective Technological Measures to, the Licensed Material if doing so restricts exercise of the Licensed Rights by any recipient of the Licensed Material. No endorsement. Nothing in this Public License constitutes or may be construed as permission to assert or imply that You are, or that Your use of the Licensed Material is, connected with, or sponsored, endorsed, or granted official status by, the Licensor or others designated to receive attribution as provided in Section 3(a)(1)(A)(i). Other rights. Moral rights, such as the right of integrity, are not licensed under this Public License, nor are publicity, privacy, and/or other similar personality rights; however, to the extent possible, the Licensor waives and/or agrees not to assert any such rights held by the Licensor to the limited extent necessary to allow You to exercise the Licensed Rights, but not otherwise. Patent and trademark rights are not licensed under this Public License. To the extent possible, the Licensor waives any right to collect royalties from You for the exercise of the Licensed Rights, whether directly or through a collecting society under any voluntary or waivable statutory or compulsory licensing scheme. In all other cases the Licensor expressly reserves any right to collect such royalties. Section 3 – License Conditions. Your exercise of the Licensed Rights is expressly made subject to the following conditions. Attribution. If You Share the Licensed Material (including in modified form), You must: retain the following if it is supplied by the Licensor with the Licensed Material: identification of the creator(s) of the Licensed Material and any others designated to receive attribution, in any reasonable manner requested by the Licensor (including by pseudonym if designated); a copyright notice; a notice that refers to this Public License; a notice that refers to the disclaimer of warranties; a URI or hyperlink to the Licensed Material to the extent reasonably practicable; indicate if You modified the Licensed Material and retain an indication of any previous modifications; and indicate the Licensed Material is licensed under this Public License, and include the text of, or the URI or hyperlink to, this Public License. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner based on the medium, means, and context in which You Share the Licensed Material. For example, it may be reasonable to satisfy the conditions by providing a URI or hyperlink to a resource that includes the required information. If requested by the Licensor, You must remove any of the information required by Section 3(a)(1)(A) to the extent reasonably practicable. If You Share Adapted Material You produce, the Adapter's License You apply must not prevent recipients of the Adapted Material from complying with this Public License. Section 4 – Sui Generis Database Rights. Where the Licensed Rights include Sui Generis Database Rights that apply to Your use of the Licensed Material: for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, reuse, reproduce, and Share all or a substantial portion of the contents of the database; if You include all or a substantial portion of the database contents in a database in which You have Sui Generis Database Rights, then the database in which You have Sui Generis Database Rights (but not its individual contents) is Adapted Material; and You must comply with the conditions in Section 3(a) if You Share all or a substantial portion of the contents of the database. For the avoidance of doubt, this Section 4 supplements and does not replace Your obligations under this Public License where the Licensed Rights include other Copyright and Similar Rights. Section 5 – Disclaimer of Warranties and Limitation of Liability. Unless otherwise separately undertaken by the Licensor, to the extent possible, the Licensor offers the Licensed Material as-is and as-available, and makes no representations or warranties of any kind concerning the Licensed Material, whether express, implied, statutory, or other. This includes, without limitation, warranties of title, merchantability, fitness for a particular purpose, non-infringement, absence of latent or other defects, accuracy, or the presence or absence of errors, whether or not known or discoverable. Where disclaimers of warranties are not allowed in full or in part, this disclaimer may not apply to You. To the extent possible, in no event will the Licensor be liable to You on any legal theory (including, without limitation, negligence) or otherwise for any direct, special, indirect, incidental, consequential, punitive, exemplary, or other losses, costs, expenses, or damages arising out of this Public License or use of the Licensed Material, even if the Licensor has been advised of the possibility of such losses, costs, expenses, or damages. Where a limitation of liability is not allowed in full or in part, this limitation may not apply to You. The disclaimer of warranties and limitation of liability provided above shall be interpreted in a manner that, to the extent possible, most closely approximates an absolute disclaimer and waiver of all liability. Section 6 – Term and Termination. This Public License applies for the term of the Copyright and Similar Rights licensed here. However, if You fail to comply with this Public License, then Your rights under this Public License terminate automatically. Where Your right to use the Licensed Material has terminated under Section 6(a), it reinstates: automatically as of the date the violation is cured, provided it is cured within 30 days of Your discovery of the violation; or upon express reinstatement by the Licensor. For the avoidance of doubt, this Section 6(b) does not affect any right the Licensor may have to seek remedies for Your violations of this Public License. For the avoidance of doubt, the Licensor may also offer the Licensed Material under separate terms or conditions or stop distributing the Licensed Material at any time; however, doing so will not terminate this Public License. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. Section 7 – Other Terms and Conditions. The Licensor shall not be bound by any additional or different terms or conditions communicated by You unless expressly agreed. Any arrangements, understandings, or agreements regarding the Licensed Material not stated herein are separate from and independent of the terms and conditions of this Public License. Section 8 – Interpretation. For the avoidance of doubt, this Public License does not, and shall not be interpreted to, reduce, limit, restrict, or impose conditions on any use of the Licensed Material that could lawfully be made without permission under this Public License. To the extent possible, if any provision of this Public License is deemed unenforceable, it shall be automatically reformed to the minimum extent necessary to make it enforceable. If the provision cannot be reformed, it shall be severed from this Public License without affecting the enforceability of the remaining terms and conditions. No term or condition of this Public License will be waived and no failure to comply consented to unless expressly agreed to by the Licensor. Nothing in this Public License constitutes or may be interpreted as a limitation upon, or waiver of, any privileges and immunities that apply to the Licensor or You, including from the legal processes of any jurisdiction or authority. =============================================================================== breakpad (Provided under following license) =============================================================================== Copyright (c) 2006, Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------- Copyright 2001-2004 Unicode, Inc. Disclaimer This source code is provided as is by Unicode, Inc. No claims are made as to fitness for any particular purpose. No warranties of any kind are expressed or implied. The recipient agrees to determine applicability of information provided. If this file has been purchased on magnetic or optical media from Unicode, Inc., the sole remedy for any claim will be exchange of defective media within 90 days of receipt. Limitations on Rights to Redistribute This Code Unicode, Inc. hereby grants the right to freely use the information supplied in this file in the creation of products supporting the Unicode Standard, and to make copies of this file in any form for internal or external distribution as long as this notice remains attached. ================================================================================ linux-syscall-support (lss) (Provided under following license) =============================================================================== Copyright (c) 2005-2011, Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ================================================================================ bazel skylib 1.0.2 (Provided under following license) ================================================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================================================ nlohmann-json 3.10.4 (Provided under following license) ================================================================================ MIT License Copyright (c) 2013-2021 Niels Lohmann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ urwid 2.1.2 (Provided under following license) ================================================================================ GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. ================================================================================ rules_pkg 0.6.0 (Provided under following license) ================================================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================================================ dlpack 0.8 (Provided under following license) ================================================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2017 by Contributors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================== magic_enum 0.9.3 (Provided under following license) =============================================================================== MIT License Copyright (c) 2019 - 2023 Daniil Goncharov Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================================================ python-on-whales 0.65.0 (Provided under following license) ================================================================================ MIT License Copyright (c) 2020 Gabriel de Marmiesse de Lussan Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================================================== cpprestsdk 2.10.18 (Provided under following license) =============================================================================== C++ REST SDK The MIT License (MIT) Copyright (c) Microsoft Corporation All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================================================== grpc 1.48.0 (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------- BSD 3-Clause License Copyright 2016, Google Inc. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ----------------------------------------------------------- Mozilla Public License Version 2.0 ================================== 1. Definitions -------------- 1.1. "Contributor" means each individual or legal entity that creates, contributes to the creation of, or owns Covered Software. 1.2. "Contributor Version" means the combination of the Contributions of others (if any) used by a Contributor and that particular Contributor's Contribution. 1.3. "Contribution" means Covered Software of a particular Contributor. 1.4. "Covered Software" means Source Code Form to which the initial Contributor has attached the notice in Exhibit A, the Executable Form of such Source Code Form, and Modifications of such Source Code Form, in each case including portions thereof. 1.5. "Incompatible With Secondary Licenses" means (a) that the initial Contributor has attached the notice described in Exhibit B to the Covered Software; or (b) that the Covered Software was made available under the terms of version 1.1 or earlier of the License, but not also under the terms of a Secondary License. 1.6. "Executable Form" means any form of the work other than Source Code Form. 1.7. "Larger Work" means a work that combines Covered Software with other material, in a separate file or files, that is not Covered Software. 1.8. "License" means this document. 1.9. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently, any and all of the rights conveyed by this License. 1.10. "Modifications" means any of the following: (a) any file in Source Code Form that results from an addition to, deletion from, or modification of the contents of Covered Software; or (b) any new file in Source Code Form that contains any Covered Software. 1.11. "Patent Claims" of a Contributor means any patent claim(s), including without limitation, method, process, and apparatus claims, in any patent Licensable by such Contributor that would be infringed, but for the grant of the License, by the making, using, selling, offering for sale, having made, import, or transfer of either its Contributions or its Contributor Version. 1.12. "Secondary License" means either the GNU General Public License, Version 2.0, the GNU Lesser General Public License, Version 2.1, the GNU Affero General Public License, Version 3.0, or any later versions of those licenses. 1.13. "Source Code Form" means the form of the work preferred for making modifications. 1.14. "You" (or "Your") means an individual or a legal entity exercising rights under this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. 2. License Grants and Conditions -------------------------------- 2.1. Grants Each Contributor hereby grants You a world-wide, royalty-free, non-exclusive license: (a) under intellectual property rights (other than patent or trademark) Licensable by such Contributor to use, reproduce, make available, modify, display, perform, distribute, and otherwise exploit its Contributions, either on an unmodified basis, with Modifications, or as part of a Larger Work; and (b) under Patent Claims of such Contributor to make, use, sell, offer for sale, have made, import, and otherwise transfer either its Contributions or its Contributor Version. 2.2. Effective Date The licenses granted in Section 2.1 with respect to any Contribution become effective for each Contribution on the date the Contributor first distributes such Contribution. 2.3. Limitations on Grant Scope The licenses granted in this Section 2 are the only rights granted under this License. No additional rights or licenses will be implied from the distribution or licensing of Covered Software under this License. Notwithstanding Section 2.1(b) above, no patent license is granted by a Contributor: (a) for any code that a Contributor has removed from Covered Software; or (b) for infringements caused by: (i) Your and any other third party's modifications of Covered Software, or (ii) the combination of its Contributions with other software (except as part of its Contributor Version); or (c) under Patent Claims infringed by Covered Software in the absence of its Contributions. This License does not grant any rights in the trademarks, service marks, or logos of any Contributor (except as may be necessary to comply with the notice requirements in Section 3.4). 2.4. Subsequent Licenses No Contributor makes additional grants as a result of Your choice to distribute the Covered Software under a subsequent version of this License (see Section 10.2) or under the terms of a Secondary License (if permitted under the terms of Section 3.3). 2.5. Representation Each Contributor represents that the Contributor believes its Contributions are its original creation(s) or it has sufficient rights to grant the rights to its Contributions conveyed by this License. 2.6. Fair Use This License is not intended to limit any rights You have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. 2.7. Conditions Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in Section 2.1. 3. Responsibilities ------------------- 3.1. Distribution of Source Form All distribution of Covered Software in Source Code Form, including any Modifications that You create or to which You contribute, must be under the terms of this License. You must inform recipients that the Source Code Form of the Covered Software is governed by the terms of this License, and how they can obtain a copy of this License. You may not attempt to alter or restrict the recipients' rights in the Source Code Form. 3.2. Distribution of Executable Form If You distribute Covered Software in Executable Form then: (a) such Covered Software must also be made available in Source Code Form, as described in Section 3.1, and You must inform recipients of the Executable Form how they can obtain a copy of such Source Code Form by reasonable means in a timely manner, at a charge no more than the cost of distribution to the recipient; and (b) You may distribute such Executable Form under the terms of this License, or sublicense it under different terms, provided that the license for the Executable Form does not attempt to limit or alter the recipients' rights in the Source Code Form under this License. 3.3. Distribution of a Larger Work You may create and distribute a Larger Work under terms of Your choice, provided that You also comply with the requirements of this License for the Covered Software. If the Larger Work is a combination of Covered Software with a work governed by one or more Secondary Licenses, and the Covered Software is not Incompatible With Secondary Licenses, this License permits You to additionally distribute such Covered Software under the terms of such Secondary License(s), so that the recipient of the Larger Work may, at their option, further distribute the Covered Software under the terms of either this License or such Secondary License(s). 3.4. Notices You may not remove or alter the substance of any license notices (including copyright notices, patent notices, disclaimers of warranty, or limitations of liability) contained within the Source Code Form of the Covered Software, except that You may alter any license notices to the extent required to remedy known factual inaccuracies. 3.5. Application of Additional Terms You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, You may do so only on Your own behalf, and not on behalf of any Contributor. You must make it absolutely clear that any such warranty, support, indemnity, or liability obligation is offered by You alone, and You hereby agree to indemnify every Contributor for any liability incurred by such Contributor as a result of warranty, support, indemnity or liability terms You offer. You may include additional disclaimers of warranty and limitations of liability specific to any jurisdiction. 4. Inability to Comply Due to Statute or Regulation --------------------------------------------------- If it is impossible for You to comply with any of the terms of this License with respect to some or all of the Covered Software due to statute, judicial order, or regulation then You must: (a) comply with the terms of this License to the maximum extent possible; and (b) describe the limitations and the code they affect. Such description must be placed in a text file included with all distributions of the Covered Software under this License. Except to the extent prohibited by statute or regulation, such description must be sufficiently detailed for a recipient of ordinary skill to be able to understand it. 5. Termination -------------- 5.1. The rights granted under this License will terminate automatically if You fail to comply with any of its terms. However, if You become compliant, then the rights granted under this License from a particular Contributor are reinstated (a) provisionally, unless and until such Contributor explicitly and finally terminates Your grants, and (b) on an ongoing basis, if such Contributor fails to notify You of the non-compliance by some reasonable means prior to 60 days after You have come back into compliance. Moreover, Your grants from a particular Contributor are reinstated on an ongoing basis if such Contributor notifies You of the non-compliance by some reasonable means, this is the first time You have received notice of non-compliance with this License from such Contributor, and You become compliant prior to 30 days after Your receipt of the notice. 5.2. If You initiate litigation against any entity by asserting a patent infringement claim (excluding declaratory judgment actions, counter-claims, and cross-claims) alleging that a Contributor Version directly or indirectly infringes any patent, then the rights granted to You by any and all Contributors for the Covered Software under Section 2.1 of this License shall terminate. 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user license agreements (excluding distributors and resellers) which have been validly granted by You or Your distributors under this License prior to termination shall survive termination. ************************************************************************ * * * 6. Disclaimer of Warranty * * ------------------------- * * * * Covered Software is provided under this License on an "as is" * * basis, without warranty of any kind, either expressed, implied, or * * statutory, including, without limitation, warranties that the * * Covered Software is free of defects, merchantable, fit for a * * particular purpose or non-infringing. The entire risk as to the * * quality and performance of the Covered Software is with You. * * Should any Covered Software prove defective in any respect, You * * (not any Contributor) assume the cost of any necessary servicing, * * repair, or correction. This disclaimer of warranty constitutes an * * essential part of this License. No use of any Covered Software is * * authorized under this License except under this disclaimer. * * * ************************************************************************ ************************************************************************ * * * 7. Limitation of Liability * * -------------------------- * * * * Under no circumstances and under no legal theory, whether tort * * (including negligence), contract, or otherwise, shall any * * Contributor, or anyone who distributes Covered Software as * * permitted above, be liable to You for any direct, indirect, * * special, incidental, or consequential damages of any character * * including, without limitation, damages for lost profits, loss of * * goodwill, work stoppage, computer failure or malfunction, or any * * and all other commercial damages or losses, even if such party * * shall have been informed of the possibility of such damages. This * * limitation of liability shall not apply to liability for death or * * personal injury resulting from such party's negligence to the * * extent applicable law prohibits such limitation. Some * * jurisdictions do not allow the exclusion or limitation of * * incidental or consequential damages, so this exclusion and * * limitation may not apply to You. * * * ************************************************************************ 8. Litigation ------------- Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. 9. Miscellaneous ---------------- This License represents the complete agreement concerning the subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not be used to construe this License against a Contributor. 10. Versions of the License --------------------------- 10.1. New Versions Mozilla Foundation is the license steward. Except as provided in Section 10.3, no one other than the license steward has the right to modify or publish new versions of this License. Each version will be given a distinguishing version number. 10.2. Effect of New Versions You may distribute the Covered Software under the terms of the version of the License under which You originally received the Covered Software, or under the terms of any subsequent version published by the license steward. 10.3. Modified Versions If you create software not governed by this License, and you want to create a new license for such software, you may create and use a modified version of this License if you rename the license and remove any references to the name of the license steward (except to note that such modified license differs from this License). 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses If You choose to distribute Source Code Form that is Incompatible With Secondary Licenses under the terms of this version of the License, the notice described in Exhibit B of this License must be attached. Exhibit A - Source Code Form License Notice ------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. If it is not possible or desirable to put the notice in a particular file, then You may include the notice in a location (such as a LICENSE file in a relevant directory) where a recipient would be likely to look for such a notice. You may add additional accurate notices of copyright ownership. Exhibit B - "Incompatible With Secondary Licenses" Notice --------------------------------------------------------- This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0. =============================================================================== boringssl-b9232f9e27e5668bc0414879dcdedb2a59ea75f2 (Provided under following license) =============================================================================== BoringSSL is a fork of OpenSSL. As such, large parts of it fall under OpenSSL licensing. Files that are completely new have a Google copyright and an ISC license. This license is reproduced at the bottom of this file. Contributors to BoringSSL are required to follow the CLA rules for Chromium: https://cla.developers.google.com/clas Files in third_party/ have their own licenses, as described therein. The MIT license, for third_party/fiat, which, unlike other third_party directories, is compiled into non-test libraries, is included below. The OpenSSL toolkit stays under a dual license, i.e. both the conditions of the OpenSSL License and the original SSLeay license apply to the toolkit. See below for the actual license texts. Actually both licenses are BSD-style Open Source licenses. In case of any license issues related to OpenSSL please contact openssl-core@openssl.org. The following are Google-internal bug numbers where explicit permission from some authors is recorded for use of their work. (This is purely for our own record keeping.) 27287199 27287880 27287883 OpenSSL License --------------- /* ==================================================================== * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. All advertising materials mentioning features or use of this * software must display the following acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"; * * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to * endorse or promote products derived from this software without * prior written permission. For written permission, please contact * openssl-core@openssl.org. * * 5. Products derived from this software may not be called "OpenSSL" * nor may "OpenSSL" appear in their names without prior written * permission of the OpenSSL Project. * * 6. Redistributions of any form whatsoever must retain the following * acknowledgment: * "This product includes software developed by the OpenSSL Project * for use in the OpenSSL Toolkit (http://www.openssl.org/)"; * * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== * * This product includes cryptographic software written by Eric Young * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com). * */ Original SSLeay License ----------------------- /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * * This package is an SSL implementation written * by Eric Young (eay@cryptsoft.com). * The implementation was written so as to conform with Netscapes SSL. * * This library is free for commercial and non-commercial use as long as * the following conditions are aheared to. The following conditions * apply to all code found in this distribution, be it the RC4, RSA, * lhash, DES, etc., code; not just the SSL code. The SSL documentation * included with this distribution is covered by the same copyright terms * except that the holder is Tim Hudson (tjh@cryptsoft.com). * * Copyright remains Eric Young's, and as such any Copyright notices in * the code are not to be removed. * If this package is used in a product, Eric Young should be given attribution * as the author of the parts of the library used. * This can be in the form of a textual message at program startup or * in documentation (online or textual) provided with the package. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: * "This product includes cryptographic software written by * Eric Young (eay@cryptsoft.com)" * The word 'cryptographic' can be left out if the rouines from the library * being used are not cryptographic related :-). * 4. If you include any Windows specific code (or a derivative thereof) from * the apps directory (application code) you must include an acknowledgement: * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" * * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * The licence and distribution terms for any publically available version or * derivative of this code cannot be changed. i.e. this code cannot simply be * copied and put under another distribution licence * [including the GNU Public Licence.] */ ISC license used for completely new code in BoringSSL: /* Copyright (c) 2015, Google Inc. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ The code in third_party/fiat carries the MIT license: Copyright (c) 2015-2016 the fiat-crypto authors (see https://github.com/mit-plv/fiat-crypto/blob/master/AUTHORS). Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Licenses for support code ------------------------- Parts of the TLS test suite are under the Go license. This code is not included in BoringSSL (i.e. libcrypto and libssl) when compiled, however, so distributing code linked against BoringSSL does not trigger this license: Copyright (c) 2009 The Go Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. BoringSSL uses the Chromium test infrastructure to run a continuous build, trybots etc. The scripts which manage this, and the script for generating build metadata, are under the Chromium license. Distributing code linked against BoringSSL does not trigger this license. Copyright 2015 The Chromium Authors. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================== boost 1.79.0 (Provided under following license) =============================================================================== Boost Software License - Version 1.0 - August 17th, 2003 Permission is hereby granted, free of charge, to any person or organization obtaining a copy of the software and accompanying documentation covered by this license (the "Software") to use, reproduce, display, distribute, execute, and transmit the Software, and to prepare derivative works of the Software, and to permit third-parties to whom the Software is furnished to do so, all subject to the following: The copyright notices in the Software and this entire statement, including the above license grant, this restriction and the following disclaimer, must be included in all copies of the Software, in whole or in part, and all derivative works of the Software, unless such copies or derivative works are solely in the form of machine-executable object code generated by a source language processor. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================================================== protobuf-22d0e265de7d2b3d2e9a00d071313502e7d4cccf (Provided under following license) =============================================================================== Copyright 2008 Google Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Google Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Code generated by the Protocol Buffer compiler is owned by the owner of the input file used when generating it. This code is not standalone and requires a support library to be linked with it. This support library is itself covered by the above license. =============================================================================== pyarmor 7.7.4 (Provided under following license) =============================================================================== Pyarmor 8.0 End User License Agreement The following agreement regarding Pyarmor is made between Jondy Zhao - referred to as "licensor" - and anyone or organization who is installing, accessing or in any other way using Pyarmor - referred to as "user" or "you". 1. Definitions -------------- 1.1. "This Software" means Pyarmor 8.0, it doesn't include Pyarmor prior to 8.0. Pyarmor 8.0 is rewritten, and provides new features. For compatibility, Pyarmor 8.0 also includes most of the old features, this license doesn't apply to those old features. It's only for new features. 1.2. "Product" means any application or software for sale. 1.3. "One Product" means a product name and everything that makes up this name. It includes all the devices to develop, build, debug, test product. It also includes product current version, history versions and all the future versions. One product may has several variants, each variant name is composed of product name plus feature name. As long as the proportion of the variable part is far less than that of the common part, they're considered as "one product". 1.4. "Customer" means anyone who uses user's product. 1.5 "Script" means Python script. 1.6 "User Script" means user owns this script. 1.7 "Other Script" means user doesn't own this script. 1.8 "Mix Str" means a feature of this software to obfuscate string constant in script 1.9 "BCC Mode" means an irreversible obfuscation method, a feature of this software 1.10 "RFT Mode" means an irreversible obfuscation method, a feature of this software 1.11 "Big Script" means script size exceeds a certain value 1.12 "Pyarmor License" means a file issued by licensor to unlock this software limitations 1.13 "Basic License" means a kind of Pyarmor License 1.13 "Pro License" means a kind of Pyarmor License 1.14 "Group License" means a kind of Pyarmor License 1.15 "License No." means a string with format "pyarmor-vax-xxxxxx", "x" stands for a digital, each Pyarmor License has an unique License No. 1.16 "Licensed Product" means product has been registered to one Pyarmor License. 2. License Grants and Conditions -------------------------------- Installing and using this software signifies acceptance of these terms and conditions of the license. If you do not agree with the terms of this license, you must remove all of this software files from your storage devices and cease to use this software. 2.1. Trial Version Limitations This software is published as shareware, free trial version never expires, but there are some limitations. 2.1.1 Can not obfuscate big script 2.1.2 Can not use feature Mix Str 2.1.3 Can not use feature RFT Mode, BCC Mode 2.1.4 Can not be used in any commercial product if the total sale income of this product is larger than 30x license fees 2.1.5 Can not be used to provide obfuscation service in any form 2.2. Grants User purchases Pyarmor License to unlock these limitations except 2.1.5. Licensor issues 3 kind of Pyarmor License. 2.2.1 Pyarmor Basic, unlock limitations 2.1.1, 2.1.2, 2.1.4 2.2.2 Pyarmor Pro, unlock limitations 2.1.1, 2.1.2, 2.1.3, 2.1.4 2.2.3 Pyarmor Group, unlock limitations 2.1.1, 2.1.2, 2.1.3, 2.1.4 Pyarmor Basic and Pyarmor Pro need internet connection to verify, it doesn't work in the device without internet connection. Pyarmor Group need not internet connection. Each Pyarmor License only need pay once, not periodically. 2.3 Conditions 2.3.1 Each Pyarmor License can only be used to register One Product. Each Licensed Product has an unique License No. in global. If user has many products, each product need purchase one Pyarmor License. Except 2.6.1 2.3.2 Pyarmor License could be installed in many machines and devices which used to develop, build, debug, test and support Licensed Product. But there is limitation to be used at the same time. See 2.3.3 2.3.3 Pyarmor Basic and Pro License can only be used in no more than 100 devices in 24 hours. Pyarmor License be used means use any feature of Pyarmor in one machine. Running obfuscated scripts generated by Pyarmor is not considered as Pyarmor License be used. 2.3.4 Pyarmor Basic and Pro License need internet connection to verify. 2.3.5 Pyarmor License could not be installed in customer's devices. 2.3.6 Pyarmor License could not be used to obfuscate any other scripts. 2.3.7 Pyarmor License could not be transferred to other product. 2.4 Special Cases 2.4.1 When product name is changed, but the product features are same, Pyarmor License could be used without changing registration product name. 2.4.2 When organization user is renamed, or acquired by others, only product name is not changed, Pyarmor License need change nothing, and still could be used. But if product name is changed, even product functions are same, Pyarmor License can't be used again. 2.4.3 When product in developing and its name is not defined, the initial registration could use "TBD" as the product name. In this case, product name can be changed once. Before this product is sold, user must change registration name to real product name. 2.5 Modifying Software User could modify Python scripts of this software to meet needs. But this modified software could only be used in Licensed Product, it could not be distributed to others. 2.6 Fair Use This License is not intended to limit any rights users have under applicable copyright doctrines of fair use, fair dealing, or other equivalents. 2.6.1 If user has many products, and has purchased one license for the first product. The second product could use first product license only if sale income of the second product less than 30x license fees. Once greater than 30x license fees, the second product need purchase its own license. It's same to user's other products. 3. Responsibilities and Commitments ----------------------------------- 3.1 This software does nothing except the features described in the software documentation. 3.2 Using Pyarmor Basic and Pro License, this software need internet connection to request authorization. And only the related files of Pyarmor License, serial number of hard disk, Ethernet address, IPv4/IPv6 address, hostname will be sent to remote server for verification. 3.3 Except 3.2, this software does not record and collect any other device information, and need not connect to internet. 3.4 Regarding to obfuscated scripts generated by this software 3.4.1 this software has no any control or limitation to obfuscated scripts, the behaviors of obfuscated scripts are totally defined by user. 3.4.2 License No. and product name will be embedded into obfuscated scripts, user's regname, email and other information are not. 4. Termination -------------- The rights granted under this License will terminate automatically if You fail to comply with any of its terms. 4.1 You issue chargeback after purchased Pyarmor License has been registered to one product. Even chargeback is rejected by bank or user cancels chargeback, this Pyarmor License can't be used again. 4.2 You let others got Pyarmor License intentionally or unintentionally 4.3 You lost Pyarmor License by hacker 4.4 In any cases include 4.2, 4.3, once licensor find too many machines use one Pyarmor License exceeds permission, this Pyarmor License will be ceased, and never could be used again. 4.5 In any cases if licensor finds one Pyarmor License is used to other product, even it's caused by 4.3, this Pyarmor License will be ceased. A notify email will be sent to registration email of this Pyarmor License. 5. Restrictions --------------- You shall not (and shall not allow any third party to): 5.1 decompile, disassemble, or otherwise reverse engineer any binary files of this software; 5.2 distribute, sell, sublicense, rent, lease, or use this software (or any portion thereof) for time sharing, hosting, service provider, or like purposes; 5.3 remove any product identification, proprietary, copyright, or other notices contained in this software; 5.4 copy, modify (except as expressly permitted in this Agreement) or translate any part of this software, create a derivative work of any part of this software, or incorporate this software into or with other software, except to the extent expressly authorized in writing by licensor; 5.5 attempt to circumvent or disable the security key mechanism that protects this software against unauthorized use (except and only to the extent that applicable law prohibits or restricts such restrictions); 6. Disclaimer of Warranty ------------------------- This Software is provided under this License on an "as is" basis, without warranty of any kind, either expressed, implied, or statutory, including, without limitation, warranties that this software is free of defects, fit for a particular purpose or non-infringing. The entire risk as to the quality and performance of this software is with users. Neither the licensor nor the agents of the licensor will be liable for data loss, damages, loss of profits or any other kind of loss while using or misusing this software. This disclaimer of warranty constitutes an essential part of this License. No use of this software is authorized under this License except under this disclaimer. 7. Changes to this Agreement ---------------------------- Licensor reserves the right, at its sole discretion, to modify or replace this Agreement at any time. If a revision is material licensor will provide at least 30 days' notice prior to any new terms taking effect. What constitutes a material change will be determined at the sole discretion of the licensor. By continuing to access or use this software after any revisions become effective, You agree to be bound by the revised terms. If You do not agree to the new terms, You are no longer authorized to use this software. 8. Litigation ------------- Any litigation relating to this License may be brought only in the courts of a jurisdiction where the defendant maintains its principal place of business and such litigation shall be governed by laws of that jurisdiction, without reference to its conflict-of-law provisions. Nothing in this Section shall prevent a party's ability to bring cross-claims or counter-claims. =============================================================================== pyinstaller 5.13.2 (Provided under following license) =============================================================================== ================================ The PyInstaller licensing terms ================================ Copyright (c) 2010-2023, PyInstaller Development Team Copyright (c) 2005-2009, Giovanni Bajo Based on previous work under copyright (c) 2002 McMillan Enterprises, Inc. PyInstaller is licensed under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Bootloader Exception -------------------- In addition to the permissions in the GNU General Public License, the authors give you unlimited permission to link or embed compiled bootloader and related files into combinations with other programs, and to distribute those combinations without any restriction coming from the use of those files. (The General Public License restrictions do apply in other respects; for example, they cover modification of the files, and distribution when not linked into a combined executable.) Bootloader and Related Files ---------------------------- Bootloader and related files are files which are embedded within the final executable. This includes files in directories: ./bootloader/ ./PyInstaller/loader Run-time Hooks ---------------------------- Run-time Hooks are a different kind of files embedded within the final executable. To ease moving them into a separate repository, or into the respective project, these files are now licensed under the Apache License, Version 2.0. Run-time Hooks are in the directory ./PyInstaller/hooks/rthooks The PyInstaller.isolated submodule ---------------------------------- By request, the PyInstaller.isolated submodule and its corresponding tests are additionally licensed with the MIT license so that it may be reused outside of PyInstaller under GPL 2.0 or MIT terms and conditions -- whichever is the most suitable to the recipient downstream project. Affected files/directories are: ./PyInstaller/isolated/ ./tests/unit/test_isolation.py About the PyInstaller Development Team -------------------------------------- The PyInstaller Development Team is the set of contributors to the PyInstaller project. A full list with details is kept in the documentation directory, in the file ``doc/CREDITS.rst``. The core team that coordinates development on GitHub can be found here: https://github.com/pyinstaller/pyinstaller. As of 2021, it consists of: * Hartmut Goebel * Jasper Harrison * Bryan Jones * Brenainn Woodsend * Rok Mandeljc Our Copyright Policy -------------------- PyInstaller uses a shared copyright model. Each contributor maintains copyright over their contributions to PyInstaller. But, it is important to note that these contributions are typically only changes to the repositories. Thus, the PyInstaller source code, in its entirety is not the copyright of any single person or institution. Instead, it is the collective copyright of the entire PyInstaller Development Team. If individual contributors want to maintain a record of what changes/contributions they have specific copyright on, they should indicate their copyright in the commit message of the change, when they commit the change to the PyInstaller repository. With this in mind, the following banner should be used in any source code file to indicate the copyright and license terms: #----------------------------------------------------------------------------- # Copyright (c) 2005-2023, PyInstaller Development Team. # # Distributed under the terms of the GNU General Public License (version 2 # or later) with exception for distributing the bootloader. # # The full license is in the file COPYING.txt, distributed with this software. # # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception) #----------------------------------------------------------------------------- For run-time hooks, the following banner should be used: #----------------------------------------------------------------------------- # Copyright (c) 2005-2023, PyInstaller Development Team. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # # The full license is in the file COPYING.txt, distributed with this software. # # SPDX-License-Identifier: Apache-2.0 #----------------------------------------------------------------------------- ================================ GNU General Public License ================================ https://gnu.org/licenses/gpl-2.0.html GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS ================================ Apache License 2.0 ================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =========== MIT License =========== Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. =============================================================================== rules_boost_630cf5dbad418ee8cfa637b1e33125b11807721d (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================== =============================================================================== libnuma 2.0.14 (Provided under following license) =============================================================================== This package was debianized by Ian Wienand on Wed, 15 Dec 2004. libnuma sources are available from https://github.com/numactl/numactl Upstream Authors: Andi Kleen Copyright (C) 2004 Andi Kleen numactl and the demo programs are under the GNU General Public License, v.2 libnuma is under the GNU Lesser General Public License, v2.1. The manpages are under the same license as the Linux manpages (see the files) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The full text of the License may be found in /usr/share/common-licenses/GPL. The redistribution of portions of this program are controlled by the GNU Lesser General Public License as published by the Free Software Foundation. The full text of the License may be found in /usr/share/common-licenses/LGPL. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Parts of the numademo program are derived from the STREAM benchmark, available from http://www.cs.virginia.edu/stream/ =============================================================================== GitPython (Provided under following license) =============================================================================== Copyright (C) 2008, 2009 Michael Trier and contributors All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the GitPython project nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. =============================================================================== RAPIDS Memory Manager (RMM) (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================== spdlog (Provided under following license) =============================================================================== The MIT License (MIT) Copyright (c) 2016 Gabi Melman. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -- NOTE: Third party dependency used by this software -- This software depends on the fmt lib (MIT License), and users must comply to its license: https://raw.githubusercontent.com/fmtlib/fmt/master/LICENSE =============================================================================== fmt (Provided under following license) =============================================================================== Copyright (c) 2012 - present, Victor Zverovich and {fmt} contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --- Optional exception to the license --- As an exception, if, as a result of your compiling your source code, portions of this Software are embedded into a machine-executable object form of such source code, you may redistribute such embedded portions in such object form without including the above copyright and permission notices. =============================================================================== yq (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================== bazelbuild/bazel-gazelle 0.24.0 (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================== bazelbuild/rules_go 0.24.2 (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================== bazelbuild/rules_docker 0.22.0 (Provided under following license) =============================================================================== Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. =============================================================================== ================================================ FILE: isaac_ros_gxf/package.xml ================================================ isaac_ros_gxf 4.4.0 Isaac ROS GXF Isaac ROS Maintainers NVIDIA Isaac ROS Software License https://developer.nvidia.com/isaac-ros-gems/ CY Chen Swapnesh Wani ament_cmake magic_enum libucx0 nvsci libgnat-23 isaac_ros_common ament_lint_auto ament_lint_common ament_cmake ================================================ FILE: isaac_ros_gxf/src/isaac_ros_gxf.cpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 // Placeholder to allow ament_cmake_lint to not error on no source files. ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_argus/CMakeLists.txt ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.22.1) project(gxf_isaac_argus LANGUAGES C CXX) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() # Determine the architecture if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") if(CMAKE_DEVICE STREQUAL "sbsa") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_aarch64_cuda_13_0") elseif(CMAKE_DEVICE STREQUAL "arm64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_jetpack70") else() message(FATAL_ERROR "Device is not supported.") endif() endif() # Add an interface target to export dependencies add_library(${PROJECT_NAME} INTERFACE) # Install shared library if(EXISTS "${GXF_EXT_LIB_PATH}/lib${PROJECT_NAME}.so") install(FILES "${GXF_EXT_LIB_PATH}/lib${PROJECT_NAME}.so" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/lib") set_property(TARGET ${PROJECT_NAME} PROPERTY INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/lib${PROJECT_NAME}.so" ) endif() # Install headers if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gxf") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/gxf/" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/include") set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include") endif() install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) # Embed versioning information into installed files ament_index_get_resource(ISAAC_ROS_COMMON_CMAKE_PATH isaac_ros_common_cmake_path isaac_ros_common) include("${ISAAC_ROS_COMMON_CMAKE_PATH}/isaac_ros_common-version-info.cmake") generate_version_info(${PROJECT_NAME}) ament_auto_package(INSTALL_TO_SHARE) ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_argus/package.xml ================================================ gxf_isaac_argus 4.4.0 GXF extension containing argus components. Isaac ROS Maintainers Apache-2.0 https://developer.nvidia.com/isaac-ros-gems/ CY Chen ament_cmake_auto isaac_ros_common isaac_ros_gxf ament_lint_auto ament_lint_common ament_cmake ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_atlas/CMakeLists.txt ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.22.1) project(gxf_isaac_atlas LANGUAGES C CXX) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() # Determine the architecture if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") if(CMAKE_DEVICE STREQUAL "sbsa") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_aarch64_cuda_13_0") elseif(CMAKE_DEVICE STREQUAL "arm64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_jetpack70") else() message(FATAL_ERROR "Device is not supported.") endif() elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_x86_64_cuda_13_0") else() message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") endif() # Add an interface target to export dependencies add_library(${PROJECT_NAME} INTERFACE) # Install shared library install(FILES "${GXF_EXT_LIB_PATH}/lib${PROJECT_NAME}.so" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/lib") set_property(TARGET ${PROJECT_NAME} PROPERTY INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/lib${PROJECT_NAME}.so" ) # Install headers if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gxf") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/gxf/" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/include") set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include") endif() install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) # Embed versioning information into installed files ament_index_get_resource(ISAAC_ROS_COMMON_CMAKE_PATH isaac_ros_common_cmake_path isaac_ros_common) include("${ISAAC_ROS_COMMON_CMAKE_PATH}/isaac_ros_common-version-info.cmake") generate_version_info(${PROJECT_NAME}) ament_auto_package(INSTALL_TO_SHARE) ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_atlas/gxf/extensions/atlas/composite_schema_server.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "common/unique_index_map.hpp" #include "gems/composite/schema.hpp" #include "gxf/core/component.hpp" namespace nvidia { namespace isaac { // CompositeSchemaServer is a central repository for storing composite schemas across multiple // components. When a Schema is loaded to the server, the server will then provide an 64 bit key // that is guaranteed to be unique for the lifetime of the CompositeSchemaServer. This allows // components to pass composite messages along with the key, rather than needing to encode the whole // Schema in the message. class CompositeSchemaServer : public gxf::Component { public: gxf_result_t registerInterface(gxf::Registrar* registrar) override; gxf_result_t initialize() override; // Stores a schema into the server and returns a unique ID tied to the schema. gxf::Expected add(const composite::Schema& schema); // Retrieves a schema from the server using the provided unique ID. gxf::Expected get(uint64_t uid) const; // Returns true if the unique index map is at maximum capacity. bool full() const { return (schemas_.size() == schemas_.capacity()); } private: gxf::Parameter maximum_capacity_; // Map of uint64_t to schemas that provides unique keys for every insert. UniqueIndexMap schemas_; // Protect from concurrent read/write access to the schemas_. mutable std::mutex mutex_; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_atlas/gxf/extensions/atlas/pose_tree_frame.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "extensions/gxf_helpers/parameter_parser_isaac.hpp" #include "extensions/gxf_helpers/parameter_wrapper_isaac.hpp" #include "extensions/gxf_helpers/string_provider.hpp" #include "gems/core/math/pose3.hpp" #include "gems/core/optional.hpp" #include "gems/pose_tree/pose_tree.hpp" #include "gxf/core/component.hpp" namespace nvidia { namespace isaac { // Creates a frame in the PoseTree with given name. Optionally sets its pose. Provides methods to // access its name and uid. class PoseTreeFrame : public gxf::Component { public: gxf_result_t registerInterface(gxf::Registrar* registrar) override; gxf_result_t initialize() override; gxf_result_t deinitialize() override; // Returns UID of the frame PoseTree::frame_t frame_uid() const { return frame_uid_; } // Returns name of the frame const char* frame_name() const { return frame_name_string_.c_str(); } // Returns name of the parent frame const char* parent_frame_name() const; // Retursn whether the frame can be moved using interactive markers. bool interactive_marker() const { return interactive_marker_; } private: // Sets up the frame in PoseTree with given parameters, if it has not already. This function can // be called by the initialize() of this component or by the initialize() of other PoseTreeFrame // components, but it executes once per initialization. gxf_result_t setup(); gxf::Parameter frame_name_; gxf::Parameter number_edges_; gxf::Parameter> parent_frame_; gxf::Parameter<::nvidia::isaac::Pose3d> initial_pose_; gxf::Parameter invert_pose_; gxf::Parameter maximum_edge_history_; gxf::Parameter> pose_tree_; gxf::Parameter> namespace_; gxf::Parameter interactive_marker_; // The value returned by setup() function. Cleared at deinitialize(). std::optional setup_result_ = std::nullopt; // Cached values PoseTree::frame_t frame_uid_; std::string frame_name_string_; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_atlas/package.xml ================================================ gxf_isaac_atlas 4.4.0 GXF extension containing environment management components, such as pose tree, map providers, and the composite schema server. Isaac ROS Maintainers Apache-2.0 https://developer.nvidia.com/isaac-ros-gems/ CY Chen ament_cmake_auto isaac_ros_common isaac_ros_gxf gxf_isaac_gems ament_lint_auto ament_lint_common ament_cmake ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_camera_utils/CMakeLists.txt ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.22.1) project(gxf_isaac_camera_utils LANGUAGES C CXX) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() # Dependencies find_package(CUDAToolkit REQUIRED) find_package(Eigen3 3.3 REQUIRED NO_MODULE) find_package(yaml-cpp) # Camera utils extension ament_auto_add_library(${PROJECT_NAME} SHARED gxf/extensions/camera_utils/camera_utils.cpp gxf/extensions/camera_utils/stereo_camera_synchronizer.cpp gxf/extensions/camera_utils/stereo_camera_synchronizer.hpp gxf/extensions/camera_utils/camera_info_synchronizer.cpp gxf/extensions/camera_utils/camera_info_synchronizer.hpp ) target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/gxf") target_link_libraries(${PROJECT_NAME} Eigen3::Eigen yaml-cpp ) set_target_properties(${PROJECT_NAME} PROPERTIES BUILD_WITH_INSTALL_RPATH TRUE BUILD_RPATH_USE_ORIGIN TRUE INSTALL_RPATH_USE_LINK_PATH TRUE ) # Install the binary file install(TARGETS ${PROJECT_NAME} DESTINATION share/${PROJECT_NAME}/gxf/lib) # Embed versioning information into installed files ament_index_get_resource(ISAAC_ROS_COMMON_CMAKE_PATH isaac_ros_common_cmake_path isaac_ros_common) include("${ISAAC_ROS_COMMON_CMAKE_PATH}/isaac_ros_common-version-info.cmake") generate_version_info(${PROJECT_NAME}) ament_auto_package(INSTALL_TO_SHARE) ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_camera_utils/gxf/extensions/camera_utils/camera_info_synchronizer.cpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #include "camera_info_synchronizer.hpp" #include #include #include #include "gxf/core/expected_macro.hpp" #include "gxf/std/timestamp.hpp" namespace nvidia { namespace isaac { namespace { // Global constants that detail sync behavior size_t kSyncOldestOnFastestQueue = 0; size_t kSyncNewestOnSlowestQueue = 1; } // namespace gxf_result_t CameraInfoSynchronization::registerInterface(gxf::Registrar* registrar) { gxf::Expected result; result &= registrar->parameter(camera_message_rx_, "camera_message_rx", "Camera Message receiver", "Camera message receiver handle."); result &= registrar->parameter( camera_info_message_rx_, "camera_info_message_rx", "Camera Info message receiver", "Camera info message receiver handle."); result &= registrar->parameter(camera_message_tx_, "camera_message_tx", "Camera Message transmitter", "Camera message transmitter handle."); result &= registrar->parameter(camera_info_message_tx_, "camera_info_message_tx", "Camera Info message transmitter", "Camera info message transmitter handle."); result &= registrar->parameter(use_latest_camera_info_, "use_latest_camera_info", "Use latest camera info", "Use latest camera info message, make time stamp " "same as image and forward", false); result &= registrar->parameter(drop_old_messages_, "drop_old_messages", "Drop oldest messages inside tick function", "Drop oldest messages inside tick function", false); result &= registrar->parameter( sync_policy_, "sync_policy", "Synchronization policy", "Synchronization policy, 0: choose oldest message from fastest moving queue" "1: choose newest message from slowest moving queue. 0 is good for processing most of the" "data at the cost of being potentially slower than realtime. 1 is good for finding sync" "points close to real time but at the cost of dropping more data.", static_cast(0)); return gxf::ToResultCode(result); } gxf_result_t CameraInfoSynchronization::start() { camera_acq_times_.reserve(camera_message_rx_->capacity()); camera_info_acq_times_.reserve(camera_info_message_rx_->capacity()); return GXF_SUCCESS; } gxf_result_t CameraInfoSynchronization::dropOldestMessagesIfQueueIsFull() { // Clear all queues RETURN_IF_ERROR(camera_message_rx_->sync()); if (camera_message_rx_->size() == camera_message_rx_->capacity()) { // If you see this log, please disable the drop_old_messages parameter and make sure your // GXF node is the first entry point into the Nitros graph. The Nitros graph will force add // a policy 0 on all incoming receivers and will drop messages if the queue is full. // This log is to inform the user that they might be unintentionally dropping messages. GXF_LOG_WARNING("Dropping messages from camera message receiver"); RETURN_IF_ERROR(camera_message_rx_->receive()); } RETURN_IF_ERROR(camera_info_message_rx_->sync()); if (camera_info_message_rx_->size() == camera_info_message_rx_->capacity()) { // If you see this log, please disable the drop_old_messages parameter and make sure your // GXF node is the first entry point into the Nitros graph. The Nitros graph will force add // a policy 0 on all incoming receivers and will drop messages if the queue is full. // This log is to inform the user that they might be unintentionally dropping messages. GXF_LOG_WARNING("Dropping messages from camera info message receiver"); RETURN_IF_ERROR(camera_info_message_rx_->receive()); } return GXF_SUCCESS; } gxf_result_t CameraInfoSynchronization::useLatestCameraInfo() { bool all_messages_available = true; RETURN_IF_ERROR(camera_message_rx_->sync()); if (camera_message_rx_->size() == 0) { GXF_LOG_DEBUG( "Camera message receiver has no messages for synchronization!"); all_messages_available = false; } RETURN_IF_ERROR(camera_info_message_rx_->sync()); if (camera_info_message_rx_->size() == 0) { GXF_LOG_DEBUG( "Camera info message receiver has no messages for synchronization!"); all_messages_available = false; } if (!all_messages_available && drop_old_messages_.get()) { // We do this to keep the graph ticking and not leading to blocks. // To enable no dropping of messages, users are requested to use individual // MessageAvailableSchedulingTerms for each rx. We do not need to do this if used as the first // input in a Nitros node because Nitros adds a policy: 0 to the input rx of the graph // automatically. return dropOldestMessagesIfQueueIsFull(); } else if (!all_messages_available) { // Do not do anything if not all messages are available return GXF_SUCCESS; } gxf::Entity camera_message = UNWRAP_OR_RETURN(camera_message_rx_->receive()); gxf::Entity camera_info_message = UNWRAP_OR_RETURN(camera_info_message_rx_->receive()); // Make camera info timestamp same as camera message auto timestamp_components_cam = camera_message.findAllHeap(); auto acq_time = timestamp_components_cam->front().value()->acqtime; // This will publish the camera and camera info messages with the same // timestamp. This might be required upstream by some codelets camera_message_tx_->publish(camera_message, acq_time); camera_info_message_tx_->publish(camera_info_message, acq_time); return GXF_SUCCESS; } gxf_result_t syncMessages(const std::vector& acq_times, const gxf::Handle& rx, const gxf::Handle& tx, const int64_t candidate_sync_point) { for (size_t index = acq_times.size(); index > 0; index--) { if (acq_times[index-1] == candidate_sync_point) { gxf::Entity message = UNWRAP_OR_RETURN(rx->receive()); RETURN_IF_ERROR(tx->publish(message)); return GXF_SUCCESS; } else if (acq_times[index-1] < candidate_sync_point) { // Old message, drop it RETURN_IF_ERROR(rx->receive()); } else if (acq_times[index-1] > candidate_sync_point) { // This should not happen GXF_LOG_ERROR("Message timestamp is not monotonically increasing"); return GXF_FAILURE; } } GXF_LOG_ERROR("Did not publish anything, should have published"); return GXF_FAILURE; } gxf_result_t CameraInfoSynchronization::tick() { // Clear all queues for processing in this tick call camera_acq_times_.clear(); camera_info_acq_times_.clear(); if (use_latest_camera_info_.get()) { return useLatestCameraInfo(); } // Check if all input queues have messages bool all_messages_available = true; RETURN_IF_ERROR(camera_message_rx_->sync()); RETURN_IF_ERROR(camera_info_message_rx_->sync()); if (camera_message_rx_->size() == 0 || camera_info_message_rx_->size() == 0) { // Not all the inputs have messages, unexpected. GXF_LOG_DEBUG("Not all the inputs have messages for synchronization!"); all_messages_available = false; } if (!all_messages_available && drop_old_messages_.get()) { // Acts as a policy inside the tick function return dropOldestMessagesIfQueueIsFull(); } else if (!all_messages_available) { // Do not do anything if not all messages are available return GXF_SUCCESS; } // Read the timestamps of available messages from camera input for (size_t index = camera_message_rx_->size(); index > 0; index--) { auto msg_result = camera_message_rx_->peek(index - 1); if (msg_result) { auto timestamp_components = msg_result->findAllHeap(); if (!timestamp_components) { return gxf::ToResultCode(timestamp_components); } if (0 == timestamp_components->size()) { GXF_LOG_ERROR("No timestamp found from the camera message"); return GXF_ENTITY_COMPONENT_NOT_FOUND; } camera_acq_times_.push_back( timestamp_components->front().value()->acqtime); } } // Read the timestamps of available messages from camera info input for (size_t index = camera_info_message_rx_->size(); index > 0; index--) { auto msg_result = camera_info_message_rx_->peek(index - 1); if (msg_result) { auto timestamp_components = msg_result->findAllHeap(); if (!timestamp_components) { return gxf::ToResultCode(timestamp_components); } if (0 == timestamp_components->size()) { GXF_LOG_ERROR("No timestamp found from the camera info message"); return GXF_ENTITY_COMPONENT_NOT_FOUND; } camera_info_acq_times_.push_back( timestamp_components->front().value()->acqtime); } } if (camera_acq_times_.size() == 0 || camera_info_acq_times_.size() == 0) { GXF_LOG_ERROR("This array should not be empty at this stage"); return GXF_FAILURE; } int64_t candidate_sync_point = std::numeric_limits::max(); if (sync_policy_.get() == kSyncNewestOnSlowestQueue) { /* Find newest timestamp from slowest moving queue, this makes sure with the messages we have we will find a sync point closest to real time, and not the potential non optimal time chosen by oldest message in fastest moving queue Each timestamps.front() is the newest message from that queue.We pick the minimum of these newest timestamps */ if (!camera_acq_times_.empty() && camera_acq_times_.front() < candidate_sync_point) { candidate_sync_point = camera_acq_times_.front(); } if (!camera_info_acq_times_.empty() && camera_info_acq_times_.front() < candidate_sync_point) { candidate_sync_point = camera_info_acq_times_.front(); } } else if (sync_policy_.get() == kSyncOldestOnFastestQueue) { // find oldest timestamp we're going to pick from the fastest moving queue candidate_sync_point = 0; if (camera_acq_times_.back() > candidate_sync_point) { candidate_sync_point = camera_acq_times_.back(); } if (camera_info_acq_times_.back() > candidate_sync_point) { candidate_sync_point = camera_info_acq_times_.back(); } } bool found_in_camera_queue = false; bool found_in_camera_info_queue = false; for (auto it = camera_acq_times_.begin(); it != camera_acq_times_.end(); it++) { if (*it == candidate_sync_point) { found_in_camera_queue = true; } } for (auto it = camera_info_acq_times_.begin(); it != camera_info_acq_times_.end(); it++) { if (*it == candidate_sync_point) { found_in_camera_info_queue = true; } } if (!found_in_camera_queue || !found_in_camera_info_queue) { GXF_LOG_DEBUG("Did not find candidate sync point in one of the input queues"); return GXF_SUCCESS; } GXF_LOG_DEBUG("Candidate timestamp for syncing (from camera queue): %zd", candidate_sync_point); RETURN_IF_ERROR(syncMessages(camera_info_acq_times_, camera_info_message_rx_, camera_info_message_tx_, candidate_sync_point)); RETURN_IF_ERROR(syncMessages(camera_acq_times_, camera_message_rx_, camera_message_tx_, candidate_sync_point)); return GXF_SUCCESS; } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_camera_utils/gxf/extensions/camera_utils/camera_info_synchronizer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gxf/core/gxf.h" #include "common/assert.hpp" #include "common/type_name.hpp" #include "gxf/core/handle.hpp" #include "gxf/core/parameter_parser_std.hpp" #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace isaac { // A codelet to sync camera messages with camera info messages. It will match the timestamp of a // camera info message with the timestamp of the corresponding camera message. If the parameter // for use_latest_camera_info is set to true, it will use the latest camera info message // It will make sure to update the camera info message with the same timestamp as that of the // camera message class CameraInfoSynchronization : public gxf::Codelet { public: gxf_result_t registerInterface(gxf::Registrar* registrar) override; gxf_result_t start() override; gxf_result_t tick() override; // This function will drop oldest messages from either queues to keep the graph ticking. // It is needed when a user decides to use this codelet with a MultiMessageAvailableScheduling // term. gxf_result_t dropOldestMessagesIfQueueIsFull(); // Gets latest camera info is in the queues and matches it with the image. It will update // timestamp of the camera info message to be the same as that of the camera message. gxf_result_t useLatestCameraInfo(); private: gxf::Parameter> camera_message_rx_; gxf::Parameter> camera_info_message_rx_; gxf::Parameter> camera_message_tx_; gxf::Parameter> camera_info_message_tx_; gxf::Parameter use_latest_camera_info_; gxf::Parameter drop_old_messages_; gxf::Parameter sync_policy_; // These parameters are used to store the timestamps of the camera and camera info messages // These are preallocated in the start function to not have memory access during runtime std::vector camera_acq_times_; std::vector camera_info_acq_times_; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_camera_utils/gxf/extensions/camera_utils/camera_utils.cpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #include "extensions/camera_utils/camera_info_synchronizer.hpp" #include "extensions/camera_utils/stereo_camera_synchronizer.hpp" #include "gxf/std/extension_factory_helper.hpp" GXF_EXT_FACTORY_BEGIN() GXF_EXT_FACTORY_SET_INFO(0xa722f33021690730, 0x8efa17986d37641d, "NvIsaacCameraUtilsExtension", "Extension containing miscellaneous camera utility components", "Isaac SDK", "2.0.0", "LICENSE"); GXF_EXT_FACTORY_ADD(0x8760c3e2306c1ff6, 0xb9f0fb97cef0110f, nvidia::isaac::StereoCameraSynchronizer, nvidia::gxf::Codelet, "Copies timestamp from left input msg to right input msg"); GXF_EXT_FACTORY_ADD(0x8760c3e2306c2ff6, 0xb9f0fb97cef0210f, nvidia::isaac::CameraInfoSynchronization, nvidia::gxf::Codelet, "Synchronizes camera info and camera message, uses cached camera info if " "needed"); GXF_EXT_FACTORY_END() ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_camera_utils/gxf/extensions/camera_utils/stereo_camera_synchronizer.cpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #include "stereo_camera_synchronizer.hpp" #include #include "gems/gxf_helpers/expected_macro_gxf.hpp" #include "gxf/std/timestamp.hpp" namespace nvidia { namespace isaac { gxf_result_t StereoCameraSynchronizer::registerInterface(gxf::Registrar* registrar) { gxf::Expected result; result &= registrar->parameter( rx_right_camera_, "rx_right_camera", "RX Right Camera Message", "Input for Right CameraMessage entities"); result &= registrar->parameter( rx_left_camera_, "rx_left_camera", "RX Left Camera Message", "Input for Left CameraMessage entities"); result &= registrar->parameter( tx_right_camera_, "tx_right_camera", "TX Right Camera Message", "Input for Right CameraMessage entities"); result &= registrar->parameter( tx_left_camera_, "tx_left_camera", "TX Left Camera Message", "Input for Left CameraMessage entities"); result &= registrar->parameter( max_timestamp_diff_, "max_timestamp_diff", "Max difference timestamps nanoseconds", "Max difference between timestamps in nanoseconds", static_cast(200000)); // 200 micro seconds return gxf::ToResultCode(result); } gxf_result_t StereoCameraSynchronizer::start() { // Set all previous timestamps to minimum value of int64_t // This ensures that the first message received does NOT trigger the // "not monotonically increasing" error prev_left_unnamed_timestamp_ = std::numeric_limits::min(); prev_right_unnamed_timestamp_ = std::numeric_limits::min(); prev_left_named_timestamp_ = std::numeric_limits::min(); prev_right_named_timestamp_ = std::numeric_limits::min(); return GXF_SUCCESS; } gxf_result_t StereoCameraSynchronizer::tick() { auto left_camera_entity = UNWRAP_OR_RETURN(rx_left_camera_->receive()); auto right_camera_entity = UNWRAP_OR_RETURN(rx_right_camera_->receive()); auto left_unnamed_timestamp = UNWRAP_OR_RETURN(left_camera_entity.get()); auto right_unnamed_timestamp = UNWRAP_OR_RETURN(right_camera_entity.get()); auto left_named_timestamp = UNWRAP_OR_RETURN(left_camera_entity.get("timestamp")); auto right_named_timestamp = UNWRAP_OR_RETURN( right_camera_entity.get("timestamp")); const int64_t unnamed_diff = std::abs(left_unnamed_timestamp->acqtime - right_unnamed_timestamp->acqtime); if (unnamed_diff > max_timestamp_diff_) { GXF_LOG_ERROR("L/R frames are not synchronized, unnamed timestamp diff = %ld ns", unnamed_diff); return GXF_FAILURE; } const int64_t named_diff = std::abs(left_named_timestamp->acqtime - right_named_timestamp->acqtime); if (named_diff > max_timestamp_diff_) { GXF_LOG_ERROR("L/R frames are not synchronized, named timestamp diff = %ld ns", named_diff); return GXF_FAILURE; } // Set right input timestamp to left input timestamp right_unnamed_timestamp->acqtime = left_unnamed_timestamp->acqtime; right_named_timestamp->acqtime = left_named_timestamp->acqtime; // Check if previous timestamp is lower than current timestamp if (prev_left_unnamed_timestamp_ > left_unnamed_timestamp->acqtime) { GXF_LOG_ERROR("Left unnamed timestamp is not monotonically increasing"); return GXF_FAILURE; } if (prev_right_unnamed_timestamp_ > right_unnamed_timestamp->acqtime) { GXF_LOG_ERROR("Right unnamed timestamp is not monotonically increasing"); return GXF_FAILURE; } if (prev_left_named_timestamp_ > left_named_timestamp->acqtime) { GXF_LOG_ERROR("Left named timestamp is not monotonically increasing"); return GXF_FAILURE; } if (prev_right_named_timestamp_ > right_named_timestamp->acqtime) { GXF_LOG_ERROR("Right named timestamp is not monotonically increasing"); return GXF_FAILURE; } prev_left_unnamed_timestamp_ = left_unnamed_timestamp->acqtime; prev_right_unnamed_timestamp_ = right_unnamed_timestamp->acqtime; prev_left_named_timestamp_ = left_named_timestamp->acqtime; prev_right_named_timestamp_ = right_named_timestamp->acqtime; RETURN_IF_ERROR(tx_left_camera_->publish(left_camera_entity)); RETURN_IF_ERROR(tx_right_camera_->publish(right_camera_entity)); return GXF_SUCCESS; } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_camera_utils/gxf/extensions/camera_utils/stereo_camera_synchronizer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gxf/std/codelet.hpp" #include "gxf/std/receiver.hpp" #include "gxf/std/transmitter.hpp" namespace nvidia { namespace isaac { // This codelet checks if stereo frames timestamps are within a tolerance and // will edit the right input timestamps to match the left input timestamp // Some downstream applications expect matched stereo frames to have exactly the same timestamp // even though in reality matched frames can differ by a few microseconds. class StereoCameraSynchronizer : public gxf::Codelet { gxf_result_t registerInterface(gxf::Registrar* registrar) override; gxf_result_t start() override; gxf_result_t tick() override; gxf_result_t stop() override { return GXF_SUCCESS; } private: gxf::Parameter> rx_right_camera_; gxf::Parameter> rx_left_camera_; gxf::Parameter> tx_right_camera_; gxf::Parameter> tx_left_camera_; gxf::Parameter max_timestamp_diff_; int64_t prev_left_unnamed_timestamp_, prev_right_unnamed_timestamp_; int64_t prev_left_named_timestamp_, prev_right_named_timestamp_; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_camera_utils/package.xml ================================================ gxf_isaac_camera_utils 4.4.0 NvIsaacCameraUtilsExtension Isaac ROS Maintainers Apache-2.0 https://developer.nvidia.com/isaac-ros-gems/ CY Chen ament_cmake_auto isaac_ros_common isaac_ros_gxf gxf_isaac_messages gxf_isaac_tensorops isaac-ros-cli tensorrt gxf_isaac_gems ament_lint_auto ament_lint_common ament_cmake ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_cuda/CMakeLists.txt ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.22.1) project(gxf_isaac_cuda LANGUAGES C CXX) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() # Determine the architecture if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") if(CMAKE_DEVICE STREQUAL "sbsa") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_aarch64_cuda_13_0") elseif(CMAKE_DEVICE STREQUAL "arm64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_jetpack70") else() message(FATAL_ERROR "Device is not supported.") endif() elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_x86_64_cuda_13_0") else() message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") endif() # Add an interface target to export dependencies add_library(${PROJECT_NAME} INTERFACE) # Install shared library install(FILES "${GXF_EXT_LIB_PATH}/lib${PROJECT_NAME}.so" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/lib") set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/lib${PROJECT_NAME}.so" ) # Install headers if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gxf") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/gxf/" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/include") set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include") endif() install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) # Embed versioning information into installed files ament_index_get_resource(ISAAC_ROS_COMMON_CMAKE_PATH isaac_ros_common_cmake_path isaac_ros_common) include("${ISAAC_ROS_COMMON_CMAKE_PATH}/isaac_ros_common-version-info.cmake") generate_version_info(${PROJECT_NAME}) ament_auto_package(INSTALL_TO_SHARE) ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_cuda/package.xml ================================================ gxf_isaac_cuda 4.4.0 GXF extension for Cuda related components in GXF Core. Isaac ROS Maintainers Apache-2.0 https://developer.nvidia.com/isaac-ros-gems/ CY Chen ament_cmake_auto isaac_ros_common isaac_ros_gxf ament_lint_auto ament_lint_common ament_cmake ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_flatscan_localization/CMakeLists.txt ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.22.1) project(gxf_isaac_flatscan_localization LANGUAGES C CXX) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() # Determine the architecture if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") if(CMAKE_DEVICE STREQUAL "sbsa") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_aarch64_cuda_13_0") elseif(CMAKE_DEVICE STREQUAL "arm64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_jetpack70") else() message(FATAL_ERROR "Device is not supported.") endif() elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_x86_64_cuda_13_0") else() message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") endif() # Add an interface target to export dependencies add_library(${PROJECT_NAME} INTERFACE) # Install shared library install(FILES "${GXF_EXT_LIB_PATH}/lib${PROJECT_NAME}.so" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/lib") set_property(TARGET ${PROJECT_NAME} PROPERTY INTERFACE_LINK_LIBRARIES "$/share/${PROJECT_NAME}/gxf/lib/lib${PROJECT_NAME}.so" ) # Install headers if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gxf") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/gxf/" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/include") set_target_properties(${PROJECT_NAME} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "$/share/${PROJECT_NAME}/gxf/include") endif() install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) # Embed versioning information into installed files ament_index_get_resource(ISAAC_ROS_COMMON_CMAKE_PATH isaac_ros_common_cmake_path isaac_ros_common) include("${ISAAC_ROS_COMMON_CMAKE_PATH}/isaac_ros_common-version-info.cmake") generate_version_info(${PROJECT_NAME}) ament_auto_package(INSTALL_TO_SHARE) ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_flatscan_localization/package.xml ================================================ gxf_isaac_flatscan_localization 4.4.0 Extension containing flatscan localization related components. Isaac ROS Maintainers Apache-2.0 https://developer.nvidia.com/isaac-ros-gems/ CY Chen ament_cmake_auto isaac_ros_common isaac_ros_gxf ament_lint_auto ament_lint_common ament_cmake ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/CMakeLists.txt ================================================ # SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES # Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # SPDX-License-Identifier: Apache-2.0 cmake_minimum_required(VERSION 3.22.1) project(gxf_isaac_gems LANGUAGES C CXX) if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") add_compile_options(-Wall -Wextra -Wpedantic) endif() find_package(ament_cmake_auto REQUIRED) ament_auto_find_build_dependencies() find_package(Eigen3 3.3 REQUIRED NO_MODULE) # Determine the architecture if(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_jetpack70") elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64") set(GXF_EXT_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/lib/gxf_x86_64_cuda_13_0") else() message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") endif() # Add an interface target to export dependencies add_library(${PROJECT_NAME} INTERFACE) # Install headers if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gxf") install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/gxf/" DESTINATION "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}/gxf/include") set_property(TARGET ${PROJECT_NAME} PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${EIGEN3_INCLUDE_DIR}" "$/share/${PROJECT_NAME}/gxf/include" ) endif() install(TARGETS ${PROJECT_NAME} EXPORT export_${PROJECT_NAME} LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin) ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET) # Embed versioning information into installed files ament_index_get_resource(ISAAC_ROS_COMMON_CMAKE_PATH isaac_ros_common_cmake_path isaac_ros_common) include("${ISAAC_ROS_COMMON_CMAKE_PATH}/isaac_ros_common-version-info.cmake") generate_version_info(${PROJECT_NAME}) ament_auto_package(INSTALL_TO_SHARE) ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/algorithm/string_utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include namespace nvidia { namespace isaac { // Checks wether a string starts with a certain string inline bool StartsWith(const std::string& str, const std::string& prefix) { return str.size() >= prefix.size() && str.compare(0, prefix.size(), prefix) == 0; } // Checks wether a string ends with a certain string inline bool EndsWith(const std::string& str, const std::string& suffix) { return str.size() >= suffix.size() && str.compare(str.size() - suffix.size(), suffix.size(), suffix) == 0; } // Creates a random alpha-numeric string template std::string RandomAlphaNumeric(size_t length, URBG&& rng) { // All alpha numeric characters constexpr char kAlphaNumeric[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "abcdefghijklmnopqrstuvwxyz" "0123456789"; std::uniform_int_distribution random_index(0, sizeof(kAlphaNumeric) - 1); std::string result(length, 0); std::generate_n(result.begin(), length, [&]() { return kAlphaNumeric[random_index(rng)]; }); return result; } // Splits a string by deliminator character inline std::vector SplitString(const std::string& str, const char delim) { std::vector result; std::stringstream ss(str); std::string item; while (!std::getline(ss, item, delim).fail()) { result.push_back(item); } return result; } // Converts a string to lower-case characters inline std::string ToLowerCase(std::string data) { std::transform(data.begin(), data.end(), data.begin(), ::tolower); return data; } // Trims the spaces at the beginning and end of string inline std::string TrimString(std::string s) { s.erase(s.begin(), find_if(s.begin(), s.end(), [](int ch) { return !std::isspace(ch); })); s.erase(find_if(s.rbegin(), s.rend(), [](int ch) { return !std::isspace(ch); }).base(), s.end()); return s; } // Returns a new string containing the last count characters of a string inline std::string TakeLast(const std::string& str, size_t count) { if (str.length() <= count) { return str; } else { if (count < 2) { return str.substr(str.length() - count, count); } else { return ".." + str.substr(str.length() - count + 2, count - 2); } } } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/common/composite_schema_uid.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include namespace nvidia { namespace isaac { // Composite schema identification for the data in a message. struct CompositeSchemaUid { // Unique identifier of the composite schema which is used to represent the data uint64_t uid; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/common/pose_frame_uid.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include namespace nvidia { namespace isaac { // Spatial information for the data in a message. struct PoseFrameUid { // Unique identifier of the pose tree frame to which this data is attached. uint64_t uid; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/composite/composite_from_tensor.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/composite/composite_view.hpp" #include "gems/composite/schema_tensor_archive.hpp" #include "gems/core/tensor/tensor.hpp" #include "gxf/core/expected.hpp" namespace nvidia { namespace isaac { namespace from_tensor_details { // Check to see if we actually derive from a composite view std::false_type composite_view_match(const void*); template std::true_type composite_view_match(const CompositeContainerConstPointer*); template std::true_type composite_view_match(const CompositeContainerPointer*); // Check to see if we actually derive from a composite view std::false_type composite_data_match(const void*); template std::true_type composite_data_match(const CompositeContainerArray*); template std::true_type composite_data_match(const CompositeContainerEigen*); // Define helper types. template using is_composite_view = decltype(composite_view_match(std::declval())); template using is_composite_data = decltype(composite_data_match(std::declval())); } // namespace from_tensor_details // Constructs CompositeConstView from TensorConstView template gxf::Expected CompositeFromTensor( ::nvidia::isaac::CpuTensorConstView tensor) { static_assert(from_tensor_details::is_composite_view::value, "Type needs to be a composite"); if (tensor.dimensions()[0] != T::kDimension) { return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } T derived; derived.pointer = tensor.element_wise_begin(); return derived; } // Constructs CompositeView or CompositeConstView from TensorView template gxf::Expected CompositeFromTensor( ::nvidia::isaac::CpuTensorView tensor) { static_assert(from_tensor_details::is_composite_view::value, "Type needs to be a composite"); if (tensor.dimensions()[0] != T::kDimension) { return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } T derived; derived.pointer = tensor.element_wise_begin(); return derived; } // Constructs CompositeView or CompositeConstView from Tensor template gxf::Expected CompositeFromTensor(::nvidia::isaac::CpuTensor& tensor) { return CompositeFromTensor(tensor.view()); } // Constructs CompositeArray or CompositeEigen from TensorConstView and schemas template gxf::Expected CompositeFromTensor( ::nvidia::isaac::CpuTensorConstView tensor, const composite::Schema& tensor_schema, const composite::Schema& composite_schema) { static_assert(from_tensor_details::is_composite_data::value, "Type must be a composite data " "container, since we cannot guarantee parameter order"); const auto maybe_index_map = CompositeIndexMap::Create(composite_schema, tensor_schema); if (!maybe_index_map) { return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } T derived; FromSchemaTensor(tensor, *maybe_index_map, derived); return derived; } // Constructs CompositeArray or CompositeEigen from Tensor and schemas template gxf::Expected CompositeFromTensor(::nvidia::isaac::CpuTensor& tensor, const composite::Schema& tensor_schema, const composite::Schema& composite_schema) { return CompositeFromTensor(tensor.const_view(), tensor_schema, composite_schema); } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/composite/composite_view.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { // Forward declare for operator= template struct CompositeContainerConstPointer; template struct CompositeContainerPointer; template struct CompositeContainerArray; template struct CompositeContainerEigen; // A base class for an immutable composite view which uses a const pointer to access data. template struct CompositeContainerConstPointer { CompositeContainerConstPointer() : pointer(nullptr) {} CompositeContainerConstPointer(const K* p) : pointer(p) {} static_assert(std::is_arithmetic::value, "Composite only supports arithmetic types"); using scalar_t = K; using Scalar = K; static constexpr int32_t kDimension = N; constexpr int32_t size() const { return N; } K operator[](int32_t i) const { return pointer[i]; } const K* pointer; }; // Accesses an element in a composite template K get(const CompositeContainerConstPointer& state) { static_assert(0 <= I && I < N, "Index out of bounds"); return state.pointer[I]; } // A base class for a mutable composite view which uses a pointer to access data. template struct CompositeContainerPointer { CompositeContainerPointer() : pointer(nullptr) {} CompositeContainerPointer(K* p) : pointer(p) {} static_assert(std::is_arithmetic::value, "Composite only supports arithmetic types"); using scalar_t = K; using Scalar = K; static constexpr int32_t kDimension = N; constexpr int32_t size() const { return N; } K operator[](int32_t i) const { return pointer[i]; } K& operator[](int32_t i) { return pointer[i]; } CompositeContainerPointer& operator=(const CompositeContainerConstPointer& other) { for (int32_t i = 0; i < size(); ++i) { pointer[i] = other[i]; } return *this; } CompositeContainerPointer& operator=(const CompositeContainerArray& other) { for (int32_t i = 0; i < size(); ++i) { pointer[i] = other[i]; } return *this; } CompositeContainerPointer& operator=(const CompositeContainerEigen& other) { for (int32_t i = 0; i < size(); ++i) { pointer[i] = other[i]; } return *this; } K* pointer; }; // Accesses an element in a composite template K get(const CompositeContainerPointer& state) { static_assert(0 <= I && I < N, "Index out of bounds"); return state.pointer[I]; } // Accesses an element in a composite template K& get(CompositeContainerPointer& state) { static_assert(0 <= I && I < N, "Index out of bounds"); return state.pointer[I]; } // A base class for a composite which uses std::array to store data. template struct CompositeContainerArray { static_assert(std::is_arithmetic::value, "Composite only supports arithmetic types"); using scalar_t = K; using Scalar = K; static constexpr int32_t kDimension = N; constexpr int32_t size() const { return N; } K operator[](int32_t i) const { return data[i]; } K& operator[](int32_t i) { return data[i]; } CompositeContainerArray& operator=(const CompositeContainerConstPointer& other) { for (int32_t i = 0; i < size(); ++i) { data[i] = other[i]; } return *this; } CompositeContainerArray& operator=(const CompositeContainerPointer& other) { for (int32_t i = 0; i < size(); ++i) { data[i] = other[i]; } return *this; } std::array data; }; // A base class for a composite which uses ::nvidia::isaac::Vector to store data. template struct CompositeContainerEigen { static_assert(std::is_arithmetic::value, "Composite only supports arithmetic types"); using scalar_t = K; using Scalar = K; static constexpr int32_t kDimension = N; constexpr int32_t size() const { return N; } K operator[](int32_t i) const { return elements[i]; } K& operator[](int32_t i) { return elements[i]; } CompositeContainerEigen& operator=(const CompositeContainerConstPointer& other) { for (int32_t i = 0; i < size(); ++i) { elements[i] = other[i]; } return *this; } CompositeContainerEigen& operator=(const CompositeContainerPointer& other) { for (int32_t i = 0; i < size(); ++i) { elements[i] = other[i]; } return *this; } ::nvidia::isaac::Vector elements; }; // Accesses an element in a composite template K get(const CompositeContainerArray& state) { return std::get(state.data); } // Accesses an element in a composite template K& get(CompositeContainerArray& state) { return std::get(state.data); } // Accesses an element in a composite template K get(const CompositeContainerEigen& state) { return state.elements[I]; } // Accesses an element in a composite template K& get(CompositeContainerEigen& state) { return state.elements[I]; } // An immutable composite view template typename ImmutableInterface> using CompositeConstView = ImmutableInterface>; // A mutable composite view template typename MutableInterface> using CompositeView = MutableInterface>; // A composite which owns its data template typename MutableInterface> using Composite = MutableInterface>; // A composite which owns its data as an Eigen Vector template typename MutableInterface> using CompositeEigen = MutableInterface>; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/composite/measure.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once namespace nvidia { namespace isaac { namespace composite { // Possible measure for an entity in Composite Message enum class Measure { kNone, // Unknown kTime, // Second kMass, // Kilogram kPosition, // Meter kSpeed, // Meter per second kAcceleration, // Meter per squared second kRotation, // Rotation of 2d or 3d kAngularSpeed, // Radian per second kAngularAcceleration, // Radian per squared second kNormal, // A normal kColor, // A color kCurvature, // Radian per meter kCurvatureDerivative, // Radian per squared meter }; } // namespace composite } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/composite/quantity.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/composite/measure.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { namespace composite { // A quantity describes meta data for values stored in a composite. struct Quantity { // Helper function to create a scalar quantity static Quantity Scalar(std::string entity, Measure measure) { return Quantity{std::move(entity), measure, ::nvidia::isaac::VectorXi::Constant(1, 1)}; } // Helper function to create a vector quantity static Quantity Vector(std::string entity, Measure measure, int dimension) { return Quantity{std::move(entity), measure, ::nvidia::isaac::VectorXi::Constant(1, dimension)}; } // Equality operator bool operator==(const Quantity& other) const { return measure == other.measure && entity == other.entity && dimensions == other.dimensions; } // Total number of elements int getElementCount() const { return dimensions.prod(); } // The name of the entity for which the values was measured. Multiple quantities can be // measured per entity. std::string entity; // The measure, e.g. unit or type, of the value. Measure measure; // The dimensions of the value. Values can be multi-dimensional but most are scalars or vectors. ::nvidia::isaac::VectorXi dimensions; }; // Exact comparison of quantities struct QuantityEquality { bool operator()(const Quantity& lhs, const Quantity& rhs) const { return lhs == rhs; } }; // Hash function for quantities using combination of hashes on elements struct QuantityHash { std::size_t operator()(const Quantity& value) const { return std::hash{}.operator()(value.entity) ^ std::hash{}.operator()(static_cast(value.measure)) ^ std::hash{}.operator()(static_cast(value.dimensions.size())); } }; } // namespace composite } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/composite/schema.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include "gems/composite/quantity.hpp" #include "gems/core/math/types.hpp" #include "gems/core/optional.hpp" namespace nvidia { namespace isaac { namespace composite { // A schema contains information about the quantities which are stored in the composite class Schema { public: // Constructs schema from given quanties static std::optional Create(std::vector&& quantities, std::string hash = ""); // Constructs schema from scalar quantities of identical measure static std::optional Create( const std::vector& entities, const Measure measure); // Similar to `Create` but will Assert if schema is invalid Schema(std::vector&& quantities, std::string hash = ""); // Similar to `Create` but will Assert if schema is invalid Schema(const std::vector& entities, const Measure measure); // Empty schema Schema() = default; // Equality operator bool operator==(const Schema& other) const { return element_count_ == other.element_count_ && hash_ == other.hash_ && quantities_ == other.quantities_; } // The hash of the schame const std::string& getHash() const { return hash_; } // Returns a list of all quantities const std::vector& getQuantities() const { return quantities_; } // Total number of values required to store the schema int getElementCount() const { return element_count_; } // Gets the starting index of a quantity in the list ofvalues. Returns nullopt if quantity is // not in the schema. std::optional findQuantityValueIndex(const Quantity& quantity) const; private: // Updates `element_count_`, `values_offset_` and `index_` variables based on quantities. bool createIndex(); // The hash of the currently used schema std::string hash_; // All quantities which are part of this schema std::vector quantities_; // Total number of elements in the schema int element_count_ = 0; // Indies of first quantity element in the values vector std::unordered_map index_; }; } // namespace composite } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/composite/schema_tensor_archive.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "common/expected.hpp" #include "gems/composite/schema.hpp" #include "gems/core/tensor/tensor.hpp" namespace nvidia { namespace isaac { // An index map which can be used to map indices from one composite to another. class CompositeIndexMap { public: // Error codes used by this data type enum struct Error { kQuantityNotFound, // A quantity from the target schema was not found in the source schema. }; // Computes an index map which can be used to associate elements in the target schema with // elements in the source schema. Will fail in case the mapping is not possible. static Expected Create(const composite::Schema& source, const composite::Schema& target); // Map a target index to the corresponding source index (see ComputeCompositeIndexMap) int32_t operator()(int32_t target) const { return indices_[target]; } private: // Private constructor to force initialization through static builder for RAII. CompositeIndexMap(int size) : indices_(size) {} // Stores the source index for each target index. // FIXME Use a stack allocated, bounded data type once available. std::vector indices_; }; // Helper type to encode a composite into a tensor template struct TensorArchiveEncoder { // Writes a value into the tensor at the given index. void operator()(int32_t index, K value) { composite_tensor(index) = value; } // The encoder writes data to this tensor. ::nvidia::isaac::CpuTensorView1 composite_tensor; }; // Helper type to decode a composite from a tensor with the help of an index map template struct TensorArchiveDecoder { // Reads a value from the tensor using an index from the *target* schema. The index map is used // to map target schema indices to indices used to access the tensor. void operator()(int32_t index, K& value) { value = composite_tensor(composite_index_map(index)); } // The decoder reads data from this tensor. ::nvidia::isaac::CpuTensorConstView1 composite_tensor; // An index map which is used to map indices given to `operator()` to the correct location in // the tensor. CompositeIndexMap composite_index_map; }; // Reads a composite state from a tensor template void FromSchemaTensor( ::nvidia::isaac::CpuTensorConstView1 composite_tensor, const CompositeIndexMap& composite_index_map, State& state) { TensorArchiveDecoder decoder{composite_tensor, composite_index_map}; for (int32_t i = 0; i < state.size(); i++) { decoder(i, state[i]); } } // Writes a composite state to a tensor template void ToSchemaTensor(const State& state, ::nvidia::isaac::CpuTensorView1 composite_tensor) { TensorArchiveEncoder encoder{composite_tensor}; for (int32_t i = 0; i < state.size(); i++) { encoder(i, state[i]); } } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/coms/socket.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include #include #include #include #include #include #include #include "gems/core/logger.hpp" namespace nvidia { namespace isaac { class Socket { public: // Creates a UDP receiving socket // Remote address corresponds to the sending socket. Port will be used for remote and local port static Socket* CreateRxUDPSocket(const std::string& remote_address, uint16_t port) { Socket* s = new Socket(remote_address, port, SOCK_DGRAM); memset(&s->local_address_, 0, sizeof(s->local_address_)); s->local_address_.sin_port = htons(port); s->local_address_.sin_family = AF_INET; s->local_address_.sin_addr.s_addr = htonl(INADDR_ANY); return s; } // Creates a TCP receiving socket static Socket* CreateRxTCPSocket(const std::string& source_address, uint16_t source_port) { return new Socket(source_address, source_port, SOCK_STREAM); } // Try to start a socket or fails and return -1 int32_t startSocket() { int32_t res = 0; // TODO Assert if (type_ == SOCK_STREAM) { res = connect(sockfd_, (struct sockaddr *)&emitter_address_, sizeof(emitter_address_)); LOG_WARNING("Never tested"); // Set reading options read_flags_ = MSG_PEEK | MSG_WAITALL; } else if (type_ == SOCK_DGRAM) { uint32_t reuse = 1; // Set Reuse Option struct timeval tv; tv.tv_sec = 1; tv.tv_usec = 0; res |= setsockopt(sockfd_, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); res |= setsockopt(sockfd_, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(uint32_t)); if (res < 0) { LOG_ERROR("Cannot set Socket options"); } if (bind(sockfd_, (struct sockaddr *)&local_address_, sizeof(local_address_)) == -1) { LOG_ERROR("Cannot bind!"); return -1; } read_flags_ = 0; } is_running_ = true; return res; } // Reads a packet size_t readPacket(char* data, size_t size) { if (!sockfd_) { LOG_ERROR("Socket is invalid, reopen the connection!"); return -1; } socklen_t slen = sizeof(emitter_address_); int32_t recvlen = recvfrom(sockfd_, data, size, 0, (struct sockaddr *)&emitter_address_, &slen); return recvlen; } // Reads a packet from size_t writePacket(const void* data, size_t size) { if (!sockfd_) { LOG_ERROR("Socket is invalid, reopen the connection!"); return -1; } socklen_t slen = sizeof(emitter_address_); int32_t recvlen = sendto(sockfd_, data, size, 0, (struct sockaddr *)&emitter_address_, slen); return recvlen; } // Closes socket void closeSocket() { if (sockfd_) { close(sockfd_); } is_running_ = false; } bool isRunning() { return is_running_; } // Identify the (externally exposed) IPv4 address corresponding to this communication socket. uint32_t getIpv4() const { uint32_t local_ipv4_address(0); // For each connected IPv4 network interface address, if the emitter address meets masking // requirement, we found our local IPv4. Don't bother checking if the socket is not running. struct ifaddrs* network_interface_addresses = nullptr; if (getifaddrs(&network_interface_addresses) != -1) { struct ifaddrs* network_interface_addresses_iterator = network_interface_addresses; while (network_interface_addresses_iterator != nullptr) { // Validate the socket family is indeed IPv4. if ((network_interface_addresses_iterator->ifa_addr != nullptr) && (network_interface_addresses_iterator->ifa_addr->sa_family == AF_INET)) { // Validate the socket is actually connected. struct sockaddr_in* local_socket_address = (struct sockaddr_in*)network_interface_addresses_iterator->ifa_addr; if (local_socket_address->sin_addr.s_addr != htonl(INADDR_ANY)) { // Validate the network masking requirements meets our emitter address. struct sockaddr_in* ifu_netmask = (struct sockaddr_in*)network_interface_addresses_iterator->ifa_netmask; if ((local_socket_address->sin_addr.s_addr & ifu_netmask->sin_addr.s_addr) == (emitter_address_.sin_addr.s_addr & ifu_netmask->sin_addr.s_addr)) { local_ipv4_address = local_socket_address->sin_addr.s_addr; break; } } } network_interface_addresses_iterator = network_interface_addresses_iterator->ifa_next; } if (network_interface_addresses) { freeifaddrs(network_interface_addresses); } } return local_ipv4_address; } int32_t getFileDescriptor() const { return sockfd_; } private: int32_t sockfd_; struct sockaddr_in local_address_; struct sockaddr_in emitter_address_; int32_t read_flags_; int32_t type_; bool is_running_; Socket(const std::string& remote_address, uint16_t remote_port, uint16_t type, const std::string& interface = "") { // Prepares for incoming data memset(&emitter_address_, 0, sizeof(emitter_address_)); emitter_address_.sin_port = htons(remote_port); emitter_address_.sin_family = AF_INET; emitter_address_.sin_addr.s_addr = inet_addr(remote_address.c_str()); type_ = type; is_running_ = false; // Creates the socket sockfd_ = socket(AF_INET, type, 0); if (!interface.empty()) { struct ifreq if_bind; strncpy(if_bind.ifr_name, interface.c_str(), IFNAMSIZ); const int error = setsockopt(sockfd_, SOL_SOCKET, SO_BINDTODEVICE, reinterpret_cast(&if_bind), sizeof(if_bind)); if (error < 0) { LOG_ERROR("Failed to specify interface %s", interface.c_str()); } } } }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/control_types/differential_drive.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/composite/composite_view.hpp" #include "gems/composite/schema.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { // Describes the full 2D pose and kinematic state of a Differential base struct DifferentialBaseEgoMotionIndices { enum { // Cartesian position X (m) kPositionX, // Cartesian position Y (m) kPositionY, // In-plane rotation angle (radian) kHeading, // Linear (longitudinal) speed (m/s) kLinearSpeed, // Rotation speed (radian/s) kAngularSpeed, // Linear (longitudinal) acceleration (m/s^2) kLinearAcceleration, // Angular (rotaion) acceleration (radians/s^2) kAngularAcceleration, kSize }; }; inline composite::Schema DifferentialBaseEgoMotionCompositeSchema() { return composite::Schema({ composite::Quantity::Vector("position", composite::Measure::kPosition, 2), composite::Quantity::Scalar("heading", composite::Measure::kRotation), composite::Quantity::Scalar("linear_speed", composite::Measure::kSpeed), composite::Quantity::Scalar("angular_speed", composite::Measure::kAngularSpeed), composite::Quantity::Scalar("linear_acceleration", composite::Measure::kAcceleration), composite::Quantity::Scalar("angular_acceleration", composite::Measure::kAngularAcceleration), }); } template struct DifferentialBaseEgoMotionImmutableInterface : public Base { using Base::operator=; using Vector2ConstMap = Eigen::Map< const ::nvidia::isaac::Vector2, 0, Eigen::InnerStride>; K position_x() const { return get(*this); } K position_y() const { return get(*this); } K heading() const { return get(*this); } K linear_speed() const { return get(*this); } K angular_speed() const { return get(*this); } K linear_acceleration() const { return get(*this); } K angular_acceleration() const { return get(*this); } Vector2ConstMap position() const { return Vector2ConstMap(this->pointer + DifferentialBaseEgoMotionIndices::kPositionX); } }; template struct DifferentialBaseEgoMotionMutableInterface : public DifferentialBaseEgoMotionImmutableInterface { using DifferentialBaseEgoMotionImmutableInterface::operator=; using Vector2Map = Eigen::Map<::nvidia::isaac::Vector2, 0, Eigen::InnerStride>; K position_x() const { return get(*this); } K position_y() const { return get(*this); } K heading() const { return get(*this); } K angular_speed() const { return get(*this); } K linear_speed() const { return get(*this); } K angular_acceleration() const { return get(*this); } K linear_acceleration() const { return get(*this); } K& position_x() { return get(*this); } K& position_y() { return get(*this); } K& heading() { return get(*this); } K& angular_speed() { return get(*this); } K& linear_speed() { return get(*this); } K& angular_acceleration() { return get(*this); } K& linear_acceleration() { return get(*this); } Vector2Map position() { return Vector2Map(&position_x()); } }; template using DifferentialBaseEgoMotionConstView = CompositeConstView; template using DifferentialBaseEgoMotionView = CompositeView; template using DifferentialBaseEgoMotion = Composite; template using DifferentialBaseEgoMotionEigen = CompositeEigen; // Describes the command type for a Differential base, ie. output of a controller and intput to the // hardware driver struct DifferentialBaseCommandIndices { enum { // Linear (longitudinal) speed (m/s) kLinearSpeed, // Rotation speed (radian/s) kAngularSpeed, kSize }; }; inline composite::Schema DifferentialBaseCommandCompositeSchema() { return composite::Schema({ composite::Quantity::Scalar("linear_speed", composite::Measure::kSpeed), composite::Quantity::Scalar("angular_speed", composite::Measure::kAngularSpeed), }); } template struct DifferentialBaseCommandImmutableInterface : public Base { using Base::operator=; K linear_speed() const { return get(*this); } K angular_speed() const { return get(*this); } }; template struct DifferentialBaseCommandMutableInterface : public DifferentialBaseCommandImmutableInterface { using DifferentialBaseCommandImmutableInterface::operator=; K linear_speed() const { return get(*this); } K angular_speed() const { return get(*this); } K& linear_speed() { return get(*this); } K& angular_speed() { return get(*this); } }; template using DifferentialBaseCommandConstView = CompositeConstView; template using DifferentialBaseCommandView = CompositeView; template using DifferentialBaseCommand = Composite; // Describes the kinematic state for an Differential base, for example input to base odometry struct DifferentialBaseStateIndices { enum { // Linear (longitudinal) speed (m/s) kLinearSpeed, // Rotation speed (radian/s) kAngularSpeed, // Linear (longitudinal) acceleration (m/s^2) kLinearAcceleration, // Angular (rotational) acceleration (radians/s^2) kAngularAcceleration, kSize }; }; inline composite::Schema DifferentialBaseStateCompositeSchema() { return composite::Schema({ composite::Quantity::Scalar("linear_speed", composite::Measure::kSpeed), composite::Quantity::Scalar("angular_speed", composite::Measure::kRotation), composite::Quantity::Scalar("linear_acceleration", composite::Measure::kAcceleration), composite::Quantity::Scalar("angular_acceleration", composite::Measure::kRotation) }); } template struct DifferentialBaseStateImmutableInterface : public Base { using Base::operator=; K linear_speed() const { return get(*this); } K angular_speed() const { return get(*this); } K linear_acceleration() const { return get(*this); } K angular_acceleration() const { return get(*this); } }; template struct DifferentialBaseStateMutableInterface : public DifferentialBaseStateImmutableInterface { using DifferentialBaseStateImmutableInterface::operator=; K linear_speed() const { return get(*this); } K angular_speed() const { return get(*this); } K linear_acceleration() const { return get(*this); } K angular_acceleration() const { return get(*this); } K& linear_speed() { return get(*this); } K& angular_speed() { return get(*this); } K& linear_acceleration() { return get(*this); } K& angular_acceleration() { return get(*this); } }; template using DifferentialBaseStateConstView = CompositeConstView; template using DifferentialBaseStateView = CompositeView; template using DifferentialBaseState = Composite; template using DifferentialBaseStateEigen = CompositeEigen; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/allocator/allocator_base.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/byte.hpp" namespace nvidia { namespace isaac { // Base class for allocators which allocate and deallocate blocks of memory. class AllocatorBase { public: // Type for a raw pointer to a block of memory using pointer_t = byte*; virtual ~AllocatorBase() = default; // Allocates memory for at least N instances of the given type template T* allocate(size_t count) { return reinterpret_cast(allocateBytes(sizeof(T) * count)); } // Deallocates a block of memory previously allocated with `allocate`. Need to be passed the same // instance count used during the call to `allocate`. template void deallocate(T* pointer, size_t count) { deallocateBytes(reinterpret_cast(pointer), sizeof(T) * count); } // Allocates memory for at least the given number of bytes virtual pointer_t allocateBytes(size_t size) = 0; // Deallocates a block of memory previously allocated with `allocate`. Need to be passed the same // byte count used during the call to `allocate`. virtual void deallocateBytes(pointer_t pointer, size_t size) = 0; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/allocator/allocators.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/allocator/allocator_base.hpp" #include "gems/core/byte.hpp" namespace nvidia { namespace isaac { // Provides a globally available allocator to allocate CPU memory. struct CpuAllocator { static byte* Allocate(size_t size); static void Deallocate(byte* pointer, size_t size); }; // Gets the currently used allocator for CPU memory allocation. AllocatorBase* GetCpuAllocator(); // Provides a globally available allocator to allocate CUDA memory. struct CudaAllocator { static byte* Allocate(size_t size); static void Deallocate(byte* pointer, size_t size); }; // Gets the currently used allocator for CUDA memory allocation. AllocatorBase* GetCudaAllocator(); } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/assert.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/core/logger.hpp" // Prints a panic message and aborts the program #define PANIC(...) \ { \ ::nvidia::isaac::logger::Log( \ __FILE__, __LINE__, ::nvidia::isaac::logger::Severity::PANIC, __VA_ARGS__); \ std::abort(); \ } // Checks if an expression evaluates to true. If not prints a panic message and aborts the program. #define ASSERT(expr, ...) \ if (!(expr)) { \ ::nvidia::isaac::logger::Log( \ __FILE__, __LINE__, ::nvidia::isaac::logger::Severity::PANIC, __VA_ARGS__); \ std::abort(); \ } // Asserts that A == B. If not prints a panic message and aborts the program. #define ISAAC_ASSERT_EQ(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ ASSERT( \ _va == _vb, "Assert failed: %s == %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A != B. If not prints a panic message and aborts the program. #define ISAAC_ASSERT_NE(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ ASSERT( \ _va != _vb, "Assert failed: %s != %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A > B. If not prints a panic message and aborts the program. #define ISAAC_ASSERT_GT(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ ASSERT( \ _va > _vb, "Assert failed: %s > %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A >= B. If not prints a panic message and aborts the program. #define ISAAC_ASSERT_GE(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ ASSERT( \ _va >= _vb, "Assert failed: %s >= %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A > B. If not prints a panic message and aborts the program. #define ISAAC_ASSERT_LT(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ ASSERT( \ _va < _vb, "Assert failed: %s > %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that A <= B. If not prints a panic message and aborts the program. #define ISAAC_ASSERT_LE(exp_a, exp_b) \ { \ const auto _va = exp_a; \ const auto _vb = exp_b; \ ASSERT( \ _va <= _vb, "Assert failed: %s <= %s.", std::to_string(_va).c_str(), \ std::to_string(_vb).c_str()); \ } // Asserts that abs(A - B) < threshold. If not prints a panic message and aborts the program. #define ISAAC_ASSERT_NEAR(exp_a, exp_b, exp_threshold) \ { \ const auto _vdiff = exp_a - exp_b; \ const auto _vthreshold = exp_threshold; \ ASSERT( \ std::abs(_vdiff) <= _vthreshold, \ "Assert failed: difference between %s and %s as |%s| <= %s.", \ std::to_string(exp_a).c_str(), std::to_string(exp_b).c_str(), \ std::to_string(_vdiff).c_str(), std::to_string(_vthreshold).c_str()); \ } ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/buffers/algorithm.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/assert.hpp" #include "gems/core/buffers/traits.hpp" #include "gems/core/byte.hpp" namespace nvidia { namespace isaac { // Copies raw memory from one buffer to another buffer void CopyArrayRaw( const void* source, BufferStorageMode source_storage, void* target, BufferStorageMode target_storage, size_t size); // Copies data between two buffers layout as matrices // For both source and target buffer the pointer and the row stride between rows is given. // `row_size` indicates the number of bytes which are actually filled with data. Bytes which are // not filled with used data might not be copied. void CopyMatrixRaw( const void* source, size_t source_stride, BufferStorageMode source_storage, void* target, size_t target_stride, BufferStorageMode target_storage, size_t rows, size_t row_size); // Copies memory from one buffer to another buffer template void CopyArray(const Source& source, Target& target) { // Asserts that the buffers have the same size ASSERT(source.size() == target.size(), "size mismatch: %zu vs %zu", source.size(), target.size()); // Copy the bytes auto source_view = View(source).template reinterpret(); auto target_view = View(target).template reinterpret(); CopyArrayRaw( reinterpret_cast(source_view.begin()), BufferTraits::kStorageMode, reinterpret_cast(target_view.begin()), BufferTraits::kStorageMode, source_view.size()); } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/buffers/buffer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/allocator/allocators.hpp" #include "gems/core/buffers/traits.hpp" #include "gems/core/byte.hpp" namespace nvidia { namespace isaac { // ------------------------------------------------------------------------------------------------- namespace detail { // A simple pointer which can be tagged. This is used for example to differentiate between a pointer // to host memory and a pointer to device memory. template class TaggedPointer { public: using value_t = std::remove_cv_t; using const_pointer_t = TaggedPointer; using pointer_t = TaggedPointer; using tag_t = Tag; // Standard constructor TaggedPointer(K* data = nullptr) : data_(data) {} // Default copy TaggedPointer(const TaggedPointer& other) = default; TaggedPointer& operator=(const TaggedPointer& other) = default; // Move will set source to nullptr TaggedPointer(TaggedPointer&& other) { *this = std::move(other); } TaggedPointer& operator=(TaggedPointer&& other) { data_ = other.data_; other.data_ = nullptr; return *this; } // Sets the actual pointer TaggedPointer& operator=(K* other) { data_ = other; return *this; } // Gets the actual pointer K* get() const { return data_; } operator K*() const { return data_; } private: K* data_; }; } // namespace detail // ------------------------------------------------------------------------------------------------- namespace detail { // Base class for Buffer and BufferView which provides storage for the memory pointer // and corresponding dimensions. template class BufferBase { public: using pointer_t = Pointer; BufferBase() : pointer_(nullptr), size_(0) {} BufferBase(Pointer pointer, size_t size) : pointer_(std::move(pointer)), size_(size) {} // pointer to the first row const Pointer& pointer() const { return pointer_; } // The total size of the buffer in bytes size_t size() const { return size_; } // A pointer to the first byte of the buffer. auto begin() const { return pointer_.get(); } // A pointer behind the last byte of the buffer. auto end() const { return begin() + size(); } protected: Pointer pointer_; size_t size_; }; } // namespace detail // ------------------------------------------------------------------------------------------------- // A buffer which owns its memory template class Buffer : public detail::BufferBase { public: using mutable_view_t = detail::BufferBase; using const_view_t = detail::BufferBase; Buffer() : handle_(nullptr, Deleter{0}) {} // Allocates memory for `size` bytes. Buffer(size_t size) : detail::BufferBase(nullptr, size), handle_(Allocator::Allocate(size), Deleter{size}) { // 1) Initialize the base class with a nullptr, the number of rows, and the desired stride. // 2) Allocate memory and store it in the unique pointer used as handle. This will also change // the stride stored in the base class to the actual stride chosen by the allocator. // 3) Get a pointer to the allocated memory and store it in the base class so that calls to // pointer() actually work. this->pointer_ = handle_.get(); } Buffer(Buffer&& buffer) : detail::BufferBase(nullptr, buffer.size_), handle_(std::move(buffer.handle_)) { this->pointer_ = handle_.get(); buffer.pointer_ = nullptr; buffer.size_ = 0; } Buffer& operator=(Buffer&& buffer) { this->handle_ = std::move(buffer.handle_); this->pointer_ = this->handle_.get(); this->size_ = buffer.size_; buffer.pointer_ = nullptr; buffer.size_ = 0; return *this; } void resize(size_t desired_size) { if (desired_size == this->size()) return; *this = Buffer(desired_size); } // Disowns the pointer from the buffer. The user is now responsible for deallocation. // WARNING: This is dangerous as the wrong allocator might be called. byte* release() { byte* pointer = handle_.release(); this->pointer_ = nullptr; return pointer; } // Creates a view which provides read and write access from this buffer object. mutable_view_t view() { return mutable_view_t(this->pointer_, this->size_, this->stride_); } const_view_t view() const { return const_view_t(typename Pointer::const_pointer_t(this->pointer_.get()), this->size_); } // Creates a view which only provides read access from this buffer object. const_view_t const_view() const { return const_view_t(typename Pointer::const_pointer_t(this->pointer_.get()), this->size_); } private: // A deleter object for the unique pointer to free allocated memory struct Deleter { size_t size; void operator()(byte* pointer) { if (size == 0) return; Allocator::Deallocate(pointer, size); } }; // A unique pointer is used to handle the allocator and to make this object non-copyable. using handle_t = std::unique_ptr; // Memory handle used to automatically deallocate memory and to disallow copy semantics. handle_t handle_; }; // ------------------------------------------------------------------------------------------------- // A pointer to host memory template using HostPointer = detail::TaggedPointer>; // A host buffer with stride which owns its memory using CpuBuffer = Buffer, CpuAllocator>; // A host buffer with stride which does not own its memory using CpuBufferView = detail::BufferBase>; // A host buffer with stride which does not own its memory and provides only read access using CpuBufferConstView = detail::BufferBase>; template <> struct BufferTraits, CpuAllocator>> { static constexpr BufferStorageMode kStorageMode = BufferStorageMode::Host; static constexpr bool kIsMutable = true; static constexpr bool kIsOwning = true; using buffer_view_t = CpuBufferView; using buffer_const_view_t = CpuBufferConstView; }; template struct BufferTraits>> { static constexpr BufferStorageMode kStorageMode = BufferStorageMode::Host; static constexpr bool kIsMutable = !std::is_const::value; static constexpr bool kIsOwning = false; using buffer_view_t = CpuBufferView; using buffer_const_view_t = CpuBufferConstView; }; // ------------------------------------------------------------------------------------------------- // A pointer to CUDA memory template using CudaPointer = detail::TaggedPointer>; // A CUDA buffer with stride which owns its memory using CudaBuffer = Buffer, CudaAllocator>; // A CUDA buffer with stride which does not own its memory using CudaBufferView = detail::BufferBase>; // A CUDA buffer with stride which does not own its memory and provides only read access using CudaBufferConstView = detail::BufferBase>; template <> struct BufferTraits, CudaAllocator>> { static constexpr BufferStorageMode kStorageMode = BufferStorageMode::Cuda; static constexpr bool kIsMutable = true; static constexpr bool kIsOwning = true; using buffer_view_t = CudaBufferView; using buffer_const_view_t = CudaBufferConstView; }; template struct BufferTraits>> { static constexpr BufferStorageMode kStorageMode = BufferStorageMode::Cuda; static constexpr bool kIsMutable = !std::is_const::value; static constexpr bool kIsOwning = false; using buffer_view_t = CudaBufferView; using buffer_const_view_t = CudaBufferConstView; }; // ------------------------------------------------------------------------------------------------- } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/buffers/traits.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include namespace nvidia { namespace isaac { // Specifies where data is stored, e.g. host or CUDA device enum class BufferStorageMode { // host memory Host, // CUDA memory Cuda }; // Specifies various properties for buffer types. // Example: // template // struct BufferTraits> { // static constexpr BufferStorageMode kStorageMode = BufferStorageMode::Cuda; // static constexpr bool kIsMutable = true; // static constexpr bool kIsOwning = true; // // static CudaArray Create(size_t size) { // return CudaArray(size); // } // }; template struct BufferTraits; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/byte.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include namespace nvidia { namespace isaac { // Will be oficially defined in C++17 using byte = uint8_t; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/constants.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include namespace nvidia { namespace isaac { // The value of pi with 75 digits available for every type. template ::value, int>::type = 0> constexpr K Pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286; // The value of 2 * pi (a.k.a tau) with 75 digits available for every type. template ::value, int>::type = 0> constexpr K TwoPi = 6.283185307179586476925286766559005768394338798750211641949889184615632812572; // Converts from degree to radians template ::value, int>::type = 0> constexpr K DegToRad(K x) { return x * K(0.017453292519943295769236907684886127134428718885417254560); } // Converts from radians to degrees template ::value, int>::type = 0> constexpr K RadToDeg(K x) { return x * K(57.29577951308232087679815481410517033240547246656432154916); } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/epsilon.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include // This file provides functions to help comparing floating point numbers for equality. // You should have a look at this excellent article for more details: // https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ namespace nvidia { namespace isaac { // A very small floating point number close to what can be represented by the corresponding // floating point standard. // For more details see https://en.wikipedia.org/wiki/Machine_epsilon template constexpr K MachineEpsilon = K(0); template <> constexpr float MachineEpsilon = 5.9604644775390625e-8f; template <> constexpr double MachineEpsilon = 1.1102230246251565404236316680908203125e-16; // Returns true if a floating point value can be considered to be zero under floating point // rounding errors. This function compares against a custom epsilon. template bool IsAlmostZero(K x, K epsilon = MachineEpsilon) { return std::abs(x) <= epsilon; } // Returns true if two floating point values are so close that they can be considered to be equal // under floating point rounding errors. This function uses relative comparison technique. // Warning: Do not use to compare against small floats, or zero, use IsAlmostZero instead. template bool IsAlmostEqualRelative(K x, K y, K max_rel_diff = K(10) * MachineEpsilon) { const K diff = std::abs(x - y); const K absx = std::abs(x); const K absy = std::abs(y); const K larger = (absx > absy) ? absx : absy; return (diff <= larger * max_rel_diff); } // Returns true if two floating point values are equal up to a certain tolerance. template bool IsAlmostEqualAbsolute(K x, K y, K tolerance) { return std::abs(x - y) <= tolerance; } // Returns true if a floating point value can be considered to be one under floating point // rounding errors. This function compares against machine epsilon. template bool IsAlmostOne(K x) { return std::abs(x - K(1)) <= K(10) * MachineEpsilon; } namespace epsilon_details { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wstrict-aliasing" inline int32_t Float32AsInteger(float x) { return *reinterpret_cast(&x); } inline int64_t Float64AsInteger(double x) { return *reinterpret_cast(&x); } #pragma GCC diagnostic pop } // namespace epsilon_details // Checks if two 32-bit floats are equal by computing their ULPs difference. inline bool IsAlmostEqualUlps(float x, float y, int32_t max_ulps_diff = 2) { const int32_t ix = epsilon_details::Float32AsInteger(x); const int32_t iy = epsilon_details::Float32AsInteger(y); if ((ix < 0) != (iy < 0)) { // In case the sign is different we still need to check if the floats were equal to // make sure -0 is equal to +0. return (x == y); } else { return std::abs(ix - iy) < max_ulps_diff; } } // Checks if two 64-bit floats are equal by computing their ULPs difference. inline bool IsAlmostEqualUlps(double x, double y, int64_t max_ulps_diff = 2) { const int64_t ix = epsilon_details::Float64AsInteger(x); const int64_t iy = epsilon_details::Float64AsInteger(y); if ((ix < 0) != (iy < 0)) { // In case the sign is different we still need to check if the floats were equal to // make sure -0 is equal to +0. return (x == y); } else { return std::abs(ix - iy) < max_ulps_diff; } } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/image/image.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/core/assert.hpp" #include "gems/core/buffers/buffer.hpp" #include "gems/core/byte.hpp" #include "gems/core/math/types.hpp" #include "gems/core/tensor/tensor.hpp" namespace nvidia { namespace isaac { // ------------------------------------------------------------------------------------------------- // A pixel which owns its data and can life independently from the image itself. template using Pixel = std::conditional_t>; // A pixel type used for read and write access to an image pixel. template using PixelRef = std::conditional_t>>; // A pixel type used for read-only access to an image pixel. template using PixelConstRef = std::conditional_t>>; namespace detail { // Helper type to create pixels and pixel references based on a pointer for N > 1 template struct PixelCreator { // Creates a non-owning pixel based on a pointer static PixelRef CreatePixelRef(K* ptr) { return PixelRef(ptr); } // Creates a non-owning, non-mutable pixel based on a pointer static PixelConstRef CreatePixelConstRef(const K* ptr) { return PixelConstRef(ptr); } }; // Specialized version of PixelCreator for N = 1 template struct PixelCreator { static PixelRef CreatePixelRef(K* ptr) { return *ptr; } static PixelConstRef CreatePixelConstRef(const K* ptr) { return *ptr; } }; // Helper type to find the correct tensor type based on the number of channels. template struct ImageTensorBase { using type = TensorBase, BufferType>; }; template struct ImageTensorBase { using type = TensorBase, BufferType>; }; } // namespace detail // ------------------------------------------------------------------------------------------------- // A two-dimensional array of pixels // // Each pixel contains `N` elements and all elements are of the same type `K`. Elements for all // pixels are stored continuously. Access to pixels returns mapped memory to provide read access // without unnecessary copies and direct write access. Pixels are stored interleaved and in // row-major storage order. // // The image type uses a tensor to store data. If `N` is equal to 1 a rank 2 tensor is used, // otherwise a rank 3 tensor is used. The tensor uses the given `BufferType` and more information // is provided in the Tensor type. // template class ImageBase { public: // The number of channels for an image must be greater than 0. static_assert(N > 0, "Number of channels must be positive"); // The number of channels for each pixels. This is also the last dimension of the underlying // tensor. static constexpr int kChannels = N; // Tensor type used to store the array of elements for this image. using tensor_t = typename detail::ImageTensorBase::type; using buffer_t = BufferType; using buffer_view_t = typename tensor_t::buffer_view_t; using buffer_const_view_t = typename tensor_t::buffer_const_view_t; static constexpr bool kIsMutable = tensor_t::kIsMutable; static constexpr bool kIsOwning = tensor_t::kIsOwning; using index_t = typename tensor_t::index_t; using coordinate_t = Vector2; // Note: Only rows and col are used for coordinates using dimensions_t = Vector2; // Note: Only rows and col are used for dimensions using element_t = typename tensor_t::element_t; using element_ptr_t = typename tensor_t::element_ptr_t; using element_const_ptr_t = typename tensor_t::element_const_ptr_t; using raw_ptr_t = typename tensor_t::raw_ptr_t; using raw_const_ptr_t = typename tensor_t::raw_const_ptr_t; // Type used for a pixel owning its memory and thus able to life outside of this image using pixel_t = Pixel; // Type used when accessing pixels which provides read and write access to pixel data. using pixel_ref_t = PixelRef; // Type used when accessing pixels which provides only read access to pixel data. using pixel_const_ref_t = PixelConstRef; // Type for a mutable view on this image using image_view_t = ImageBase; // Type for a non-mutable view on this image using image_const_view_t = ImageBase; // Create an empty image object ImageBase() = default; // Create an image object of given dimensions. This will create a new storage container and is // only available for storage container types which own their memory. This function is templated // on the integer type so that we can distable this constructor for non-owning storage types. ImageBase(const dimensions_t& dimensions) : tensor_(dimensions[0], dimensions[1]) {} ImageBase(index_t rows, index_t cols) : tensor_(rows, cols) {} // Create an image object of given dimensions and with given storage container ImageBase(buffer_t buffer, const dimensions_t& dimensions) : tensor_(std::move(buffer), dimensions[0], dimensions[1]) {} ImageBase(buffer_t buffer, index_t rows, index_t cols) : tensor_(std::move(buffer), rows, cols) {} // Creates an image from a tensor. ImageBase(tensor_t tensor) : tensor_(std::move(tensor)) {} // Copy construction uses the default behavior ImageBase(const ImageBase& other) = default; // Copy assignment uses the default behavior ImageBase& operator=(const ImageBase& other) = default; // Move construction uses the default behavior ImageBase(ImageBase&& other) = default; // Move assignment uses the default behavior ImageBase& operator=(ImageBase&& other) = default; // Creates a mutable view on this tensor template std::enable_if_t view() { return image_view_t({this->data().begin(), this->data().size()}, this->dimensions()); } // Creates a non-mutable view on this tensor image_const_view_t const_view() const { return image_const_view_t({this->data().begin(), this->data().size()}, this->dimensions()); } image_const_view_t view() const { return const_view(); } // Provides conversion to a mutable view for owning images and mutable views. template operator std::enable_if_t() { return view(); } // Provides conversion to a non-mutable view operator image_const_view_t() const { return const_view(); } // Returns true if this image has dimensions 0 bool empty() const { return rows() == 0 || cols() == 0; } // (rows, cols) as a 2-vector dimensions_t dimensions() const { return dimensions_t{rows(), cols()}; } // Returns the number of rows index_t rows() const { return tensor().dimensions()[0]; } // Returns the number of cols index_t cols() const { return tensor().dimensions()[1]; } // The number of channels constexpr int channels() const { return kChannels; } // The total number of pixels in the image index_t num_pixels() const { return rows() * cols(); } // Resizes the image template std::enable_if_t resize(index_t desired_rows, index_t desired_cols) { tensor_.resize(desired_rows, desired_cols); } template std::enable_if_t resize(const dimensions_t& dimensions) { tensor_.resize(dimensions[0], dimensions[1]); } // Returns true if the given pixel coordinate references a valid pixel. bool isValidCoordinate(index_t row, index_t col) const { return 0 <= row && row < rows() && 0 <= col && col < cols(); } // Returns a non mutable reference pixel holder on the position (row, col). pixel_const_ref_t operator()(index_t row, index_t col) const { return detail::PixelCreator::CreatePixelConstRef( row_pointer(row) + col * kChannels); } pixel_const_ref_t operator()(const coordinate_t& coordinate) const { return this->operator()(coordinate[0], coordinate[1]); } // Returns a mutable reference pixel holder on the position (row, col). template std::enable_if_t operator()(index_t row, index_t col) { return detail::PixelCreator::CreatePixelRef(row_pointer(row) + col * kChannels); } template std::enable_if_t operator()(const coordinate_t& coordinate) { return this->operator()(coordinate[0], coordinate[1]); } // Returns a non mutable reference pixel holder at the position `index`. pixel_const_ref_t operator[](index_t index) const { return detail::PixelCreator::CreatePixelConstRef( element_wise_begin() + index * kChannels); } // Returns a mutable reference pixel holder at the position `index`. template std::enable_if_t operator[](index_t index) { return detail::PixelCreator::CreatePixelRef( element_wise_begin() + index * kChannels); } // Pointers to the first element of the first pixel element_const_ptr_t element_wise_begin() const { return tensor().element_wise_begin(); } element_ptr_t element_wise_begin() { return tensor().element_wise_begin(); } // Pointers behind the last element of the last pixel element_const_ptr_t element_wise_end() const { return tensor().element_wise_end(); } element_ptr_t element_wise_end() { return tensor().element_wise_end(); } // The total number of elements in the image index_t num_elements() const { return num_pixels() * channels(); } // Pointer to the first element in the i-th row in an image element_ptr_t row_pointer(index_t row) { return element_wise_begin() + row * cols() * kChannels; } element_const_ptr_t row_pointer(index_t row) const { return element_wise_begin() + row * cols() * kChannels; } // Number of bytes used to store one row of the image in memory. size_t getStride() const { return ByteCount(1, cols()); } // Number of bytes which are used for elements of an image of the given number of rows and columns static size_t ByteCount(index_t rows, index_t cols) { ASSERT(rows >= 0, "Number of rows must not be negative: %d", rows); ASSERT(cols >= 0, "Number of cols must not be negative: %d", cols); // Note: Number of channels are guaranteed to be positive. return static_cast(rows * cols * kChannels) * sizeof(K); } // The underlying tensor object const tensor_t& tensor() const { return tensor_; } template std::enable_if_t tensor() { return tensor_; } // The underlying buffer object const buffer_t& data() const { return tensor().data(); } template std::enable_if_t data() { return tensor().data(); } private: tensor_t tensor_; }; // ------------------------------------------------------------------------------------------------- // An image which owns it's memory template using Image = ImageBase; // A mutable view on an image which does not own memory but can be used to read and write the // data of the underlying image. template using ImageView = ImageBase; // A non-mutable view on an image which does not own the memory and can only be used to read // the data of the underlying image. template using ImageConstView = ImageBase; #define ISAAC_DECLARE_CPU_IMAGE_TYPES_IMPL(N, T, S) \ using Image##N##S = Image; \ using ImageView##N##S = ImageView; \ using ImageConstView##N##S = ImageConstView; \ using Pixel##N##S = Pixel; \ using PixelRef##N##S = PixelRef; \ using PixelConstRef##N##S = PixelConstRef; #define ISAAC_DECLARE_CPU_IMAGE_TYPES(N) \ template \ using Image##N = Image; \ template \ using ImageView##N = ImageView; \ template \ using ImageConstView##N = ImageConstView; \ ISAAC_DECLARE_CPU_IMAGE_TYPES_IMPL(N, uint8_t, ub) \ ISAAC_DECLARE_CPU_IMAGE_TYPES_IMPL(N, uint16_t, ui16) \ ISAAC_DECLARE_CPU_IMAGE_TYPES_IMPL(N, int, i) \ ISAAC_DECLARE_CPU_IMAGE_TYPES_IMPL(N, double, d) \ ISAAC_DECLARE_CPU_IMAGE_TYPES_IMPL(N, float, f) ISAAC_DECLARE_CPU_IMAGE_TYPES(1) ISAAC_DECLARE_CPU_IMAGE_TYPES(2) ISAAC_DECLARE_CPU_IMAGE_TYPES(3) ISAAC_DECLARE_CPU_IMAGE_TYPES(4) #undef ISAAC_DECLARE_CPU_IMAGE_TYPES #undef ISAAC_DECLARE_CPU_IMAGE_TYPES_IMPL // ------------------------------------------------------------------------------------------------- // Helper function to create an image view from a pointer using dense storage template ImageView CreateImageView( K* data, typename ImageView::index_t rows, typename ImageView::index_t cols) { ASSERT(rows >= 0, "Number of rows must not be negative - was %d", rows); ASSERT(cols >= 0, "Number of columns must not be negative - was %d", cols); const size_t size = ImageView::ByteCount(rows, cols); return ImageView(CpuBufferView(reinterpret_cast(data), size), rows, cols); } // Helper function to create an image const view from a pointer using dense storage template ImageConstView CreateImageConstView( const K* data, typename ImageConstView::index_t rows, typename ImageConstView::index_t cols) { ASSERT(rows >= 0, "Number of rows must not be negative - was %d", rows); ASSERT(cols >= 0, "Number of columns must not be negative - was %d", cols); const size_t size = ImageConstView::ByteCount(rows, cols); return ImageConstView( CpuBufferConstView(reinterpret_cast(data), size), rows, cols); } // ------------------------------------------------------------------------------------------------- // An image stored in device memory which owns it's memory template using CudaImage = ImageBase; // A mutable view on an image which is stored on GPU device memory, does not own memory, but can be // used to read and write the data of the underlying image. template using CudaImageView = ImageBase; // A non-mutable view on an image which is stored on GPU device memory, does not own its memory, and // can only be used to read the data of the underlying image. template using CudaImageConstView = ImageBase; // Helper macro for ISAAC_DECLARE_CUDA_IMAGE_TYPES #define ISAAC_DECLARE_CUDA_IMAGE_TYPES_IMPL(N, K, S) \ using CudaImage##N##S = CudaImage; \ using CudaImageView##N##S = CudaImageView; \ using CudaImageConstView##N##S = CudaImageConstView; // Helper macro to define various CudaImage types #define ISAAC_DECLARE_CUDA_IMAGE_TYPES(N) \ template \ using CudaImage##N = CudaImage; \ template \ using CudaImageView##N = CudaImageView; \ template \ using CudaImageConstView##N = CudaImageConstView; \ ISAAC_DECLARE_CUDA_IMAGE_TYPES_IMPL(N, uint8_t, ub) \ ISAAC_DECLARE_CUDA_IMAGE_TYPES_IMPL(N, uint16_t, ui16) \ ISAAC_DECLARE_CUDA_IMAGE_TYPES_IMPL(N, int, i) \ ISAAC_DECLARE_CUDA_IMAGE_TYPES_IMPL(N, double, d) \ ISAAC_DECLARE_CUDA_IMAGE_TYPES_IMPL(N, float, f) ISAAC_DECLARE_CUDA_IMAGE_TYPES(1) ISAAC_DECLARE_CUDA_IMAGE_TYPES(2) ISAAC_DECLARE_CUDA_IMAGE_TYPES(3) ISAAC_DECLARE_CUDA_IMAGE_TYPES(4) // ------------------------------------------------------------------------------------------------- // Helper function to create a CUDA image view from a pointer using dense storage template CudaImageView CreateCudaImageView( K* data, typename CudaImageView::index_t rows, typename CudaImageView::index_t cols) { ASSERT(rows >= 0, "Number of rows must not be negative - was %d", rows); ASSERT(cols >= 0, "Number of columns must not be negative - was %d", cols); const size_t size = CudaImageView::ByteCount(rows, cols); return CudaImageView(CudaBufferView(reinterpret_cast(data), size), rows, cols); } // Helper function to create a CUDA image const view from a pointer using dense storage template CudaImageConstView CreateCudaImageConstView( const K* data, typename CudaImageConstView::index_t rows, typename CudaImageConstView::index_t cols) { ASSERT(rows >= 0, "Number of rows must not be negative - was %d", rows); ASSERT(cols >= 0, "Number of columns must not be negative - was %d", cols); const size_t size = CudaImageConstView::ByteCount(rows, cols); return CudaImageConstView( CudaBufferConstView(reinterpret_cast(data), size), rows, cols); } // ------------------------------------------------------------------------------------------------- } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/logger.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include // Logs a debug message #define LOG_DEBUG(...) \ ::nvidia::isaac::logger::Log( \ __FILE__, __LINE__, ::nvidia::isaac::logger::Severity::DEBUG, __VA_ARGS__) // Logs an informational message #define LOG_INFO(...) \ ::nvidia::isaac::logger::Log( \ __FILE__, __LINE__, ::nvidia::isaac::logger::Severity::INFO, __VA_ARGS__) // Logs a warning #define LOG_WARNING(...) \ ::nvidia::isaac::logger::Log( \ __FILE__, __LINE__, ::nvidia::isaac::logger::Severity::WARNING, __VA_ARGS__) // Logs an error #define LOG_ERROR(...) \ ::nvidia::isaac::logger::Log( \ __FILE__, __LINE__, ::nvidia::isaac::logger::Severity::ERROR, __VA_ARGS__) namespace nvidia { namespace isaac { namespace logger { // Indicates the level of severity for a log message enum class Severity { // A utility case which can be used for `SetSeverity` to disable all severity levels. NONE = -2, // A utility case which can be used for `Redirect` and `SetSeverity` ALL = -1, // The five different log severities in use from most severe to least severe. PANIC = 0, // Need to start at 0 ERROR, WARNING, INFO, DEBUG, // A utility case representing the number of log levels used internally. COUNT }; // Function which is used for logging. It can be changed to intercept the logged messages. extern void (*LoggingFunction)(const char* file, int line, Severity severity, const char* log); // Redirects the output for a given log severity. void Redirect(std::FILE* file, Severity severity = Severity::ALL); // Redirects the output for a given file log severity up to and including a given log severity. void RedirectFileLog(std::FILE* file, Severity severity = Severity::DEBUG); // Sets global log severity thus effectively disabling all logging with lower severity void SetSeverity(Severity severity); // Converts the message and argument into a string and pass it to LoggingFunction. template void Log(const char* file, int line, Severity severity, const char* txt, ...) { va_list args1; va_start(args1, txt); va_list args2; va_copy(args2, args1); std::vector buf(1 + std::vsnprintf(NULL, 0, txt, args1)); va_end(args1); std::vsnprintf(buf.data(), buf.size(), txt, args2); va_end(args2); LoggingFunction(file, line, severity, buf.data()); } // Helper datastructure for Singleton struct SeverityContainer { Severity r = Severity::DEBUG; }; } // namespace logger } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/math/macros.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #ifdef __CUDACC__ #define CUDA_BOTH __host__ __device__ #define CUDA_BOTH_INLINE __forceinline__ __host__ __device__ #define CUDA_INLINE __forceinline__ __device__ #else #define CUDA_BOTH #define CUDA_BOTH_INLINE __inline__ #endif // __CUDACC__ ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/math/pose2.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/core/math/so2.hpp" #include "gems/core/math/types.hpp" #include "gems/core/math/utils.hpp" namespace nvidia { namespace isaac { // Class for 2D transformation. template struct Pose2 { using Scalar = K; static constexpr int kDimension = 2; SO2 rotation; Vector2 translation; // Returns identity transformation static Pose2 Identity() { return Pose2{SO2::Identity(), Vector2::Zero()}; } // Creates a translation transformation static Pose2 Translation(const Vector2& translation) { return Pose2{SO2::Identity(), translation}; } static Pose2 Translation(K x, K y) { return Pose2{SO2::Identity(), Vector2{x, y}}; } // Creates a rotation transformation static Pose2 Rotation(const K angle) { return Pose2{SO2::FromAngle(angle), Vector2::Zero()}; } // Creates a pose from position and angle static Pose2 FromXYA(K px, K py, K angle) { return Pose2{SO2::FromAngle(angle), Vector2{px, py}}; } // Creates a pose from matrix transformation static Pose2 FromMatrix(const Matrix3& matrix) { return Pose2{ SO2::FromNormalized(matrix(0, 0), matrix(1, 0)), Vector2(matrix(0, 2), matrix(1, 2))}; } // Returns the inverse transformation Pose2 inverse() const { const SO2 inv = rotation.inverse(); return Pose2{inv, -(inv * translation)}; } // Returns the transformation as a matrix Matrix3 matrix() const { Matrix3 ret; ret << rotation.cos(), -rotation.sin(), translation.x(), rotation.sin(), rotation.cos(), translation.y(), K(0), K(0), K(1); return ret; } // Casts to a different type template ::value, int> = 0> Pose2 cast() const { return Pose2{rotation.template cast(), translation.template cast()}; } template ::value, int> = 0> const Pose2& cast() const { // Nothing to do as the type does not change return *this; } // Composition of Pose2 friend Pose2 operator*(const Pose2& lhs, const Pose2& rhs) { return Pose2{lhs.rotation * rhs.rotation, lhs.rotation * rhs.translation + lhs.translation}; } // Transforms a vector 2D with the given 2D transformation friend Vector2 operator*(const Pose2& pose, const Vector2& vec) { return pose.rotation * vec + pose.translation; } // Exponentaiton of the transformation Pose2 pow(K exponent) const { const K angle = rotation.angle(); const K half_angle = angle / K(2); const K csc_sin = IsAlmostZero(angle) ? exponent * (K(1) + (K(1) - exponent * exponent) * half_angle * half_angle / K(6)) : std::sin(half_angle * exponent) / std::sin(half_angle); const SO2 rot = SO2::FromAngle(half_angle * (exponent - K(1))); return Pose2{SO2::FromAngle(angle * exponent), csc_sin * (rot * translation)}; } }; using Pose2d = Pose2; using Pose2f = Pose2; // The "exponential" map from three-dimensional tangent space to SE(2) manifold space // For SE(2) this function encodes the tangent space as a three-dimensional vector (tx, ty, a) // where (tx, ty) is the translation component and a is the angle. template Pose2 Pose2Exp(const Vector3& tangent) { return Pose2{SO2::FromAngle(tangent[2]), tangent.template head<2>()}; } // The "logarithmic" map from manifold to tangent space // This computes the tangent for a pose relative to the identity pose. Log and exp are inverse // to each other. template Vector3 Pose2Log(const Pose2& pose) { return Vector3{pose.translation.x(), pose.translation.y(), pose.rotation.angle()}; } // Returns true if given pose is almost identity. template bool IsPoseAlmostIdentity(const Pose2& pose) { return IsAlmostZero(pose.translation.x()) && IsAlmostZero(pose.translation.y()) && IsAlmostOne(pose.rotation.cos()); } // Returns distance to identity pose in position and angle. // First element of the return value is for position, the seconds is for angle. template Vector2 PoseMagnitude(const Pose2& pose) { return {pose.translation.norm(), std::abs(pose.rotation.angle())}; } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/math/pose3.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/core/math/pose2.hpp" #include "gems/core/math/so3.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { // Class for 3D transformation. template struct Pose3 { using Scalar = K; static constexpr int kDimension = 3; SO3 rotation; Vector3 translation; // Returns identity transformation CUDA_BOTH static Pose3 Identity() { return Pose3{SO3::Identity(), Vector3::Zero()}; } // Creates a translation transformation CUDA_BOTH static Pose3 Translation(const Vector3& translation) { return Pose3{SO3::Identity(), translation}; } CUDA_BOTH static Pose3 Translation(K x, K y, K z) { return Pose3{SO3::Identity(), Vector3{x, y, z}}; } // Creates a translation transformation CUDA_BOTH static Pose3 Rotation(const Vector3& axis, K angle) { return Pose3{SO3::FromAxisAngle(axis, angle), Vector3::Zero()}; } // Creates a 3D pose from a 2D pose in the XY plane CUDA_BOTH static Pose3 FromPose2XY(const Pose2& pose) { return Pose3{ SO3::FromSO2XY(pose.rotation), Vector3{pose.translation.x(), pose.translation.y(), K(0)}}; } // Creates a pose from matrix transformation CUDA_BOTH static Pose3 FromMatrix(const Matrix4& matrix) { return Pose3{ SO3::FromNormalizedQuaternion(Quaternion(matrix.template topLeftCorner<3, 3>())), matrix.template topRightCorner<3, 1>()}; } // Returns the inverse transformation CUDA_BOTH Pose3 inverse() const { const auto inv = rotation.inverse(); return Pose3{inv, -(inv * translation)}; } // Returns the transformation as a matrix CUDA_BOTH Matrix4 matrix() const { Matrix4 ret; ret.template topLeftCorner<3, 3>() = rotation.matrix(); ret.template topRightCorner<3, 1>() = translation; ret.template bottomLeftCorner<1, 3>().setZero(); ret(3, 3) = K(1); return ret; } // Casts to a different type template ::value, int> = 0> CUDA_BOTH Pose3 cast() const { return Pose3{rotation.template cast(), translation.template cast()}; } template ::value, int> = 0> CUDA_BOTH const Pose3& cast() const { // Nothing to do as the type does not change return *this; } // Converts to a 2D pose in the XY plane CUDA_BOTH Pose2 toPose2XY() const { return Pose2{rotation.toSO2XY(), translation.template head<2>()}; } // Composition of poses CUDA_BOTH friend Pose3 operator*(const Pose3& lhs, const Pose3& rhs) { return Pose3{lhs.rotation * rhs.rotation, lhs.rotation * rhs.translation + lhs.translation}; } // Transforms a vector 2D with the given 2D transformation CUDA_BOTH friend Vector3 operator*(const Pose3& pose, const Vector3& vec) { return pose.rotation * vec + pose.translation; } // Exponentaiton of the transformation CUDA_BOTH Pose3 pow(K exponent) const { // First step: align the rotation vector with the z axis. const K angle = WrapPi(rotation.angle()); if (IsAlmostZero(angle)) { // TODO(bbutin): Use Taylor expension in that case? return Pose3{rotation, exponent * translation}; } const Vector3 axis = rotation.axis(); const Vector3 cross = axis.cross(Vector3(K(0), K(0), K(1))); const K cos = axis.z(); const K sin = cross.norm(); Matrix3 rot = Matrix3::Identity() * cos; // If axis is align in the Z direction, the matrix above will do the trick, if not we compute // rotation matrix to transform the axis in the Z axis. if (!IsAlmostZero(sin)) { // TODO(bbutin): Use Taylor expension in case sin ~ 0? const Vector3 unit = cross / sin; rot += (1.0 - cos) * unit * unit.transpose(); rot(0, 1) += -cross.z(); rot(0, 2) += cross.y(); rot(1, 2) += -cross.x(); rot(1, 0) += cross.z(); rot(2, 0) += -cross.y(); rot(2, 1) += cross.x(); } // Now we can compute the exponentation the same way as for the 2d for x and y, while z will // just be linearly FromScaledAxis const K half_angle = angle / K(2); const K csc_sin = IsAlmostZero(angle) ? exponent * (K(1) + (K(1) - exponent * exponent) * half_angle * half_angle / K(6)) : std::sin(half_angle * exponent) / std::sin(half_angle); const SO2 rot2 = SO2::FromAngle(half_angle * (exponent - K(1))); const Vector3 t = rot * translation; const Vector2 xy = csc_sin * (rot2 * t.template head<2>()); const SO3 final_rotation = SO3::FromAngleAxis(angle * exponent, axis); return Pose3{final_rotation, rot.inverse() * Vector3(xy.x(), xy.y(), t.z() * exponent)}; } }; using Pose3d = Pose3; using Pose3f = Pose3; // The "exponential" map of SE(3) which maps a tangent space element to the manifold space // For SE(3) this function encodes the tangent space as a six-dimensional vector // (px, py, pz, rx, ry, rz) where (px, py, pz) is the translation component and (rx, ry, rz) is the // scaled rotation axis. template CUDA_BOTH Pose3 Pose3Exp(const Vector6& tangent) { return Pose3{SO3::FromScaledAxis(tangent.template tail<3>()), tangent.template head<3>()}; } // The "logarithmic" map of SE(3) which maps a manifold space element to the tangent space // This computes the tangent for a pose relative to the identity pose. Log and exp are inverse // to each other. template CUDA_BOTH Vector6 Pose3Log(const Pose3& pose) { Vector6 result; result.template head<3>() = pose.translation; result.template tail<3>() = pose.rotation.angle() * pose.rotation.axis(); return result; } // Returns true if given pose is almost identity. template CUDA_BOTH bool IsPoseAlmostIdentity(const Pose3& pose) { return IsAlmostZero(pose.translation.norm()) && IsAlmostZero(pose.rotation.angle()); } // Returns distance to identity pose in position and angle. // First element of the return value is for position, the seconds is for angle. template CUDA_BOTH Vector2 PoseMagnitude(const Pose3& pose) { return {pose.translation.norm(), static_cast(std::abs(pose.rotation.angle()))}; } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/math/so2.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/core/assert.hpp" #include "gems/core/epsilon.hpp" #include "gems/core/math/types.hpp" #include "gems/core/math/utils.hpp" namespace nvidia { namespace isaac { // Class for 2D rotation template class SO2 { public: using Scalar = K; static constexpr int kDimension = 2; // Creates an undefined rotation // Note: Use Identity to create the identity rotation SO2() {} // Return identity rotation CUDA_BOTH static SO2 Identity() { SO2 q; q.cos_sin_ = Vector2(K(1), K(0)); return q; } // Creates rotation from an angle // Note: This uses calls to trigonometric functions. CUDA_BOTH static SO2 FromAngle(K angle) { SO2 q; q.cos_sin_ = Vector2(std::cos(angle), std::sin(angle)); return q; } // Creates rotation from a not necessarily normalized direction vector CUDA_BOTH static SO2 FromDirection(const Vector2& direction) { SO2 q; const K norm = direction.norm(); ASSERT(!IsAlmostZero(norm), "Direction vector must not be 0"); q.cos_sin_ = direction / norm; return q; } CUDA_BOTH static SO2 FromDirection(K dx, K dy) { return FromDirection(Vector2(dx, dy)); } // Creates from a normalized cos/sin direction angle CUDA_BOTH static SO2 FromNormalized(const Vector2& cos_sin) { ASSERT( IsAlmostEqualRelative(cos_sin.squaredNorm(), K(1)), "Given cos/sin vector is not normalized: %lf", cos_sin.norm()); SO2 q; q.cos_sin_ = cos_sin; return q; } CUDA_BOTH static SO2 FromNormalized(K cos_angle, K sin_angle) { return FromNormalized(Vector2(cos_angle, sin_angle)); } // Access to cosine and sine of the rotation angle. // Note this is a simple getter and deos not call trigonometric functions. CUDA_BOTH K cos() const { return cos_sin_[0]; } CUDA_BOTH K sin() const { return cos_sin_[1]; } // Access to cos and sin of the rotation angle as a direction vector. const Vector2& asDirection() const { return cos_sin_; } // Returns the rotation angle in range [-PI;PI] // Note: This uses a call to a trigonometric function. CUDA_BOTH K angle() const { return std::atan2(sin(), cos()); } // Return Rotation matrix CUDA_BOTH Matrix2 matrix() const { Matrix2 m; m(0, 0) = cos(); m(0, 1) = -sin(); m(1, 0) = sin(); m(1, 1) = cos(); return m; } // Inverse Rotation CUDA_BOTH SO2 inverse() const { return SO2::FromNormalized(cos(), -sin()); } // Casts to a different type template ::value, int> = 0> CUDA_BOTH SO2 cast() const { // We need to re-normalize in the new type return SO2::FromDirection(asDirection().template cast()); } template ::value, int> = 0> CUDA_BOTH const SO2& cast() const { // Nothing to do as the type does not change return *this; } // Rotation composition CUDA_BOTH friend SO2 operator*(const SO2& lhs, const SO2& rhs) { return FromDirection( lhs.cos() * rhs.cos() - lhs.sin() * rhs.sin(), lhs.sin() * rhs.cos() + lhs.cos() * rhs.sin()); } // Rotates a vector 2D CUDA_BOTH friend Vector2 operator*(const SO2& lhs, const Vector2& vec) { return Vector2( lhs.cos() * vec[0] - lhs.sin() * vec[1], lhs.sin() * vec[0] + lhs.cos() * vec[1]); } private: Vector2 cos_sin_; }; using SO2d = SO2; using SO2f = SO2; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/math/so3.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/core/math/macros.hpp" #include "gems/core/math/so2.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { // Class for 3D rotation template class SO3 { public: using Scalar = K; static constexpr int kDimension = 3; // Creates an empty un-initialized quaternion // Note: Use Identity to create an identity rotation. SO3() {} // Return identity rotation CUDA_BOTH static SO3 Identity() { return SO3(Quaternion::Identity()); } // Creates a rotation which rotates by around the given axes by the magnitude of the axis CUDA_BOTH static SO3 FromScaledAxis(const Vector3& axis_angle) { const K norm = axis_angle.norm(); if (IsAlmostZero(norm)) { return SO3::Identity(); } else { return SO3(Quaternion(Eigen::AngleAxis(norm, axis_angle / norm))); } } // Creates a rotation which rotates by an angle around a given (not necessarily normalized) axis CUDA_BOTH static SO3 FromAxisAngle(const Vector3& axis, K angle) { return SO3(Quaternion(Eigen::AngleAxis(angle, axis.normalized()))); } CUDA_BOTH static SO3 FromAngleAxis(K angle, const Vector3& axis) { return SO3(Quaternion(Eigen::AngleAxis(angle, axis.normalized()))); } // Creates rotation from a (not necessarily normalized) quaternion CUDA_BOTH static SO3 FromQuaternion(const Quaternion& quaternion) { return SO3(quaternion.normalized()); } // Creates rotation from a normalized quaternion // Note: This will assert if the quaternion does not have unit length. CUDA_BOTH static SO3 FromNormalizedQuaternion(const Quaternion& quaternion) { ASSERT( IsAlmostEqualRelative(quaternion.squaredNorm(), K(1)), "Given cos/sin vector is not normalized: %lf", quaternion.norm()); return SO3(quaternion); } // Creates a 3D rotation from a 2D rotation in the XY plane CUDA_BOTH static SO3 FromSO2XY(const SO2& rotation) { return FromAxisAngle({K(0), K(0), K(1)}, rotation.angle()); } // Creates rotation from a 3x3 rotation matrix CUDA_BOTH static SO3 FromMatrix(const Matrix& matrix) { return SO3(Quaternion(matrix).normalized()); } // Returns the rotation axis CUDA_BOTH Vector3 axis() const { return quaternion_.coeffs().head(3).normalized(); } // Returns the angle of rotation around the axis // Note: This calls a trigonometric function. CUDA_BOTH K angle() const { return K(2) * std::atan2(quaternion_.coeffs().head(3).norm(), quaternion_.coeffs().w()); } // Returns the quaternion representation of the rotation CUDA_BOTH const Quaternion& quaternion() const { return quaternion_; } // Returns the matrix representation of the rotation CUDA_BOTH Matrix3 matrix() const { return quaternion_.toRotationMatrix(); } // Returns the roll, pitch, yaw euler angles of the rotation CUDA_BOTH Vector3 eulerAnglesRPY() const { const Vector3d euler_angles = quaternion_.toRotationMatrix().eulerAngles(0, 1, 2); // Make sure the roll is in range [-Pi/2, Pi/2] if (std::abs(euler_angles[0]) > Pi * K(0.5)) { return Vector3d( WrapPi(euler_angles[0] + Pi), WrapPi(Pi - euler_angles[1]), WrapPi(euler_angles[2] + Pi)); } return euler_angles; } // Returns the inverse rotation. CUDA_BOTH SO3 inverse() const { // conjugate == inverse iff quaternion_.norm() == 1 return SO3(quaternion_.conjugate()); } // Casts to a different type template ::value, int> = 0> CUDA_BOTH SO3 cast() const { // We need to re-normalize in the new type return SO3::FromQuaternion(quaternion().template cast()); } template ::value, int> = 0> CUDA_BOTH const SO3& cast() const { // Nothing to do as the type does not change return *this; } // Converts to a 2D rotation in the XY plane CUDA_BOTH SO2 toSO2XY() const { // 2D rotation matrix: // cos(a) -sin(a) // sin(a) cos(a) // Quaternion to 3D rotation matrix: // 1 - 2*(qy^2 + qz^2) 2*(qx*qy - qz*qw) ... // 2*(qx*qy + qz*qw) 1 - 2*(qx^2 + qz^2) ... // It follows (modulo re-normalization): // cos(a) = 1 - (qx^2 + qy^2 + 2*qz^2) // sin(a) = 2*qz*qw // These formulas correspond to the half-angle formulas for sin/cos. const K qx = quaternion_.x(); const K qy = quaternion_.y(); const K qz = quaternion_.z(); const K qw = quaternion_.w(); const K cos_a = K(1) - (qx * qx + qy * qy + K(2) * qz * qz); const K sin_a = K(2) * qz * qw; return SO2::FromDirection(cos_a, sin_a); } // Rotation composition CUDA_BOTH friend SO3 operator*(const SO3& lhs, const SO3& rhs) { return FromQuaternion(lhs.quaternion_ * rhs.quaternion_); } // Rotates a vector 3D by the given rotation CUDA_BOTH friend Vector3 operator*(const SO3& rot, const Vector3& vec) { // TODO: faster implementation return (rot.quaternion_ * Quaternion(K(0), vec.x(), vec.y(), vec.z()) * rot.quaternion_.conjugate()) .coeffs() .head(3); } // Create rotation from roll/pitch/yaw Euler angles CUDA_BOTH static SO3 FromEulerAnglesRPY(K roll_angle, K pitch_angle, K yaw_angle) { SO3 roll = SO3::FromAngleAxis(roll_angle, {K(1), K(0), K(0)}); SO3 pitch = SO3::FromAngleAxis(pitch_angle, {K(0), K(1), K(0)}); SO3 yaw = SO3::FromAngleAxis(yaw_angle, {K(0), K(0), K(1)}); return roll * pitch * yaw; } // Create rotation from Euler angles in order (roll, pitch, yaw) CUDA_BOTH static SO3 FromEulerAnglesRPY(const Vector3d& roll_pitch_yaw) { return FromEulerAnglesRPY(roll_pitch_yaw[0], roll_pitch_yaw[1], roll_pitch_yaw[2]); } // Computes the jacobian of the rotation of normal vector. Plane normal only has rotation // component. CUDA_BOTH Matrix vectorRotationJacobian(const Vector3& n) const { // Ref: https://www.weizmann.ac.il/sci-tea/benari/sites/sci-tea.benari/files/uploads/ // softwareAndLearningMaterials/quaternion-tutorial-2-0-1.pdf // Rotation Matrix in Quaternion (R): // [w^2 + x^2 - y^2 - z^2 2xy - 2wz 2wy + 2xz] // [2wz + 2xy w^2 - x^2 + y^2 - z^2 2yz - 2wx] // [2xz - 2wy 2wx + 2yz w^2 - x^2 - y^2 + z^2] const K qx = quaternion_.x(); const K qy = quaternion_.y(); const K qz = quaternion_.z(); const K qw = quaternion_.w(); Matrix result; result << K(2) * (qw * n[0] - qz * n[1] + qy * n[2]), K(2) * (qx * n[0] + qy * n[1] + qz * n[2]), K(-2) * (qy * n[0] - qx * n[1] - qw * n[2]), K(-2) * (qz * n[0] + qw * n[1] - qx * n[2]), K(2) * (qz * n[0] + qw * n[1] - qx * n[2]), K(2) * (qy * n[0] - qx * n[1] - qw * n[2]), K(2) * (qx * n[0] + qy * n[1] + qz * n[2]), K(2) * (qw * n[0] - qz * n[1] + qy * n[2]), K(-2) * (qy * n[0] - qx * n[1] - qw * n[2]), K(2) * (qz * n[0] + qw * n[1] - qx * n[2]), K(-2) * (qw * n[0] - qz * n[1] + qy * n[2]), K(2) * (qx * n[0] + qy * n[1] + qz * n[2]); return result; } private: SO3(const Quaternion& quaternion) : quaternion_(quaternion) {} Quaternion quaternion_; }; using SO3d = SO3; using SO3f = SO3; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/math/types.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/math/macros.hpp" namespace nvidia { namespace isaac { template using Matrix = Eigen::Matrix; template using Vector = Eigen::Matrix; template using RowVector = Eigen::Matrix; template using ColVector = Eigen::Matrix; template using VectorX = Vector; using VectorXd = VectorX; using VectorXf = VectorX; using VectorXi = VectorX; using VectorXub = VectorX; using VectorXcf = Eigen::VectorXcf; template using RowVectorX = RowVector; using RowVectorXf = RowVectorX; template using ColVectorX = ColVector; using ColVectorXf = ColVectorX; template using MatrixX = Matrix; using MatrixXd = MatrixX; using MatrixXf = MatrixX; using MatrixXi = MatrixX; using MatrixXcf = Eigen::MatrixXcf; #define DEFINE_MATRIX_TYPES(N) \ template \ using Matrix##N = Matrix; \ using Matrix##N##d = Matrix##N; \ using Matrix##N##f = Matrix##N; \ using Matrix##N##i = Matrix##N; DEFINE_MATRIX_TYPES(2) DEFINE_MATRIX_TYPES(3) DEFINE_MATRIX_TYPES(4) DEFINE_MATRIX_TYPES(5) DEFINE_MATRIX_TYPES(6) DEFINE_MATRIX_TYPES(7) DEFINE_MATRIX_TYPES(8) #undef DEFINE_MATRIX_TYPES // Matrix types with fixed number of rows but dynamic number of columns. // Useful to store and efficiently manipulate sets of geometric entities, e.g. points and planes. // 2xN: 2D points in Euclidean coordinates // 3xN: 2D points in homogeneous coordinates or 3D points in Euclidean coordinates // 4xN: planes or 3D points in homogeneous coordinates #define DEFINE_FIXED_ROWS_MATRIX_TYPES(N) \ template \ using Matrix##N##X = Matrix; \ using Matrix##N##Xd = Matrix##N##X; \ using Matrix##N##Xf = Matrix##N##X; \ using Matrix##N##Xi = Matrix##N##X; DEFINE_FIXED_ROWS_MATRIX_TYPES(2) DEFINE_FIXED_ROWS_MATRIX_TYPES(3) DEFINE_FIXED_ROWS_MATRIX_TYPES(4) DEFINE_FIXED_ROWS_MATRIX_TYPES(5) DEFINE_FIXED_ROWS_MATRIX_TYPES(6) DEFINE_FIXED_ROWS_MATRIX_TYPES(7) DEFINE_FIXED_ROWS_MATRIX_TYPES(8) #undef DEFINE_FIXED_ROWS_MATRIX_TYPES template using Matrix34 = Matrix; using Matrix34d = Matrix34; using Matrix34f = Matrix34; using Matrix34i = Matrix34; template using Matrix43 = Matrix; using Matrix43d = Matrix43; using Matrix43f = Matrix43; using Matrix43i = Matrix43; #define DEFINE_VECTOR_TYPES(N) \ template \ using Vector##N = Vector; \ using Vector##N##d = Vector##N; \ using Vector##N##f = Vector##N; \ using Vector##N##i = Vector##N; \ using Vector##N##ub = Vector##N; DEFINE_VECTOR_TYPES(2) DEFINE_VECTOR_TYPES(3) DEFINE_VECTOR_TYPES(4) DEFINE_VECTOR_TYPES(5) DEFINE_VECTOR_TYPES(6) DEFINE_VECTOR_TYPES(7) DEFINE_VECTOR_TYPES(8) #undef DEFINE_VECTOR_TYPES template using Quaternion = Eigen::Quaternion; using Quaterniond = Quaternion; using Quaternionf = Quaternion; // Helper function to compute the sum of two quaternions template CUDA_BOTH Quaternion operator+(const Quaternion& lhs, const Quaternion& rhs) { return Quaternion(lhs.coeffs() + rhs.coeffs()); } // Helper function to compute the difference of two quaternions template CUDA_BOTH Quaternion operator-(const Quaternion& lhs, const Quaternion& rhs) { return Quaternion(lhs.coeffs() - rhs.coeffs()); } // Unary - operator for a quaternion template CUDA_BOTH Quaternion operator-(const Quaternion& q) { return Quaternion(-q.coeffs()); } template using EigenImage = Eigen::Array; template using EigenImageMap = Eigen::Map>; template using EigenImageConstMap = Eigen::Map>; // A base helper for constructing Views of data as eigen matrix maps. template < typename K, int Rows = Eigen::Dynamic, int Cols = Eigen::Dynamic, int MatrixOptions = 0, int MapOptions = 0, int OuterStride = 0, int InnerStride = 0> using EigenMatrixView = Eigen::Map< Eigen::Matrix, MapOptions, Eigen::Stride>; // A base helper for constructing const Views of data as eigen matrix maps. template < typename K, int Rows = Eigen::Dynamic, int Cols = Eigen::Dynamic, int MatrixOptions = 0, int MapOptions = 0, int OuterStride = 0, int InnerStride = 0> using EigenMatrixConstView = Eigen::Map< const Eigen::Matrix, MapOptions, Eigen::Stride>; // A base helper for constructing Views of data as eigen vector maps. template < typename K, int Rows = Eigen::Dynamic, int MapOptions = 0, int OuterStride = 0, int InnerStride = 0> using EigenVectorView = Eigen::Map, MapOptions, Eigen::Stride>; // A base helper for constructing const Views of data as eigen vector maps. template < typename K, int Rows = Eigen::Dynamic, int MapOptions = 0, int OuterStride = 0, int InnerStride = 0> using EigenVectorConstView = Eigen::Map< const Eigen::Matrix, MapOptions, Eigen::Stride>; // A base helper for constructing Views of data as eigen row vector maps. template < typename K, int Cols = Eigen::Dynamic, int MapOptions = 0, int OuterStride = 0, int InnerStride = 0> using EigenRowVectorView = Eigen::Map< Eigen::Matrix, MapOptions, Eigen::Stride>; // A base helper for constructing const Views of data as eigen row vector maps. template < typename K, int Cols = Eigen::Dynamic, int MapOptions = 0, int OuterStride = 0, int InnerStride = 0> using EigenRowVectorConstView = Eigen::Map< const Eigen::Matrix, MapOptions, Eigen::Stride>; // Creates a Vector from an initializer list template CUDA_BOTH Vector MakeVector(const K (&elements)[N]) { Vector result; for (size_t i = 0; i < N; i++) { result[i] = elements[i]; } return result; } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/math/utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/core/assert.hpp" #include "gems/core/constants.hpp" #include "gems/core/epsilon.hpp" #include "gems/core/math/macros.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { // Returns square of a number. This is alternative to using std::pow(number, 2). template CUDA_BOTH K Square(K number) { return number * number; } // Returns an angle within the range ]-Pi, Pi] that is equivalent to `angle`: // WrapPi(angle) == angle + k*2*Pi (k being an integer) template CUDA_BOTH K WrapPi(K angle) { // Use -angle in order to include Pi and exclude -Pi const K d = std::floor((Pi - angle) / TwoPi); return angle + d * TwoPi; } // Returns an angle within the range [0, 2*Pi[ that is equivalent to `angle`: // WrapTwoPi(angle) == angle + k*2*Pi (k being an integer) template CUDA_BOTH K WrapTwoPi(K angle) { while (angle >= TwoPi) angle -= TwoPi; while (angle < K(0)) angle += TwoPi; return angle; } // Returns the difference between two angles in the range ]-Pi, Pi] // Warning to not use the result to compare to zero if the angles are big. template CUDA_BOTH K DeltaAngle(K x, K y) { return WrapPi(x - y); } // Returns the average of two angles in the range ]-Pi, Pi] template CUDA_BOTH K MeanAngle(K x, K y) { return WrapPi(y + 0.5 * DeltaAngle(x, y)); } // Computes a unit vector at given angle (anti clock-wise from x-axis) template CUDA_BOTH Vector2 AngleVector(K angle) { return Vector2{std::cos(angle), std::sin(angle)}; } // Limits the absolute of a value template CUDA_BOTH K LimitAbs(K x, K max) { return x < -max ? -max : (x > max ? max : x); } // Clamps a value to the given interval [xmin, xmax] template CUDA_BOTH K Clamp(K x, K xmin, K xmax) { return x < xmin ? xmin : (x > xmax ? xmax : x); } // Clamps a value to the unit interval [0, 1] template CUDA_BOTH K Clamp01(K x) { return Clamp(x, K(0), K(1)); } // Safely cast a floating point number into an integral type and clamp the result in the range // [min, max]. If NaN is provided as input, then max will be returned. template < typename K, typename I, typename std::enable_if_t::value, int> = 0, typename std::enable_if_t::value, int> = 0> CUDA_BOTH I SafeClampAndCast(K value, I min, I max) { if (value < static_cast(min)) { return min; } if (value < static_cast(max)) { return static_cast(value); } return max; } // Convenience function which calls std::floor and stores the result in a 32-bit integer. template ::value, int> = 0> CUDA_BOTH int FloorToInt(K value) { return static_cast(std::floor(value)); } // Rounds a double to a 32-bit integer using a nifty trick. This function only works if the double // is within reasonable range. CUDA_BOTH_INLINE int FastRoundDoubleToInt32(double x) { union { double real; int integer; } q; q.real = x + 6755399441055744.0; return q.integer; } // Convenience function which calls std::floor and stores the result in a 32-bit integer. template ::value, int> = 0> CUDA_BOTH int FloorToIntWithReminder(K value, K& reminder) { const K floor_value = std::floor(value); reminder = value - floor_value; return static_cast(floor_value); } // Computes 0 <= a such that k*n + a = x for 0 <= k < n CUDA_BOTH_INLINE int PositiveModulo(int x, int n) { const int k = x % n; return (k < 0 ? k + n : k); } // Computes smallest q such that q * b >= a for a >= 0 and b > 0. If a or b are out of bounds // -1 is returned. CUDA_BOTH_INLINE int CeilDivision(int a, int b) { if (a < 0 || b <= 0) return -1; return (a / b) + (a % b != 0 ? 1 : 0); // Note the assumption is that / and % are computed // as part of the same operation. } // Returns whether or not two vectors are colinear template CUDA_BOTH bool IsColinear(const Vector& a, const Vector& b) { const K dot = a.dot(b); // If dot is null, either one of the vector is null which means the two vectors are colinear, if // not then the two vectors are orthogonal so obviously not colinear. if (IsAlmostZero(dot)) { return IsAlmostZero(a.squaredNorm()) || IsAlmostZero(b.squaredNorm()); } // a.dot(b) / (||a|| * ||b||) = cos(alpha) where alpha is the angle between both vector; // Taking the square of it avoid the use of sqrt and both vector are colinear iff |cos(alpha)| = 1 return IsAlmostOne(dot * dot / (a.squaredNorm() * b.squaredNorm())); } // Returns the cross product of Vector2 defined as: // AxB = ||A||*||B||*sin(A/B); template CUDA_BOTH K CrossProduct(const Vector2& a, const Vector2& b) { return a.x() * b.y() - a.y() * b.x(); } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/optional.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) #include #else #include namespace std { using experimental::make_optional; using experimental::nullopt; using experimental::optional; } // namespace std #endif ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/tensor/sample_cloud.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/core/tensor/tensor.hpp" namespace nvidia { namespace isaac { // ------------------------------------------------------------------------------------------------- namespace sample_cloud_details { // Helper type to find the correct tensor type based on the number of channels. template struct SampleCloudImpl { using type = TensorBase, Buffer>; }; template struct SampleCloudImpl { using type = TensorBase, Buffer>; }; } // namespace sample_cloud_details // A sample cloud is identical to a (X, N) tensor. template using SampleCloudBase = typename sample_cloud_details::SampleCloudImpl::type; // ------------------------------------------------------------------------------------------------- template using SampleCloud = SampleCloudBase; template using SampleCloudView = SampleCloudBase; template using SampleCloudConstView = SampleCloudBase; #define ISAAC_DECLARE_SAMPLE_CLOUD_TYPES_IMPL(N, T, S) \ using SampleCloud##N##S = SampleCloud; \ using SampleCloudView##N##S = SampleCloudView; \ using SampleCloudConstView##N##S = SampleCloudConstView; #define ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(N) \ template \ using SampleCloud##N = SampleCloud; \ template \ using SampleCloudView##N = SampleCloudView; \ template \ using SampleCloudConstView##N = SampleCloudConstView; \ ISAAC_DECLARE_SAMPLE_CLOUD_TYPES_IMPL(N, uint8_t, ub) \ ISAAC_DECLARE_SAMPLE_CLOUD_TYPES_IMPL(N, uint16_t, ui16) \ ISAAC_DECLARE_SAMPLE_CLOUD_TYPES_IMPL(N, int, i) \ ISAAC_DECLARE_SAMPLE_CLOUD_TYPES_IMPL(N, double, d) \ ISAAC_DECLARE_SAMPLE_CLOUD_TYPES_IMPL(N, float, f) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(1) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(2) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(3) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(4) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(5) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(6) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(7) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(8) ISAAC_DECLARE_SAMPLE_CLOUD_TYPES(9) #undef ISAAC_DECLARE_SAMPLE_CLOUD_TYPES #undef ISAAC_DECLARE_SAMPLE_CLOUD_TYPES_IMPL // ------------------------------------------------------------------------------------------------- template using CudaSampleCloud = SampleCloudBase; template using CudaSampleCloudView = SampleCloudBase; template using CudaSampleCloudConstView = SampleCloudBase; #define ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES_IMPL(N, T, S) \ using CudaSampleCloud##N##S = CudaSampleCloud; \ using CudaSampleCloudView##N##S = CudaSampleCloudView; \ using CudaSampleCloudConstView##N##S = CudaSampleCloudConstView; #define ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(N) \ template \ using CudaSampleCloud##N = CudaSampleCloud; \ template \ using CudaSampleCloudView##N = CudaSampleCloudView; \ template \ using CudaSampleCloudConstView##N = CudaSampleCloudConstView; \ ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES_IMPL(N, uint8_t, ub) \ ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES_IMPL(N, uint16_t, ui16) \ ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES_IMPL(N, int, i) \ ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES_IMPL(N, double, d) \ ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES_IMPL(N, float, f) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(1) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(2) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(3) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(4) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(5) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(6) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(7) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(8) ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES(9) #undef ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES #undef ISAAC_DECLARE_CUDA_SAMPLE_CLOUD_TYPES_IMPL // ------------------------------------------------------------------------------------------------- } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/core/tensor/tensor.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include "gems/core/assert.hpp" #include "gems/core/buffers/buffer.hpp" #include "gems/core/byte.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { // ------------------------------------------------------------------------------------------------- namespace tensor { namespace details { // A compile-time sequence of integer template using int_sequence = std::integer_sequence; // Helper type to define repeated_int_sequence template struct repeated_int_sequence_impl { using type = typename repeated_int_sequence_impl::type; }; template struct repeated_int_sequence_impl<0, V, D...> { using type = int_sequence; }; // A compile-time sequence of integers which are all identical template using repeated_int_sequence = typename repeated_int_sequence_impl::type; template struct DropFirstImpl; template struct DropFirstImpl> { using type = int_sequence; }; // Compute the logical AND for a list of arguments template struct VariadicAnd : std::integral_constant::value> {}; template struct VariadicAnd : std::integral_constant {}; } // namespace details // This value can be used for tensor dimensions to indicate that the size is not fixed at compile // time and will instead be provided at runtime. We use the same value as Eigen to be compatible. constexpr int kDynamic = Eigen::Dynamic; // A compile-time list of integers used to specify tensor dimensions. template using Dimensions = details::int_sequence; // A compile-time list of integers used to specify tensor dimensions which are all dynamic. template using Rank = details::repeated_int_sequence; template using DropFirst = typename details::DropFirstImpl::type; // Gets the i-th element in an integer sequence template constexpr int IntSequenceAt(Dimensions, int i) { constexpr int arr[] = {Ints...}; return i < 0 ? 0 : arr[i]; } // Gets the last element in an integer sequence template constexpr int IntSequenceLast(Dimensions) { constexpr int arr[] = {Ints...}; return arr[sizeof...(Ints) - 1]; } // Gets a vector of dimensions based on the compile-time dimensions and the dimensions given as // arguments. If the compile-time dimension is dynamic (-1) the dimension passed as an argument // will be used instead. Otherwise the compile-time dimension must match the argument dimension. // Dimensions must not be negative with the exception of using -1 for compile-time dimensions. It is // also possible to obmit trailing argument dimensions if they are fixed at compile time. template Vector GetDimensionsVector(Args... dimensions) { constexpr int kRank = sizeof...(Dimensions); constexpr int kArgumentCount = sizeof...(Args); std::array compile_time_dimensions{Dimensions...}; // TODO(dweikersdorf) Use explicit conversion to int Vector runtime_dimensions(dimensions...); Vector result; for (int i = 0; i < kRank; i++) { if (i >= kArgumentCount) { // The dimension was not specified as an argument. Thus use the compile-time dimension ASSERT( compile_time_dimensions[i] != -1, "Dimension argument can only be obmitted if the " "dimension is specified at compile-time"); ASSERT( compile_time_dimensions[i] > 0, "Dimension argument can only be obmitted if the " "compile-time dimension is positive. Was: %d", compile_time_dimensions[i]); result[i] = compile_time_dimensions[i]; } else { // The dimension was specified as an argument. Use if it the compile-time dimension is -1. // Otherwise they both need to argree. ASSERT( compile_time_dimensions[i] == -1 || compile_time_dimensions[i] == runtime_dimensions[i], "dimension mismatch: %d vs %d", compile_time_dimensions[i], runtime_dimensions[i]); ASSERT(runtime_dimensions[i] >= 0, "dimensions must not be negative: %d", result[i]); result[i] = runtime_dimensions[i]; } } return result; } // Gets a vector of dimensions based the template parameters. For a dimension of dynamic size a // size of zero will be chosen. template Vector GetDimensionsVector() { constexpr int kRank = sizeof...(Dimensions); std::array compile_time_dimensions{Dimensions...}; Vector result; for (int i = 0; i < kRank; i++) { if (compile_time_dimensions[i] == kDynamic) { result[i] = 0; } else { ASSERT( compile_time_dimensions[i] > 0, "Compile-time dimensions must be positive or Dynamic " "Was: %d", compile_time_dimensions[i]); result[i] = compile_time_dimensions[i]; } } return result; } } // namespace tensor // ------------------------------------------------------------------------------------------------- template struct TensorBase; // A multi-dimensional array of elements. // // All elements are of the same type `K`. // // The tensor stores a multi-dimensional array of elements. The sizes of the array are specified by // the template parameter `Dimensions`. An std::integer_sequence of ints is used as type for the // list of dimensions. For each axes the dimension can either be a positive integer which indicates // a compile-time dimension or it can be `tensor::Dynamic` (which is -1) which indicates that the // dimension is specified at runtime. The template `tensor::Dimensions<...>` can be used as an alias // for `std::integer_sequence`. The template `tensor::Rank` can be used as an alias for // `std::integer_sequence`. // // Elements are stored in a buffer of type `Buffer`. Most notably buffers can either own memory or // just be a view on memory owned by someone else. Buffers can also either allow or not allow // modifications of elements. template class TensorBase, Buffer> { public: // Tensor is not allowed. Use TensorConstView instead. static_assert(!std::is_const::value, "Tensor can only be used with non-const element type"); // The integer sequence containing the sizes of the tensor using Dimensions = tensor::details::int_sequence; // The rank of the tensor is the number of its dimensions. static constexpr int kRank = sizeof...(DimensionsPack); // The rank must be greater than 0. static_assert(kRank > 0, "Rank must be at least 1"); // @deprecated static constexpr int Order = kRank; // The underlying buffer object used to store elements. using buffer_t = Buffer; // Type for mutable views on the underlying buffer using buffer_view_t = typename BufferTraits::buffer_view_t; // Type for non-mutable views on the underlying buffer using buffer_const_view_t = typename BufferTraits::buffer_const_view_t; // A mutable tensor allows modification of elements. static constexpr bool kIsMutable = BufferTraits::kIsMutable; // An owning tensor owns its memory while a non-owning memory uses memory owned by another party. static constexpr bool kIsOwning = BufferTraits::kIsOwning; // The integral type used for a single row or column index. using index_t = int; // The vector type to use for pixel coordinates. using coordinate_t = Vector; // The vector type to use for pixel dimensions. using dimensions_t = Vector; using element_t = std::remove_cv_t; using element_const_ptr_t = std::add_const_t*; using element_ptr_t = std::conditional_t; using element_const_ref_t = std::add_const_t&; using element_ref_t = std::conditional_t; using raw_const_ptr_t = std::add_const_t*; using raw_ptr_t = std::conditional_t; using tensor_view_t = TensorBase; using tensor_const_view_t = TensorBase; TensorBase() { // If no dimensions are provided set to zero. setDimensions(tensor::GetDimensionsVector()); } // Constructs a tensor with the given dimensions which owns its data. TensorBase(const dimensions_t& dimensions) { resize(dimensions, true); } template < typename... RequestedDimensionsPack, std::enable_if_t...>::value>* = nullptr> TensorBase(RequestedDimensionsPack... dimensions) : TensorBase(tensor::GetDimensionsVector(dimensions...)) {} // Constructs a tensor based on an existing buffer object using the given dimensions. This // constructor will throw if the provided buffer does not contain enough data. TensorBase(buffer_t data, const dimensions_t& dimensions) : data_(std::move(data)) { ASSERT(CheckDimensions(dimensions), "Trying to create tensor with invalid dimensions"); setDimensions(dimensions); ASSERT( data_.size() >= byte_size(), "Buffer too small: provided %zd, required %zd", data_.size(), byte_size()); } template < typename... RequestedDimensionsPack, std::enable_if_t...>::value>* = nullptr> TensorBase(buffer_t data, RequestedDimensionsPack... dimensions) : TensorBase(std::move(data), tensor::GetDimensionsVector(dimensions...)) { } // Copy construction uses the default behavior TensorBase(const TensorBase& other) = default; // Copy assignment uses the default behavior1 TensorBase& operator=(const TensorBase& other) = default; // Move construction uses the default behavior TensorBase(TensorBase&& other) { *this = std::move(other); } // Move assignment uses the default behavior TensorBase& operator=(TensorBase&& other) { data_ = std::move(other.data_); // The dimensions of the tensor. dimensions_ = other.dimensions_; offsets_ = other.offsets_; other.dimensions_.setZero(); other.offsets_.setZero(); return *this; } // Creates a mutable view on this tensor template std::enable_if_t view() { return tensor_view_t({this->data().begin(), this->data().size()}, this->dimensions()); } // Creates a non-mutable view on this tensor tensor_const_view_t const_view() const { return tensor_const_view_t({this->data().begin(), this->data().size()}, this->dimensions()); } // Provides conversion to a mutable view for owning tensors and mutable views. template operator std::enable_if_t() { return view(); } // Provides conversion to a non-mutable view operator tensor_const_view_t() const { return const_view(); } // Returns true if any dimension of this tensor is 0 and thus if the number of elements stored in // this tensor is 0. bool empty() const { return element_count() == 0; } // Returns the rank of the tensor constexpr int rank() const { return kRank; } // Deprecated - use rank() instead constexpr int order() const { return kRank; } // Returns the dimensions of the tensor dimensions_t dimensions() const { return dimensions_; } // Resizes the tensor. This operation is destructive. template std::enable_if_t resize( const dimensions_t& dimensions, bool force_reallocation = false) { // Only allocate new memory if the dimensions change. if (force_reallocation || dimensions != dimensions_) { ASSERT(CheckDimensions(dimensions), "Invalid dimensions"); setDimensions(dimensions); data_ = buffer_t(byte_size()); } } // Similar as `resize` but takes dimensions individually without using the vector type. template < typename... RequestedDimensionsPack, bool X = kIsMutable, std::enable_if_t* = nullptr> void resize(RequestedDimensionsPack... requested_dimensions) { return resize(tensor::GetDimensionsVector(requested_dimensions...)); } // Returns true if the element coordinate is within the tensor's dimension bool isValidCoordinate(const coordinate_t& indicies) const { return (indicies.array() >= 0).all() && (indicies.array() < dimensions_.array()).all(); } // Helper wrappers for isValidCoordinate for the most common orders of tensors template * = nullptr> bool isValidCoordinate(Args... indices) const { return isValidCoordinate(coordinate_t(indices...)); // TODO(dweikersdorf) Use explict casts } // Accesses the given index in the tensor with respect to memory ordering template ::value> std::enable_if_t operator()(const coordinate_t& indicies) const { return *(this->element_wise_begin() + indexToOffset(indicies)); } // Accesses the given index in the tensor with respect to memory ordering template ::value> std::enable_if_t operator()(const coordinate_t& indicies) const { return *(this->element_wise_begin() + indexToOffset(indicies)); } // Accesses the given index in the tensor with respect to memory ordering template std::enable_if_t operator()(const coordinate_t& indicies) { return *(this->element_wise_begin() + indexToOffset(indicies)); } // Helper wrappers for operator access for the most common orders of tensors template < typename... Args, std::enable_if_t::value>* = nullptr> element_t operator()(Args... indices) const { return operator()(coordinate_t(indices...)); // TODO(dweikersdorf) Use explict casts } // Helper wrappers for operator access for the most common orders of tensors template < typename... Args, std::enable_if_t::value>* = nullptr> element_const_ref_t operator()(Args... indices) const { return operator()(coordinate_t(indices...)); // TODO(dweikersdorf) Use explict casts } // Helper wrappers for operator access for the most common orders of tensors template * = nullptr> element_ref_t operator()(Args... indices) { return operator()(coordinate_t(indices...)); // TODO(dweikersdorf) Use explict casts } // Creates a view on a slice with one dimension less. The dimension with highest significance // is sliced. template = 2> std::enable_if_t, buffer_view_t>> slice( index_t index) { using slice_t = TensorBase, buffer_view_t>; const size_t slice_size = static_cast(offsets_[0]) * sizeof(K); const size_t slice_offset = static_cast(index) * slice_size; return slice_t( buffer_view_t{this->data().begin() + slice_offset, slice_size}, this->dimensions().template segment(1).eval()); } template = 2> std::enable_if_t, buffer_const_view_t>> slice( index_t index) { return const_slice(index); } // Creates a const view on a slice with one dimension less. The dimension with highest // significance is sliced. template = 2> std::enable_if_t, buffer_const_view_t>> const_slice(index_t index) const { using const_slice_t = TensorBase, buffer_const_view_t>; const size_t slice_size = static_cast(offsets_[0]) * sizeof(K); const size_t slice_offset = static_cast(index) * slice_size; return const_slice_t( buffer_const_view_t{this->data().begin() + slice_offset, slice_size}, this->dimensions().template segment(1).eval()); } // Helper types for Eigen matrix-style access static constexpr int kBackDim2 = tensor::IntSequenceAt(Dimensions{}, kRank - 2); static constexpr int kBackDim1 = tensor::IntSequenceAt(Dimensions{}, kRank - 1); using matrix_view_t = Eigen::Map>; using matrix_const_view_t = Eigen::Map>; using vector_view_t = Eigen::Map>; using vector_const_view_t = Eigen::Map>; // Returns a mutable Eigen matrix view sliced on the last two dimensions template < typename... Args, std::enable_if_t* = nullptr> matrix_view_t matrix(Args... indices) { return matrix_view_t( this->element_wise_begin() + indexToOffset(coordinate_t(indices..., 0, 0)), dimensions_[kRank - 2], dimensions_[kRank - 1]); } // Returns a non-mutable Eigen matrix view sliced on the last two dimensions template * = nullptr> matrix_const_view_t matrix(Args... indices) const { return matrix_const_view_t( this->element_wise_begin() + indexToOffset(coordinate_t(indices..., 0, 0)), dimensions_[kRank - 2], dimensions_[kRank - 1]); } // Returns a mutable Eigen vector view sliced on the last dimension template < typename... Args, std::enable_if_t* = nullptr> vector_view_t matrix(Args... indices) { return vector_view_t( this->element_wise_begin() + indexToOffset(coordinate_t(indices..., 0)), dimensions_[kRank - 1]); } // Returns a non-mutable Eigen vector view sliced on the last dimension template * = nullptr> vector_const_view_t matrix(Args... indices) const { return vector_const_view_t( this->element_wise_begin() + indexToOffset(coordinate_t(indices..., 0)), dimensions_[kRank - 1]); } // When indices are omitted in operator() access it behaves the same as `matrix()`. template < typename... Args, std::enable_if_t< (sizeof...(Args) == kRank - 2 || sizeof...(Args) == kRank - 1) && kIsMutable>* = nullptr> auto operator()(Args... indices) { return matrix(indices...); } // When indices are omitted in operator() access it behaves the same as `matrix()`. template < typename... Args, std::enable_if_t* = nullptr> auto operator()(Args... indices) const { return matrix(indices...); } // Const Pointer to the beginning of the data block element_const_ptr_t element_wise_begin() const { return reinterpret_cast(data_.begin()); } // Pointer to the beginning of the data block element_ptr_t element_wise_begin() { return reinterpret_cast(data_.begin()); } // Const Pointer to the beginning of the data block element_const_ptr_t element_wise_end() const { return reinterpret_cast(data_.end()); } // Pointer to the beginning of the data block element_ptr_t element_wise_end() { return reinterpret_cast(data_.end()); } // The total number of elements in the tensor index_t num_elements() const { return offsets_[0] * dimensions_[0]; } // @deprecated int element_count() const { return num_elements(); } // Returns a non mutable reference pixel holder at the position `index`. element_const_ref_t operator[](index_t index) const { return this->element_wise_begin()[index]; } // Returns a mutable reference pixel holder at the position `index`. template std::enable_if_t operator[](index_t index) { return this->element_wise_begin()[index]; } // const access to the underlying buffer object const buffer_t& data() const { return data_; } // access to the underlying buffer object template std::enable_if_t data() { return data_; } // The total numbe of bytes required to store the tensor size_t byte_size() const { return static_cast(element_count()) * sizeof(element_t); } private: // Returns true if all dimensions are greater than zero or zero static bool CheckDimensions(const dimensions_t& dimensions) { return (dimensions.array() >= 0).all(); } // Sets the dimensions of the tensor and updates offsets. void setDimensions(const dimensions_t& dimensions) { dimensions_ = dimensions; offsets_[kRank - 1] = 1; // Rank is guaranteed to be positive for (int i = kRank - 1; i > 0; i--) { offsets_[i - 1] = offsets_[i] * dimensions_[i]; } } // Computes the position of an element based on its coordinate. int indexToOffset(const coordinate_t& indices) const { return offsets_.dot(indices); } // storage for the tensor buffer_t data_; // The dimensions of the tensor. dimensions_t dimensions_; // Dimension offsets for indexing rows of storage dimensions_t offsets_; }; // namespace isaac // ------------------------------------------------------------------------------------------------- template using CpuTensor = TensorBase, CpuBuffer>; template using CpuTensorView = TensorBase, CpuBufferView>; template using CpuTensorConstView = TensorBase, CpuBufferConstView>; #define ISAAC_DECLARE_CPU_TENSOR_TYPES_IMPL(N, T, S) \ using CpuTensor##N##S = CpuTensor; \ using CpuTensorView##N##S = CpuTensorView; \ using CpuTensorConstView##N##S = CpuTensorConstView; #define ISAAC_DECLARE_CPU_TENSOR_TYPES(N) \ template \ using CpuTensor##N = CpuTensor; \ template \ using CpuTensorView##N = CpuTensorView; \ template \ using CpuTensorConstView##N = CpuTensorConstView; \ ISAAC_DECLARE_CPU_TENSOR_TYPES_IMPL(N, uint8_t, ub) \ ISAAC_DECLARE_CPU_TENSOR_TYPES_IMPL(N, uint16_t, ui16) \ ISAAC_DECLARE_CPU_TENSOR_TYPES_IMPL(N, int, i) \ ISAAC_DECLARE_CPU_TENSOR_TYPES_IMPL(N, double, d) \ ISAAC_DECLARE_CPU_TENSOR_TYPES_IMPL(N, float, f) ISAAC_DECLARE_CPU_TENSOR_TYPES(1) ISAAC_DECLARE_CPU_TENSOR_TYPES(2) ISAAC_DECLARE_CPU_TENSOR_TYPES(3) ISAAC_DECLARE_CPU_TENSOR_TYPES(4) #undef ISAAC_DECLARE_CPU_TENSOR_TYPES #undef ISAAC_DECLARE_CPU_TENSOR_TYPES_IMPL // ------------------------------------------------------------------------------------------------- // An Tensor stored in device memory which owns it's memory template using GpuTensor = TensorBase, CudaBuffer>; // A mutable view on an Tensor which is stored on GPU device memory, does not own memory, but can // be used to read and write the data of the underlying Tensor. template using GpuTensorView = TensorBase, CudaBufferView>; // A non-mutable view on an Tensor which is stored on GPU device memory, does not own its memory, // and can only be used to read the data of the underlying Tensor. template using GpuTensorConstView = TensorBase, CudaBufferConstView>; // Helper macro for ISAAC_DECLARE_CUDA_TENSOR_TYPES #define ISAAC_DECLARE_CUDA_TENSOR_TYPES_IMPL(N, K, S) \ using GpuTensor##N##S = GpuTensor; \ using GpuTensorView##N##S = GpuTensorView; \ using GpuTensorConstView##N##S = GpuTensorConstView; // Helper macro to define various GpuTensor types #define ISAAC_DECLARE_CUDA_TENSOR_TYPES(N) \ template \ using GpuTensor##N = GpuTensor; \ template \ using GpuTensorView##N = GpuTensorView; \ template \ using GpuTensorConstView##N = GpuTensorConstView; \ ISAAC_DECLARE_CUDA_TENSOR_TYPES_IMPL(N, uint8_t, ub) \ ISAAC_DECLARE_CUDA_TENSOR_TYPES_IMPL(N, uint16_t, ui16) \ ISAAC_DECLARE_CUDA_TENSOR_TYPES_IMPL(N, int, i) \ ISAAC_DECLARE_CUDA_TENSOR_TYPES_IMPL(N, double, d) \ ISAAC_DECLARE_CUDA_TENSOR_TYPES_IMPL(N, float, f) ISAAC_DECLARE_CUDA_TENSOR_TYPES(1) ISAAC_DECLARE_CUDA_TENSOR_TYPES(2) ISAAC_DECLARE_CUDA_TENSOR_TYPES(3) ISAAC_DECLARE_CUDA_TENSOR_TYPES(4) #undef ISAAC_DECLARE_CUDA_TENSOR_TYPES #undef ISAAC_DECLARE_CUDA_TENSOR_TYPES_IMPL // ------------------------------------------------------------------------------------------------- // Creates a CpuTensorView instance from a raw host `data` pointer that allows to alter the data // pointed to, although it will still be owned by the entity that allocated it originally. The // `elements` parameter denotes the number of elements contained within `data`. The `shape` // parameter is a `Vector` with `N` being the tensor's rank. Its elements are the dimensions // of the tensor. The template parameters denote the variable type the CpuTensorView should // represent and the rank of the tensor. template CpuTensorView CreateCpuTensorViewFromData( K* data, size_t elements, const Vector& shape) { return CpuTensorView( CpuBufferView(HostPointer(reinterpret_cast(data)), sizeof(K) * elements), shape); } // Creates a TensorConstView instance from a raw host `data` pointer. The data pointed to will still // be owned by the entity that allocated it originally. The `elements` parameter denotes the number // of elements contained within `data`. The `shape` parameter is a `Vector` with `N` being // the tensor's rank. Its elements are the dimensions of the tensor. The template parameters denote // the variable type the CpuTensorView should represent and the rank of the tensor. template CpuTensorConstView CreateCpuTensorConstViewFromData( const K* data, size_t elements, const Vector& shape) { return CpuTensorConstView( CpuBufferConstView( HostPointer(reinterpret_cast(data)), sizeof(K) * elements), shape); } // Creates a GpuTensorView instance from a raw device `data` pointer that allows to alter the data // pointed to, although it will still be owned by the entity that allocated it originally. The // `elements` parameter denotes the number of elements contained within `data`. The `shape` // parameter is a `Vector` with `N` being the tensor's rank. Its elements are the dimensions // of the tensor. The template parameters denote the variable type the TensorView should represent // and the rank of the tensor. template GpuTensorView CreateGpuTensorViewFromData( T* data, size_t elements, const Vector& shape) { return GpuTensorView( CudaBufferView(CudaPointer(reinterpret_cast(data)), sizeof(K) * elements), shape); } // Creates a GpuTensorConstView instance from a raw device `data` pointer. The data pointed to // will still be owned by the entity that allocated it originally.The `elements` parameter // denotes the number of elements contained within `data`. The `shape` parameter is a // `Vector` with `N` being the tensor's rank. Its elements are the dimensions of the // tensor. The template parameters denote the variable type the TensorView should represent and // the rank of the tensor. template GpuTensorConstView CreateGpuTensorConstViewFromData( const T* data, size_t elements, const Vector& shape) { return GpuTensorConstView( CudaBufferConstView( CudaPointer(reinterpret_cast(data)), sizeof(K) * elements), shape); } // ------------------------------------------------------------------------------------------------- } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/cuda_utils/launch_utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "cuda_runtime.h" namespace nvidia { namespace isaac { // Computes a positive integer x such that (x - 1) * b < a <= x * b template T DivRoundUp(T a, T b) { return (a + b - T{1}) / b; } // Same as DivRoundUp but for all three elements. This is for example useful in computing // launch parameters for CUDA kernels. inline dim3 DivRoundUp(dim3 a, dim3 b) { return { DivRoundUp(a.x, b.x), DivRoundUp(a.y, b.y), DivRoundUp(a.z, b.z) }; } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/cuda_utils/stride_pointer.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "cuda_runtime.h" namespace nvidia { namespace isaac { // A CUDA-friendly pointer with a stride. Can be used to work with data which uses a grid layout // with a non non-trivial offset between rows. This means rows are longer than they would need to be // in order to enable higher performance. template struct StridePointer { // Pointer to the first element K* pointer; // Offset in bytes between consecutive rows. size_t stride; // Gets a pointer to the given row inline __host__ __device__ K* row_pointer(int row) const { // TODO Properly cast pointer using reinterpret_cast with either char* or const char* return reinterpret_cast((char*)(pointer) + row * stride); // NOLINT } // Accesses the element at the coordinate (row, col) inline __host__ __device__ const K& at(int row, int col) const { return row_pointer(row)[col]; } // Accesses the element at the coordinate (row, col) inline __host__ __device__ K& at(int row, int col) { return row_pointer(row)[col]; } // Accesses the element at the given coordinates inline __host__ __device__ const K& at(int2 coordinates) const { return at(coordinates.x, coordinates.y); } // Accesses the element at the given coordinates inline __host__ __device__ K& at(int2 coordinates) { return at(coordinates.x, coordinates.y); } // Identical to `at` inline __host__ __device__ const K& operator()(int row, int col) const { return row_pointer(row)[col]; } // Identical to `at` inline __host__ __device__ K& operator()(int row, int col) { return row_pointer(row)[col]; } // Identical to `at` inline __host__ __device__ const K& operator()(int2 coordinates) const { return at(coordinates.x, coordinates.y); } // Identical to `at` inline __host__ __device__ K& operator()(int2 coordinates) { return at(coordinates.x, coordinates.y); } // Casts to a given element type. This can for example be used to cast between a // StridePointer used on the CPU and a StridePointer used on the GPU. template __host__ __device__ StridePointer cast() const { return {reinterpret_cast(pointer), stride}; } }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/cuda_utils/stride_pointer_3d.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "cuda_runtime.h" namespace nvidia { namespace isaac { // TODO(kchinniah): move memory layout & shape defns inside StridePointer3D class // TODO(kpatzwaldt): merge all the multidimensional indexing methods (ISAFETY-1363) /// The memory layout of a 3D pointer enum class StridePointer3D_MemoryLayout { kNCHW, ///< batch_size x channel x height x width kHWC, ///< height x width x channel kNHWC, ///< batch_size x height x width x channel }; /// The shape of a 3D pointer struct StridePointer3D_Shape { /// The height uint32_t height{}; /// The width uint32_t width{}; /// The number of channels uint32_t channels{}; }; // A stride pointer that's suitable for indexing 3D data. // In particular, this is useful for processing tensors. // If no strides are specified, the strides are computed assuming no offsets / padding. // WARNING: the NCHW and NHWC drop the N (batch size) dimension, hence // assuming that the batch size is 1. // and are only included to make converting tensors easier. // Additionally, this pointer does not have ownership of the passed pointer // Access to this must be given as: (row, col, depth) or (height, width, channel) // Bound checking is responsible on the caller of the methods of this class template class StridePointer3D { private: /// The maximum allowable dimension static constexpr size_t kMaxDims{3}; // Ensure that the received data has a size greater than 0 static_assert(sizeof(T) > 0, "Error: received type who's size is 0"); public: StridePointer3D() : memory_buffer_{nullptr}, shape_{}, memory_layout_{}, strides_{0, 0, 0} {} /** Creates a 3D Stride Pointer using the raw memory, shape and memory layout specified. This will compute trivial strides for the strides @param T The type of the memory buffer @param memory_buffer The memory buffer that will be traversed @param shape The shape of the memory buffer @param memory_layout The memory layout of the memory buffer **/ StridePointer3D( T* memory_buffer, StridePointer3D_Shape shape, StridePointer3D_MemoryLayout memory_layout) : memory_buffer_{memory_buffer}, shape_{shape}, memory_layout_{memory_layout} { computeStrides(); setStrideIndices(); } /** Creates a 3D Stride Pointer using the raw memory, shape, memory layout and strides specified. The provided strides must be given in terms of bytes. These will be divided by sizeof(T) for indexing The byte_strides must be formatted as: - byte_strides[2] = The amount of bytes necessary to traverse one unit of the least significant dim - byte_strides[1] = The amount of bytes necessary to traverse one unit of the 2nd least significant dim - byte_strides[0] = The amount of bytes necessary to traverse one unit of the 3rd least significant dim For example, suppose the memory layout is MemoryLayout::kHWC and that there is no extra padding or offsets, - byte_strides[2] should be sizeof(T) since it requires sizeof(T) units to traverse along the channel axis - byte_strides[1] should be sizeof(T) * shape.channels since this is the amount of bytes required to traverse along the width axis - For example, if there are 3 channels and sizeof(T) = 1, then to go from width = 0 -> width = 1 requires traversal of 3 units - byte_strides[0] should be sizeof(T) * shape.channels * shape.width since this is the amount of bytes required to traverse along the height axis - For example, if there are 3 channels, sizeof(T) = 1 and the width is 5, then to go from width = 0 -> 1 requires sizeof(T) * 3 channels, then since we would like to traverse from height 0 -> height 1, we must traverse 5 widths worth of memory, hence sizeof(T) * 3 channels * 5 width units is required @param T The type of the memory buffer @param memory_buffer The memory buffer that will be traversed @param shape The shape of the memory buffer @param memory_layout The memory layout of the memory buffer @param byte_strides The strides of each dimension in bytes **/ StridePointer3D( T* memory_buffer, StridePointer3D_Shape shape, StridePointer3D_MemoryLayout memory_layout, const std::array& byte_strides) : memory_buffer_{memory_buffer}, shape_{shape}, memory_layout_{memory_layout} { for (size_t i = 0; i < kMaxDims; ++i) { strides_[i] = byte_strides[i] / sizeof(T); } setStrideIndices(); } /** This is identical to the std::array version of the constructor **/ StridePointer3D( T* memory_buffer, StridePointer3D_Shape shape, StridePointer3D_MemoryLayout memory_layout, size_t byte_strides[kMaxDims]) : memory_buffer_{memory_buffer}, shape_{shape}, memory_layout_{memory_layout} { for (size_t i = 0; i < kMaxDims; ++i) { strides_[i] = byte_strides[i] / sizeof(T); } setStrideIndices(); } /** Returns a mutable reference at the specified (row, col, depth). NOTE: (row, col, depth) corresponds to (height, width, channel) indexing WARNING: this method does not do bounds checking @param row The row (height) index @param col The column (width) index @param depth The depth (channel) index **/ __device__ __host__ T& operator()(uint32_t row, uint32_t col, uint32_t depth) { return memory_buffer_[computeFlattenedIndex(row, col, depth)]; } /** Returns a mutable reference at the specified (row, col). This assumes the depth is 0. This is useful for processing, grayscale images, for example NOTE: (row, col) corresponds to (height, width) indexing WARNING: this method does not do bounds checking @param row The row (height) index @param col The column (width) index **/ __device__ __host__ T& operator()(uint32_t row, uint32_t col) { return memory_buffer_[computeFlattenedIndex(row, col, 0)]; } /** Returns a constant reference at the specified (row, col, depth). NOTE: (row, col, depth) corresponds to (height, width, channel) indexing WARNING: this method does not do bounds checking @param row The row (height) index @param col The column (width) index @param depth The depth (channel) index **/ __device__ __host__ const T& operator()(uint32_t row, uint32_t col, uint32_t depth) const { return memory_buffer_[computeFlattenedIndex(row, col, depth)]; } /** Returns a constant reference at the specified (row, col). This assumes the depth is 0. This is useful for processing, grayscale images, for example WARNING: this method does not do bounds checking NOTE: (row, col) corresponds to (height, width) indexing @param row The row (height) index @param col The column (width) index **/ __device__ __host__ const T& operator()(uint32_t row, uint32_t col) const { return memory_buffer_[computeFlattenedIndex(row, col, 0)]; } /// Returns the memory layout __device__ __host__ StridePointer3D_MemoryLayout memory_layout() const { return memory_layout_; } /// Returns the shape __device__ __host__ StridePointer3D_Shape shape() const { return shape_; } /// Returns the memory buffer __device__ __host__ T* pointer() const { return memory_buffer_; } /** Returns the memory buffer at the specified (row, col, depth). NOTE: (row, col, depth) corresponds to (height, width, channel) indexing WARNING: this method does not do bounds checking @param row The row (height) index @param col The column (width) index @param depth The depth (channel) index **/ __device__ __host__ T* pointerAt(uint32_t row, uint32_t col, uint32_t depth) const { return memory_buffer_ + computeFlattenedIndex(row, col, depth); } /** Returns the memory buffer at the specified (row, col). This assumes the depth is 0. This is useful for processing, grayscale images, for example NOTE: (row, col) corresponds to (height, width) indexing WARNING: this method does not do bounds checking @param row The row (height) index @param col The column (width) index **/ __device__ __host__ T* pointerAt(uint32_t row, uint32_t col) const { return memory_buffer_ + computeFlattenedIndex(row, col, 0); } /** Returns the flattened index at the specified (row, col, depth). NOTE: (row, col, depth) corresponds to (height, width, channel) indexing @param row The row (height) index @param col The column (width) index @param depth The depth (channel) index **/ __device__ __host__ size_t indexAt(uint32_t row, uint32_t col, uint32_t depth) const { return computeFlattenedIndex(row, col, depth); } /** Returns the flattened index at the specified (row, col). This assumes the depth is 0. This is useful for processing, grayscale images, for example NOTE: (row, col) corresponds to (height, width) indexing @param row The row (height) index @param col The column (width) index **/ __device__ __host__ size_t indexAt(uint32_t row, uint32_t col) const { return computeFlattenedIndex(row, col, 0); } private: /// The raw memory buffer T* memory_buffer_{}; /// The shape of the memory buffer StridePointer3D_Shape shape_{}; /// The memory layout of the memory buffer StridePointer3D_MemoryLayout memory_layout_; /// The stride size_t strides_[kMaxDims]; /// Maps a dimension to the stride array struct StrideIndexMapping { /// The height index mapping size_t height_idx{}; /// The width index mapping size_t width_idx{}; /// The channel index mapping size_t channel_idx{}; } stride_index_mapping_; /** Computes the strides of the data based on the memory layout, assuming no extra memory offset or padding NOTE: the strides are divided by sizeof(T). This is why, for example, strides_[2] = 1 The computed strides can be interpreted as follows: - strides_[2] -> the stride required to traverse along the least significant dimension - strides_[1] -> the stride required to traverse along the 2nd least significant dimension - strides_[0] -> the stride required to traverse along the 3rd least significant dimension **/ void computeStrides() { switch (memory_layout_) { case StridePointer3D_MemoryLayout::kNHWC: case StridePointer3D_MemoryLayout::kHWC: strides_[2] = 1; strides_[1] = shape_.channels * strides_[2]; strides_[0] = shape_.width * strides_[1]; break; case StridePointer3D_MemoryLayout::kNCHW: strides_[2] = 1; strides_[1] = shape_.width * strides_[2]; strides_[0] = shape_.height * strides_[1]; break; } } /** Sets the index stride mapping based on the memory layout. For NHWC and HWC, this is height = 0, width = 1, channel = 2 For NCHW, this is channel = 0, width = 1, height = 2 **/ void setStrideIndices() { switch (memory_layout_) { case StridePointer3D_MemoryLayout::kNHWC: case StridePointer3D_MemoryLayout::kHWC: stride_index_mapping_.height_idx = 0; stride_index_mapping_.width_idx = 1; stride_index_mapping_.channel_idx = 2; break; case StridePointer3D_MemoryLayout::kNCHW: stride_index_mapping_.channel_idx = 0; stride_index_mapping_.height_idx = 1; stride_index_mapping_.width_idx = 2; break; } } /** Flattens a 3 dimensional index into a 1 dimension one @param row The row (height) index @param col the col (width) index @param depth The depth (channel) index **/ __device__ __host__ size_t computeFlattenedIndex(uint32_t row, uint32_t col, uint32_t depth) const { return row * strides_[stride_index_mapping_.height_idx] + col * strides_[stride_index_mapping_.width_idx] + depth * strides_[stride_index_mapping_.channel_idx]; } }; #define ISAAC_DECLARE_STRIDE_POINTER_3D_TYPES(T, S) using StridePointer3D##S = StridePointer3D; ISAAC_DECLARE_STRIDE_POINTER_3D_TYPES(uint8_t, ub) ISAAC_DECLARE_STRIDE_POINTER_3D_TYPES(uint16_t, ui16) ISAAC_DECLARE_STRIDE_POINTER_3D_TYPES(int, i) ISAAC_DECLARE_STRIDE_POINTER_3D_TYPES(double, d) ISAAC_DECLARE_STRIDE_POINTER_3D_TYPES(float, f) #undef ISAAC_DECLARE_STRIDE_POINTER_3D_TYPES } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/cuda_utils/vector_math.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2019-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "cuda_runtime.h" namespace nvidia { namespace isaac { inline __host__ __device__ float3 operator-(const float3& a, const float3& b) { return make_float3(a.x - b.x, a.y - b.y, a.z - b.z); } inline __host__ __device__ float2 operator-(const float2& a, const float2& b) { return make_float2(a.x - b.x, a.y - b.y); } inline __host__ __device__ float2 operator-(const float2& a, const int2& b) { return make_float2(a.x - static_cast(b.x), a.y - static_cast(b.y)); } inline __host__ __device__ float2 operator-(const int2& a, const float2& b) { return make_float2(static_cast(a.x) - b.x, static_cast(a.y) - b.y); } inline __host__ __device__ int3 operator-(const int3& a, const int3& b) { return make_int3(a.x - b.x, a.y - b.y, a.z - b.z); } inline __host__ __device__ int2 operator-(const int2& a, const int2& b) { return make_int2(a.x - b.x, a.y - b.y); } inline __host__ __device__ float3 operator+(const float3& a, const float3& b) { return make_float3(a.x + b.x, a.y + b.y, a.z + b.z); } inline __host__ __device__ float2 operator+(const float2& a, const float2& b) { return make_float2(a.x + b.x, a.y + b.y); } inline __host__ __device__ int2 operator+(const int2& a, const int2& b) { return make_int2(a.x + b.x, a.y + b.y); } inline __host__ __device__ float3 operator*(const float3& a, const float& s) { return make_float3(s*a.x, s*a.y, s*a.z); } inline __host__ __device__ float3 operator*(const float& s, const float3& a) { return make_float3(s*a.x, s*a.y, s*a.z); } inline __host__ __device__ float2 operator*(const float2& a, const float& s) { return make_float2(s*a.x, s*a.y); } inline __host__ __device__ float2 operator*(const float& s, const float2& a) { return make_float2(s*a.x, s*a.y); } // Coeffient-wise multiplication for two 3-vectors inline __host__ __device__ float3 CwiseMult(const float3& a, const float3& b) { return make_float3(a.x*b.x, a.y*b.y, a.z*b.z); } // Dot product for two float3 vectors inline __host__ __device__ float Dot(const float3& a, const float3 b) { return a.x*b.x + a.y*b.y + a.z*b.z; } // Dot product for two float2 vectors inline __host__ __device__ float Dot(const float2& a, const float2 b) { return a.x*b.x + a.y*b.y; } // Dot product for two int3 vectors inline __host__ __device__ int Dot(const int3& a, const int3& b) { return a.x*b.x + a.y*b.y + a.z*b.z; } // Dot product for two int2 vectors inline __host__ __device__ int Dot(const int2& a, const int2& b) { return a.x*b.x + a.y*b.y; } // Cross product for two float3 vectors inline __host__ __device__ float3 Cross(const float3& a, const float3 b) { return make_float3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); } // Square of 2-norm for a float3 vector inline __host__ __device__ float SquareNorm(const float3& a) { return Dot(a, a); } // Square of 2-norm for a int3 vector inline __host__ __device__ int SquareNorm(const int3& a) { return Dot(a, a); } // Square of 2-norm for a float2 vector inline __host__ __device__ float SquareNorm(const float2& a) { return Dot(a, a); } // 2-norm for a float3 vector inline __host__ __device__ float Norm(const float3& a) { return sqrtf(SquareNorm(a)); } // 2-norm for a float2 vector inline __host__ __device__ float Norm(const float2& a) { return sqrtf(SquareNorm(a)); } // Coefficient-wise sum for a float3 vector inline __host__ __device__ float Sum(const float3& a) { return a.x + a.y + a.z; } inline __host__ __device__ int2 Floorf(const float2& a) { return make_int2(floorf(a.x), floorf(a.y)); } // Coefficient-wise conversion to int for a uchar3 vector inline __host__ __device__ int3 ToInt(uchar3 a) { return make_int3(static_cast(a.x), static_cast(a.y), static_cast(a.z)); } // Coefficient-wise conversion to float for a int3 vector inline __host__ __device__ float3 ToFloat(int3 a) { return make_float3(static_cast(a.x), static_cast(a.y), static_cast(a.z)); } // Coefficient-wise conversion to float for a int2 vector inline __host__ __device__ float2 ToFloat(int2 a) { return make_float2(static_cast(a.x), static_cast(a.y)); } // Accesses the index-th element of a float4 vector. Assumes index = 0 if index not in {0, 1, 2, 3}. inline __device__ float& Coefficient(float4& a, int index) { if (index == 0) return a.x; else if (index == 1) return a.y; else if (index == 2) return a.z; else if (index == 3) return a.w; else return a.x; // NOLINT } // Accesses the index-th element of a short4 vector. Assumes index = 0 if index not in {0, 1, 2, 3}. inline __device__ short& Coefficient(short4& a, int index) { // NOLINT if (index == 0) return a.x; else if (index == 1) return a.y; else if (index == 2) return a.z; else if (index == 3) return a.w; else return a.x; // NOLINT } // Rotate a float2 unit vector by another float2 vector. The vector elements represent the cos and // sin of the rotation angle of the vector. inline __host__ __device__ float2 Rotate(const float2& a, const float2& b) { return make_float2(a.x * b.x - a.y * b.y, a.y * b.x + a.x * b.y); } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/flatscan/flatscan_info.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once namespace nvidia { namespace isaac { // Data structure holding meta information about flatscan messages. Every flatscan message must // contain an instance of this message. struct FlatscanInfo { // If the beam free range end is greater than or equal to this value the beam did not hit an // obstacle at the end of the free range. double out_of_range; // Horizontal width of every beam in radians. double beam_width; // The lower z value of the height slice. double height_min; // The upper z value of the height slice. double height_max; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/flatscan/flatscan_types.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/composite/composite_view.hpp" #include "gems/composite/schema.hpp" namespace nvidia { namespace isaac { // Describes each beam in a flatscan struct FlatscanIndices { enum { // Angle of the beam kAngle, // Start of the free range kRangeStart, // End of the free range kRangeEnd, // Visibility range of the flat ray, e.g., the furthest distance the ray could reach within // the height slice without any obstacles kVisibilityRange, // The relative time for this beam to the message timestamp, unit in seconds // beam_absolute_time = message_time + relative_time kRelativeTime, kSize }; }; inline composite::Schema FlatscanCompositeSchema() { return composite::Schema({ composite::Quantity::Scalar("angle", composite::Measure::kRotation), composite::Quantity::Scalar("range_start", composite::Measure::kPosition), composite::Quantity::Scalar("range_end", composite::Measure::kPosition), composite::Quantity::Scalar("visibility_range", composite::Measure::kPosition), composite::Quantity::Scalar("relative_time", composite::Measure::kTime), }); } template struct FlatscanImmutableInterface : public Base { using Base::Base; using Base::operator=; K angle() const { return get(*this); } K range_start() const { return get(*this); } K range_end() const { return get(*this); } K visibility_range() const { return get(*this); } K relative_time() const { return get(*this); } }; template struct FlatscanMutableInterface : public FlatscanImmutableInterface { using FlatscanImmutableInterface::FlatscanImmutableInterface; using FlatscanImmutableInterface::operator=; K& angle() { return get(*this); } K& range_start() { return get(*this); } K& range_end() { return get(*this); } K& visibility_range() { return get(*this); } K& relative_time() { return get(*this); } }; template using FlatscanConstView = CompositeConstView; template using FlatscanView = CompositeView; template using Flatscan = Composite; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/line.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/math/types.hpp" #include "gems/core/math/utils.hpp" namespace nvidia { namespace isaac { namespace geometry { // Represent a line in dimension N. // The line is defined with a point and a ray. If IsFullLine is set to false then the line is a // half line starting from the origin and in the direction of the ray. template class Line { public: // Type of a point. using Vector_t = Vector; using Scalar = K; constexpr static int kDimension = N; // Empty constructor to allow allocation Line() {} // Helper to create a direction from a point and a direction. static Line FromDirection(const Vector_t& pt, const Vector_t& direction) { return Line{pt, direction}; } // Helper to create a direction from two points. static Line FromPoints(const Vector_t& a, const Vector_t& b) { return Line{a, b-a}; } // Returns a point on the line. const Vector_t& origin() const { return origin_; } // Returns the direction starting from the extremity 'origin'. const Vector_t& direction() const { return direction_; } // Clamp the value of lambda such as origin() + lambda * direction() belong on the Line. K clamp(K lambda) const { if (IsFullLine) { return lambda; } else { return std::max(K(0), lambda); } } // Casts to a different type template ::value, int> = 0> Line cast() const { return Line::FromDirection( origin_.template cast(), direction_.template cast()); } template::value, int> = 0> const Line& cast() const { // Nothing to do as the type does not change return *this; } private: // Private constructor to avoid confusion between direction initialization and points // initialization. Use FromDirection or FromPoints to create a line. Line(const Vector_t& origin, const Vector_t& direction) : origin_(origin), direction_(direction) { ASSERT(!IsAlmostZero(direction.squaredNorm()), "direction must not be null"); } Vector_t origin_; Vector_t direction_; }; using Line2d = Line; using Line3d = Line; using Line4d = Line; using Line2f = Line; using Line3f = Line; using Line4f = Line; using Ray2d = Line; using Ray3d = Line; using Ray4d = Line; using Ray2f = Line; using Ray3f = Line; using Ray4f = Line; } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/line_segment.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/core/math/types.hpp" #include "gems/core/math/utils.hpp" namespace nvidia { namespace isaac { namespace geometry { // Represent a segment in dimension N. // The segment is defined with a couple of points (both extremities). template class LineSegment { public: // Type of a point. using Vector_t = Vector; using Scalar = K; constexpr static int kDimension = N; // Empty constructor to allow allocation. LineSegment() {} // Constructor. LineSegment(const Vector_t& a, const Vector_t& b) : a_(a), b_(b) { } // Helper to create a segment from two points. static LineSegment FromPoints(const Vector_t& a, const Vector_t& b) { return LineSegment{a, b}; } // Returns one extremity such as origin() + direction() == the other extremity. const Vector_t& origin() const { return a_; } // Returns the direction starting from the extremity 'origin'. const Vector_t direction() const { return b_ - a_; } // Returns one extremity of the segment. const Vector_t& a() const { return a_; } // Returns one extremity of the segment. Vector_t& a() { return a_; } // Returns the other extremity of the segment. const Vector_t& b() const { return b_; } // Returns the other extremity of the segment. Vector_t& b() { return b_; } // Clamp the value of lambda such as origin() + lambda * direction() belong on the LineSegment. K clamp(K lambda) const { return lambda <= K(0) ? K(0) : (lambda < K(1) ? lambda : K(1)); } // Casts to a different type template ::value, int> = 0> LineSegment cast() const { return LineSegment(a_.template cast(), b_.template cast()); } template::value, int> = 0> const LineSegment& cast() const { // Nothing to do as the type does not change return *this; } private: Vector_t a_; Vector_t b_; }; using LineSegment2i = LineSegment; using LineSegment3i = LineSegment; using LineSegment4i = LineSegment; using LineSegment2d = LineSegment; using LineSegment3d = LineSegment; using LineSegment4d = LineSegment; using LineSegment2f = LineSegment; using LineSegment3f = LineSegment; using LineSegment4f = LineSegment; } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/line_utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/core/assert.hpp" #include "gems/core/math/types.hpp" #include "gems/core/math/utils.hpp" #include "gems/geometry/polyline.hpp" namespace nvidia { namespace isaac { namespace geometry { // Returns the closest point of a segment (ab) to a point `p`. // NOTE: It can be used with Line/HalfLine/Segment. template typename Line::Vector_t ClosestPointToLine(const Line& line, const typename Line::Vector_t& p); // Returns the squared distance between a point and a Line/HalfLine/Segment. // Avoid any sqrt by using the pytagorian theorem. template typename Line::Scalar SquaredDistancePointToLine(const Line& line, const typename Line::Vector_t& p); // Returns the distance between a point and a Line/HalfLine/Segment. template typename Line::Scalar DistancePointToLine(const Line& line, const typename Line::Vector_t& p); // Returns whether two Line/HalfLine/Segment are intersecting. // In addition if the line intersect lambda_{A/B} would be filled such as: // A.origin() + lambda_a A.direction() == B.origin() + lambda_b B.direction() template bool AreLinesIntersecting(const LineT1& line_a, const LineT2& line_b, typename LineT1::Scalar* lambda_a = nullptr, typename LineT1::Scalar* lambda_b = nullptr); // Returns the closest point of two lines. If the lines are intersecting, the intersection will be // returned, otherwise (i.e. when the lines are parallel), any point of any line would work. Note // that if a line segment is passed this function only looks at the underlying line and ignores the // start and end of the segment. template Vector2 Intersection(const LineT1& line_a, const LineT2& line_b); // Returns the closest point of a segment [ab] to a point `p`. template Vector ClosestPointToSegment(const Vector& a, const Vector& b, const Vector& p); // Returns the closest point of a polyline [ab...yz] to a point `p`. // If `segment_index` is provided, it will contain the index of the segment the closest to the // point. template Vector ClosestPointToPolyline(const Polyline& polyline, const Vector& p, size_t* segment_index = nullptr); // Returns the squared distance of a point `p` to a segment [ab]. template K DistanceSquaredPointToSegment(const Vector& a, const Vector& b, const Vector& p); // Returns the distance of a point `p` to a segment [ab]. template K DistancePointToSegment(const Vector& a, const Vector& b, const Vector& p); // ------------------------------------------------------------------------------------------------- template typename Line::Vector_t ClosestPointToLine(const Line& line, const typename Line::Vector_t& p) { const typename Line::Vector_t& ray = line.direction(); const typename Line::Vector_t ap = p - line.origin(); const typename Line::Scalar l = line.clamp(ray.dot(ap) / ray.squaredNorm()); return line.origin() + l * ray; } template typename Line::Scalar SquaredDistancePointToLine(const Line& line, const typename Line::Vector_t& p) { using K = typename Line::Scalar; const typename Line::Vector_t& ray = line.direction(); const typename Line::Vector_t ap = p - line.origin(); const K ray_sq_norm = ray.squaredNorm(); // Check this is not an empty segment, in which case the distance is the distance to one of the // extremities. if (IsAlmostZero(ray_sq_norm)) return ap.squaredNorm(); const K dot = ray.dot(ap); const K l = dot / ray_sq_norm; const K cl = line.clamp(l); const K cl2 = cl * cl * ray_sq_norm; return ap.squaredNorm() + cl2 - K(2) * l * cl * ray_sq_norm; } template typename Line::Scalar DistancePointToLine(const Line& line, const typename Line::Vector_t& p) { return std::sqrt(SquaredDistancePointToLine(line, p)); } // P(x, y) is on a line iff (P-A)xR_a = 0 // We are looking for lambda such as (B + lambda R_b - A) x R_a = 0 // lambda = (A-B) x R_a / (R_b x R_a) // x denotes the cross product here. template bool AreLinesIntersecting(const LineT1& line_a, const LineT2& line_b, typename LineT1::Scalar* lambda_a, typename LineT1::Scalar* lambda_b) { static_assert(LineT1::kDimension == 2 && LineT2::kDimension == 2, "AreLinesIntersecting only works in 2D"); static_assert(std::is_same::value, "Type mismatch"); using K = typename LineT1::Scalar; K lA, lB; if (lambda_a == nullptr) lambda_a = &lA; if (lambda_b == nullptr) lambda_b = &lB; const Vector2& R_a = line_a.direction(); const Vector2& R_b = line_b.direction(); const K ray_cross = CrossProduct(R_b, R_a); // The two lines are parallel, they could still intersect in one or an infinity of points. if (IsAlmostZero(ray_cross)) { const Vector2 pt = ClosestPointToLine(line_a, line_b.origin()); constexpr K kEpsilonThreshold = MachineEpsilon * 1000.0; if (SquaredDistancePointToLine(line_b, pt) >= kEpsilonThreshold) return false; const K R_a_norm = line_a.direction().squaredNorm(); const K R_b_norm = line_b.direction().squaredNorm(); *lambda_a = IsAlmostZero(R_a_norm) ? K(0) : (pt - line_a.origin()).dot(R_a) / R_a_norm; *lambda_b = IsAlmostZero(R_b_norm) ? K(0) : (pt - line_b.origin()).dot(R_b) / R_b_norm; } else { const Vector2 BA = line_a.origin() - line_b.origin(); *lambda_b = CrossProduct(BA, R_a) / ray_cross; *lambda_a = CrossProduct(BA, R_b) / ray_cross; } // Checks that both lambda is within the range of the line. return line_a.clamp(*lambda_a) == *lambda_a && line_b.clamp(*lambda_b) == *lambda_b; } template Vector2 Intersection(const LineT1& line_a, const LineT2& line_b) { static_assert(std::is_same(), "both line need to have the same type"); using K = typename LineT1::Scalar; // Line equation is given by: // line.direction.tangent.dot(x, y) = line.direction.tangent.dot(line.origin) // We have a set of two equations, with two unknowns: // ( d1_y -d1_x) (x) (a) // ( ) * ( ) = ( ) // (-d2_y d2_x) (y) (b) const Vector2 t1(line_a.direction().y(), -line_a.direction().x()); const Vector2 t2(-line_b.direction().y(), line_b.direction().x()); const K det = t1.dot(line_b.direction()); // In this case the line are parallel. if (IsAlmostZero(det)) return line_a.origin(); Matrix2 matrix_inverse; matrix_inverse << t2.y(), -t1.y(), -t2.x(), t1.x(); const Vector2 result(line_a.origin().dot(t1), line_b.origin().dot(t2)); return matrix_inverse * result / det; } template Vector ClosestPointToSegment(const Vector& a, const Vector& b, const Vector& p) { const Vector ab = b - a; const Vector ap = p - a; const K l = ab.dot(ap); if (l <= K(0)) { return a; } const K ab_n2 = ab.squaredNorm(); if (l >= ab_n2) { return b; } return a + (l / ab_n2) * ab; } template Vector ClosestPointToPolyline(const Polyline& polyline, const Vector& p, size_t* segment_index) { ASSERT(polyline.size() > 0, "Polyline is empty"); if (segment_index) *segment_index = 0; K best_dist = (p - polyline.front()).squaredNorm(); Vector ret = polyline.front(); for (size_t i = 1; i < polyline.size(); i++) { const auto vec = ClosestPointToSegment(polyline[i - 1], polyline[i], p); const K dist = (vec - p).squaredNorm(); if (dist < best_dist) { best_dist = dist; ret = vec; if (segment_index) *segment_index = i-1; } } return ret; } template K DistanceSquaredPointToSegment(const Vector& a, const Vector& b, const Vector& p) { const Vector ab = b - a; const Vector ap = p - a; const K l = ab.dot(ap); if (l <= K(0)) { return ap.squaredNorm(); } const K ab_n2 = ab.squaredNorm(); if (l >= ab_n2) { return (b - p).squaredNorm(); } return ap.squaredNorm() - l * l / ab_n2; } template K DistancePointToSegment(const Vector& a, const Vector& b, const Vector& p) { return std::sqrt(DistanceSquaredPointToSegment(a, b, p)); } } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/n_cuboid.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { namespace geometry { // Represent a Rectangular Cuboid in dimension N (https://en.wikipedia.org/wiki/Cuboid). template class NCuboid { public: // Type of a point. using Vector_t = Vector; using Scalar = K; constexpr static int kDimension = N; // Creates a NCuboid from the boundaries: // A point will belong in the cuboid if for each dimension dims[i][0] <= pt[i] <= dims[i][1]. static NCuboid FromBoundingCuboid(const std::array, N>& dims) { Vector_t min, max; for (size_t dim = 0; dim < N; dim++) { min[dim] = dims[dim][0]; max[dim] = dims[dim][1]; } return NCuboid{min, max}; } // Creates a NCuboid from the boundaries: // A point will belong in the cuboid if for each dimension min[i] <= pt[i] <= max[i]. static NCuboid FromOppositeCorners(const Vector_t& corner1, const Vector_t& corner2) { return NCuboid{corner1, corner2}; } // Creates a NCuboid from the center and the size of each dimensions. // A point will belong in the cuboid if for each dimension: // center[i] - sizes[i]/2 <= pt[i] <= center[i] + sizes[i]/2 static NCuboid FromSizes(const Vector_t& center, const Vector_t& sizes) { const Vector_t min = center - sizes / K(2); return NCuboid{min, (min + sizes).eval()}; } // Empty constructor to allow allocation NCuboid() {} // Accessor const Vector_t& min() const { return min_; } Vector_t& min() { return min_; } const Vector_t& max() const { return max_; } Vector_t& max() { return max_; } // Returns the center point of the cuboid Vector_t center() const { return (min_ + max_) / K(2); } // Returns sizes of each dimension of the cuboid Vector_t sizes() const { return max_ - min_; } // Returns whether a point is inside the cuboid bool isInside(const Vector_t& pt) const { for (size_t dim = 0; dim < kDimension; dim++) { if (pt[dim] < min_[dim] || pt[dim] > max_[dim]) { return false; } } return true; } // Casts to a different type template ::value, int> = 0> NCuboid cast() const { return NCuboid::FromOppositeCorners(min_.template cast(), max_.template cast()); } template ::value, int> = 0> const NCuboid& cast() const { // Nothing to do as the type does not change return *this; } // Computes Volume of cuboid. Computes the area if N is 2. Scalar volume() const { Scalar volume = Scalar(1); for (size_t dim = 0; dim < kDimension; dim++) { volume *= max_[dim] - min_[dim]; } return volume; } // Extends this n_cuboid to contain the other n_cuboid void encapsulate(const NCuboid& other) { min_ = min_.cwiseMin(other.min()); max_ = max_.cwiseMax(other.max()); } // Extends this n_cuboid to contain point void encapsulate(const Vector_t& point) { min_ = min_.cwiseMin(point); max_ = max_.cwiseMax(point); } // Translates the box void translate(const Vector_t& translation) { min_ += translation; max_ += translation; } private: // Private constructor to avoid confusion between corners initialization and sizes initialization. // Use FromOppositeCorners or FromSizes to create a line. NCuboid(const Vector_t& corner1, const Vector_t& corner2) { for (size_t dim = 0; dim < kDimension; dim++) { if (corner1[dim] < corner2[dim]) { min_[dim] = corner1[dim]; max_[dim] = corner2[dim]; } else { min_[dim] = corner2[dim]; max_[dim] = corner1[dim]; } } } Vector_t min_, max_; }; template using Rectangle = NCuboid; template using Box = NCuboid; using RectangleD = Rectangle; using RectangleF = Rectangle; using RectangleI = Rectangle; using BoxD = Box; using BoxF = Box; using BoxI = Box; } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/n_sphere.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { namespace geometry { // Represent a sphere in dimension N. // Note: the mathematical definition of N-Sphere belongs in a space at N+1 dimensions. The N // provided as template argument corresponds to the number of dimension. // Therefore a circle is 1-sphere mathematically but NSphere here. // Same for the regular sphere: 2-sphere mathematically but NSphere here. template struct NSphere { public: // Type of a point. using Vector_t = Vector; using Scalar = K; constexpr static int kDimension = N; Vector_t center; Scalar radius; // Returns whether a point is inside the sphere bool isInside(const Vector_t& pt) const { return (center - pt).squaredNorm() <= radius * radius; } // Casts to a different type template ::value, int> = 0> NSphere cast() const { return NSphere{center.template cast(), static_cast(radius)}; } template::value, int> = 0> const NSphere& cast() const { // Nothing to do as the type does not change return *this; } }; template using Circle = NSphere; template using Sphere = NSphere; using CircleD = Circle; using CircleF = Circle; using SphereD = Sphere; using SphereF = Sphere; } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/pinhole.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/assert.hpp" #include "gems/core/epsilon.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { namespace geometry { // A pinhole camera model describes how points in 3D space are projected onto a 2D image plane. // // In Isaac we choose the following coordinate frames: // * Camera coordinate, i.e. a point in front of the pinhole which will be projected onto the // image plane, are given as: // X right, Y down, Z forward. // * Image coordinates, i.e. a point in pixel coordinates, are given as: // 0: rows, 1: columns // // The pinhole type is templated on the scalar type used for optical center and focal length. // This type must be a floating point type like float or double. template ::value, int>::type = 0> struct Pinhole { // The dimensions of the camera image plane in pixels in the order (rows, columns) Vector2i dimensions; // Focal length of the projection (in pixels) in the order (row, column) Vector2 focal; // Optical center of the projection (in pixels) in the order (row, column) Vector2 center; // Creates a pinhole camera model from horizontal field of view with center in the middle or the // image plane. static Pinhole FromHorizontalFieldOfView(const Vector2i& dimensions, K fov_horizontal) { ASSERT(fov_horizontal > K(0), "Field of view must be greater than 0"); const K focal = static_cast(dimensions[1]) / (K(2) * std::tan(K(0.5) * fov_horizontal)); return Pinhole{dimensions, {focal, focal}, K(0.5) * dimensions.cast()}; } static Pinhole FromHorizontalFieldOfView(int rows, int cols, K fov_horizontal) { return FromHorizontalFieldOfView({rows, cols}, fov_horizontal); } // Similar to `FromHorizontalFieldOfView`, but the field of view angle indicates the vertical // field of view. static Pinhole FromVerticalFieldOfView(const Vector2i& dimensions, K fov_vertical) { ASSERT(fov_vertical > K(0), "Field of view must be greater than 0"); const K focal = static_cast(dimensions[0]) / (K(2) * std::tan(K(0.5) * fov_vertical)); return Pinhole{dimensions, {focal, focal}, K(0.5) * dimensions.cast()}; } static Pinhole FromVerticalFieldOfView(int rows, int cols, K fov_vertical) { return FromVerticalFieldOfView({rows, cols}, fov_vertical); } // Projects a 3D point in camera coordinates onto the pixel plane and returns the pixel coordinate // as fractional values. template ::value, int>::type = 0> Vector2 project(const Eigen::MatrixBase& point) const { ASSERT(!IsAlmostZero(point[2]), "Invaid point with z almost 0 (%f)", point[2]); return ((point.template head<2>() / point[2]).array()).reverse() * focal.array() + center.array(); } // Projects a 3D point in camera coordinates onto the pixel plane and rouns the pixel coordinate // to the nearest pixel on the image plane (rounding down). template ::value, int>::type = 0> Vector2i projectToInt(const Eigen::MatrixBase& point) const { const Vector2 pixel = project(point); return {FloorToInt(pixel[0]), FloorToInt(pixel[1])}; } // Casts a ray through the given pixel coordinate and gives the point on the ray at the given // distance `depth`. The point is given in camera coordinates. template ::value, int>::type = 0> Vector3 unproject(const Eigen::MatrixBase& pixel, K depth) const { const Vector2 a = ((pixel - center).array() / focal.array()) * depth; return {a[1], a[0], depth}; } // Special version for integer-coordinate pixels. We assume that pixel rays go through the center // of the pixel. template < typename Derived, typename std::enable_if::value, int>::type = 0> Vector3 unproject(const Eigen::MatrixBase& pixel, K depth) const { return unproject(pixel.template cast() + Vector2{K(0.5), K(0.5)}, depth); } Vector3 unproject(int px, int py, K depth) const { return unproject(Vector2i{px, py}.template cast() + Vector2{K(0.5), K(0.5)}, depth); } // Computes the area of a pixel at given depth assuming a planar patch K pixelAreaAtDepth(K depth) const { return depth * depth / (focal[0] * focal[1]); } // Scale the pinhole. The scale factor is different for rows and cols Pinhole scale(const Vector2& scale_factor) const { ASSERT((scale_factor.array() >= 0).all(), "Invalid scale factor"); return { (dimensions.template cast().cwiseProduct(scale_factor)).template cast(), focal.cwiseProduct(scale_factor), center.cwiseProduct(scale_factor)}; } // Scale the pinhole Pinhole scale(K scale_factor) const { ASSERT(scale_factor > K(0), "Invalid scale factor"); return scale(Vector2{scale_factor, scale_factor}); } // First crop the intrinsics and then scale them Pinhole cropAndScale(const Vector2i& crop_start, const Vector2i& crop_size, const Vector2i& scaled_size) const { ASSERT((crop_start.array() >= 0).all(), "Invalid crop start"); ASSERT((crop_start.array() < dimensions.array()).all(), "Invalid crop start"); ASSERT((crop_size.array() > 0).all(), "Invalid crop size"); const Pinhole cropped_pinhole{crop_size, focal, center - crop_start.cast()}; return cropped_pinhole.scale(scaled_size.cast().cwiseQuotient(crop_size.cast())); } // Computes the field of view angles (in radians) in the order (vertical, horizontal) Vector2 computeFieldOfView() const { return { K(2) * std::atan2(K(0.5) * static_cast(dimensions[0] - 1), focal[0]), K(2) * std::atan2(K(0.5) * static_cast(dimensions[1] - 1), focal[1]) }; } // Returns the 3x3 projection matrix Matrix3 matrix() const { Matrix3 mat; mat << K(0), focal[0], center[0], focal[1], K(0), center[1], K(0), K(0), K(1); return mat; } // Casts the pinhole to a different numeric type. For example from double to float. template Pinhole cast() const { return {dimensions, focal.template cast(), center.template cast()}; } }; // Typedef for pinhole with using 64-bit floating points using PinholeD = Pinhole; } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/plane.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "Eigen/Eigen" namespace nvidia { namespace isaac { namespace geometry { // A plane in N dimensions represented by a normal vector and an offset. template using Hyperplane = class Eigen::Hyperplane; template using Plane = Hyperplane; using PlaneF = Plane; using PlaneD = Plane; } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/polygon.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include #include #include "gems/core/math/types.hpp" #include "gems/geometry/line_segment.hpp" #include "gems/geometry/line_utils.hpp" #include "gems/geometry/n_cuboid.hpp" #include "gems/geometry/n_sphere.hpp" namespace nvidia { namespace isaac { namespace geometry { // A polygon in 2D, the last point and first point are connected template struct Polygon2 { // Type of a point. using Vector_t = Vector2; using Scalar = K; std::vector points; // Returns whether a point is inside the polygon // Note that this method is not accurate if the point lies too close to one edge, Especially if // the point is really close to the edge or of a vertex, it might return true. // This function used the strategy of counting the intersection between the segments of the // polygon and a virtual segment from the `pt` to a point outside of the polygon. While fast, this // method does not work well when the virtual segment is too close to one of the vertices. In this // case it fallbacks to the slower implementation below. bool isInside(const Vector_t& pt) const { if (points.empty()) return false; // Select a point outside of the polygon (max(x) + 1, max(y) + 2). // Picking a different constant for x and y helps reduce the chance the point is aligned with // one vertex. Vector_t max = points.front(); for (const auto& point : points) { max.x() = std::max(max.x(), point.x() + K(1)); max.y() = std::max(max.y(), point.y() + K(2)); } // If the maximum value of x+1 is less or equal to our point, then we are obviously outside. if (max.x() <= pt.x()) return false; if (max.y() <= pt.y()) return false; const LineSegment seg(pt, max); // Count how many segment it intersects, if it's an odd number then the point is inside or on // one edge. int counter = 0; for (size_t ix = 0; ix < points.size(); ix++) { const LineSegment edge(points[ix], points[(ix + 1) % points.size()]); K lambda; if (AreLinesIntersecting(seg, edge, nullptr, &lambda)) { counter++; // If our lines are too close, we fallback to the slow but accurate method. if (IsAlmostZero(lambda) || IsAlmostOne(lambda)) { return slowIsInside(pt); } } } return counter % 2 == 1; } // Returns whether a point is inside the polygon // This function is a bit slow and should not be called in critical path too often. // This function used the strategy to measure the sum of the field of view the segment are // observed. It was the most accurate solution, however it requires using trigonometric functions, // which are quite slow. bool slowIsInside(const Vector_t& pt) const { if (points.empty()) return false; K sum_angle = K(0); Vector_t delta = points.back() - pt; // If delta == 0, it means pt is the same as one of the vertex. if (IsAlmostZero(delta.squaredNorm())) return true; K last_angle = std::atan2(delta.y(), delta.x()); for (size_t ix = 0; ix < points.size(); ix++) { delta = points[ix] - pt; // If delta == 0, it means pt is the same as one of the vertex. if (IsAlmostZero(delta.squaredNorm())) return true; const K angle = std::atan2(delta.y(), delta.x()); const K delta_angle = DeltaAngle(angle, last_angle); // If delta == +/- pi, it means pt is on one of the segment. if (IsAlmostEqualRelative(std::abs(delta_angle), Pi)) { return true; } sum_angle += delta_angle; last_angle = angle; } return std::abs(sum_angle) > Pi; } // Returns the distance of a point from the polygon edges K distance(const Vector_t& pt, Vector_t* grad = nullptr) const { K squared_dist = std::numeric_limits::max(); for (size_t ix = 0; ix < points.size(); ix++) { const LineSegment edge(points[ix], points[(ix + 1) % points.size()]); const Vector_t closest = ClosestPointToLine(edge, pt); const K dist = (pt - closest).squaredNorm(); if (dist < squared_dist) { squared_dist = dist; if (grad) *grad = pt - closest; } } if (grad) grad->normalize(); return std::sqrt(squared_dist); } // Returns the signed distance of a point from the polygon (negative means inside the polygon) K signedDistance(const Vector_t& pt, Vector_t* grad = nullptr) const { const K dist = distance(pt, grad); // If the point is inside the polygon, we need to revert the direction of the gradient. if (isInside(pt)) { if (grad) *grad = -(*grad); return -dist; } return dist; } // Returns the signed area of the polygon // https://mathworld.wolfram.com/PolygonArea.html K signedArea() const { K area = K(0); for (size_t curr = 0, prev = points.size()-1; curr < points.size(); curr++) { area += CrossProduct(points[prev], points[curr]); prev = curr; } return area / K(2); } // Returns the centroid of the polygon // https://en.wikipedia.org/wiki/Centroid#Of_a_polygon Vector_t centroid() const { if (points.size() < 3) { if (points.empty()) return Vector_t::Zero(); return (points.front() + points.back()) / K(2); } Vector_t centroid = Vector_t::Zero(); for (size_t curr = 0, prev = points.size()-1; curr < points.size(); curr++) { const K cross_product = CrossProduct(points[prev], points[curr]); centroid += (points[prev] + points[curr]) * cross_product; prev = curr; } return centroid / (K(6) * signedArea()); } // Returns the minimum circle that contains the polygon. Circle boundingCircle() const { std::vector indices(points.size()); std::vector border; for (size_t idx = 0; idx < points.size(); idx++) { indices[idx] = idx; } // Random order to improve performance std::random_device rd; std::mt19937 gen(rd()); std::shuffle(indices.begin(), indices.end(), gen); // Compute the center when the number of vertices is less or equal to 3 auto trivialCenter = [&](const std::vector& indices) -> Circle { switch (indices.size()) { // Edge case for empty polygon, there is no real good answer, but any circle of radius 0 // is technically a good answer. case 0: return {Vector_t::Zero(), K(0)}; // If the polygon has a single point, then it's the center of the circle of radius 0. case 1: return {points[indices[0]], K(0)}; // For two points, the center is the center of the segment, and the radius can be computed // using one of the extremity. case 2: { const Vector_t delta = (points[indices[1]] - points[indices[0]]) / K(2); return {points[indices[0]] + delta, delta.norm()}; } // There is a formula for a triangle: // https://en.wikipedia.org/wiki/Circumscribed_circle#Cartesian_coordinates_2 case 3: { const Vector_t& A = points[indices[0]]; const Vector_t& B = points[indices[1]] - A; const Vector_t& C = points[indices[2]] - A; const K b_squared_norm = B.squaredNorm(); const K c_squared_norm = C.squaredNorm(); const K d = K(2) * CrossProduct(B, C); const Vector_t center = Vector_t( b_squared_norm * C.y() - c_squared_norm * B.y(), c_squared_norm * B.x() - b_squared_norm * C.x()) / d; return {A + center, center.norm()}; } default: PANIC("Invalid size: %zd", indices.size()); } return {Vector_t::Zero(), K(0)}; }; // Implementation of the welzl algorithm: // https://en.wikipedia.org/wiki/Smallest-circle_problem#Welzl's_algorithm auto welzl = [&](auto welzl, std::vector& indices, std::vector& border) { if (indices.empty() || border.size() == 3) return trivialCenter(border); size_t p = indices.back(); indices.pop_back(); auto circle = welzl(welzl, indices, border); if (circle.isInside(points[p])) { indices.push_back(p); return circle; } border.push_back(p); circle = welzl(welzl, indices, border); border.pop_back(); indices.push_back(p); return circle; }; return welzl(welzl, indices, border); } // Returns whether both polygons intersect. If one polygon is fully inside the other, then the // function returns false. bool intersect(const Polygon2& polygon) const { return intersectImpl<1>(polygon.points); } // Returns whether this polygon intersect with the polyline. bool intersect(const Polyline& polyline) const { return intersectImpl<0>(polyline); } // Returns the distance between two polygons. // If one polygon is stricly included in the other, the distance will be negative. K distance(const Polygon2& polygon) const { const K squared_dist = squaredDistanceImpl<1>(polygon.points); if (squared_dist == K(0)) return K(0); const auto bounding_box_a = getBoundingBox(); const auto bounding_box_b = polygon.getBoundingBox(); // If the bounding box A encapsulates B, then B might be inside A if (bounding_box_a.min().x() < bounding_box_b.min().x() && bounding_box_b.max().x() < bounding_box_a.max().x() && bounding_box_a.min().y() < bounding_box_b.min().y() && bounding_box_b.max().y() < bounding_box_a.max().y()) { return isInside(polygon.points.front()) ? -std::sqrt(squared_dist) : std::sqrt(squared_dist); } // If the bounding box B encapsulates A, then A might be inside B if (bounding_box_b.min().x() < bounding_box_a.min().x() && bounding_box_a.max().x() < bounding_box_b.max().x() && bounding_box_b.min().y() < bounding_box_a.min().y() && bounding_box_a.max().y() < bounding_box_b.max().y()) { return polygon.isInside(points.front()) ? -std::sqrt(squared_dist) : std::sqrt(squared_dist); } return std::sqrt(squared_dist); } // Returns the distance between this polygon and a polyline. // If the polyline is stricly included in this polygon, the distance will be negative. K distance(const Polyline& polyline) const { const K squared_dist = squaredDistanceImpl<0>(polyline); if (squared_dist == K(0)) return K(0); return isInside(polyline.front()) ? -std::sqrt(squared_dist) : std::sqrt(squared_dist); } // Returns the bounding box, aligned with the axis, that contain this polygon. Rectangle getBoundingBox() const { if (points.empty()) { return Rectangle::FromOppositeCorners(Vector2::Zero(), Vector2::Zero()); } Vector2 min = points.front(); Vector2 max = points.front(); for (const auto& pt : points) { min = min.cwiseMin(pt); max = max.cwiseMax(pt); } return Rectangle::FromOppositeCorners(min, max); } // Casts to a different type template ::value, int> = 0> Polygon2 cast() const { std::vector> pts; pts.reserve(points.size()); for (const auto& pt : points) { pts.emplace_back(pt.template cast()); } return Polygon2{std::move(pts)}; } template::value, int> = 0> const Polygon2& cast() const { // Nothing to do as the type does not change return *this; } private: // Implementation of the squaredDistance using a polyline. // If loop is 1, then we close the polyline (making it a polygon). template K squaredDistanceImpl(const Polyline& polyline) const { static_assert(Loop >= 0 && Loop <= 1, "Loop must be 0 or 1"); // Check for an intersection if (intersectImpl(polyline)) return K(0); // Find the closest point of either polygon to the other one. K squared_dist = std::numeric_limits::max(); // For all the points of this polygon, we check the distance to all the segments of the other // polygon. for (size_t ax = 0; ax < points.size(); ax++) { const Vector2& a = points[ax]; const Vector2& b = points[(ax + 1) % points.size()]; for (size_t bx = 0; bx < polyline.size(); bx++) { squared_dist = std::min(squared_dist, DistanceSquaredPointToSegment(a, b, polyline[bx])); } } // For all the points of the other polygon, we check the distance to all the segments of this // polygon. for (size_t ax = 1; ax < polyline.size() + Loop; ax++) { const Vector2& a = polyline[ax - 1]; const Vector2& b = polyline[ax % polyline.size()]; for (size_t bx = 0; bx < points.size(); bx++) { squared_dist = std::min(squared_dist, DistanceSquaredPointToSegment(a, b, points[bx])); } } return squared_dist; } // Implementation of the intersect function with a polyline. // If loop is 1, then we close the polyline (making it a polygon). template K intersectImpl(const Polyline& polyline) const { static_assert(Loop >= 0 && Loop <= 1, "Loop must be 0 or 1"); const auto bounding_box_a = getBoundingBox(); const auto bounding_box_b = Polygon2{polyline}.getBoundingBox(); if (bounding_box_a.min().x() > bounding_box_b.max().x() || bounding_box_b.min().x() > bounding_box_a.max().x() || bounding_box_a.min().y() > bounding_box_b.max().y() || bounding_box_b.min().y() > bounding_box_a.max().y()) { return false; } for (size_t ax = 0; ax < points.size(); ax++) { const LineSegment a(points[ax], points[(ax + 1) % points.size()]); for (size_t bx = 1; bx < polyline.size() + Loop; bx++) { const LineSegment b(polyline[bx - 1], polyline[bx % polyline.size()]); if (AreLinesIntersecting(a, b)) return true; } } return false; } }; // A polygon in 3D, the last point and first point are connected template struct Polygon3 { // Type of a point. using Vector_t = Vector3; using Scalar = K; std::vector points; }; using Polygon2D = Polygon2; using Polygon2F = Polygon2; using Polygon3D = Polygon3; using Polygon3F = Polygon3; } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/polyline.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { namespace geometry { // A polyline is currently simply a list of points template using Polyline = std::vector>; using Polyline2d = Polyline; using Polyline2f = Polyline; using Polyline3d = Polyline; using Polyline3f = Polyline; } // namespace geometry } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/geometry/types.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/geometry/line.hpp" #include "gems/geometry/line_segment.hpp" #include "gems/geometry/n_cuboid.hpp" #include "gems/geometry/n_sphere.hpp" #include "gems/geometry/plane.hpp" #include "gems/geometry/polygon.hpp" #include "gems/geometry/polyline.hpp" ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/gxf_helpers/expected_macro_abstract.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/logger.hpp" // This file defines macro helpers that can be used to check the result of an expression. Note that // this is an abstract implementation that has no knowledge of the result types it can be used with. // In order to use the macro it has to be configured first for a specific result type. // // Taxonomy: // - Result Type: The union of both status and unwrappable types. // - Status Type: A type that is used as the return type of an expression and holds the return // status of the expression, eg. bool, int, enum etc. // - Unwrappable Type: A type that is used as the return type of an expression and holds both the // return status and the return value of the expression, eg. std::optional, // nvidia::Expected etc. // Concatenates its two arguments. #define EXPECTED_MACRO_INTERNAL_CONCAT(a, b) EXPECTED_MACRO_INTERNAL_CONCAT_IMPL(a, b) #define EXPECTED_MACRO_INTERNAL_CONCAT_IMPL(a, b) a##b // Converts its argument to a string at compile time. #define EXPECTED_MACRO_INTERNAL_TO_STRING(x) EXPECTED_MACRO_INTERNAL_TO_STRING_IMPL(x) #define EXPECTED_MACRO_INTERNAL_TO_STRING_IMPL(x) #x // Gets the current location in the source code in the format "file:line". #define EXPECTED_MACRO_INTERNAL_FILE_LINE() __FILE__ ":" EXPECTED_MACRO_INTERNAL_TO_STRING(__LINE__) // Helper to support logging a default message and an optional custom message. #define EXPECTED_MACRO_INTERNAL_LOG_IN_EXPECT_MACRO(expression_result, expression_string, ...) \ nvidia::expected_macro::LogHelper( \ __FILE__, __LINE__, expression_result, expression_string, ##__VA_ARGS__); // Helper to check the return type of the expression used in RETURN_IF_ERROR. #define EXPECTED_MACRO_INTERNAL_CHECK_EXPRESSION_IS_RESULT(expression_result) \ static_assert( \ nvidia::expected_macro::config::IsStatus::value || \ nvidia::expected_macro::config::IsUnwrappable::value , \ EXPECTED_MACRO_INTERNAL_FILE_LINE() \ ": RETURN_IF_ERROR can only be used with expressions that return a result type. You " \ "can register a type as a result type unwrappable with one of" \ "`template <> struct IsUnwrappable : std::true_type {};` or " \ "`template <> struct IsStatus : std::true_type {}`. "); // Helper to check the return type of the expression used in UNWRAP_OR_RETURN. #define EXPECTED_MACRO_INTERNAL_CHECK_EXPRESSION_IS_UNWRAPPABLE(expression_result) \ static_assert( \ nvidia::expected_macro::config::IsUnwrappable::value, \ EXPECTED_MACRO_INTERNAL_FILE_LINE() \ ": UNWRAP_OR_RETURN can only be used with expressions that return an unwrappable type. " \ "You can register a type as being unwrappable with " \ "`template <> struct IsUnwrappable : std::true_type {};`. For expressions " \ "returning a status instead of an unwrappable use `RETURN_IF_ERROR` instead."); // Evaluates an expression that returns a result type. If the returned result contains an error it // returns the error. This macro can only be used in functions that also return a result type. // // Per default the macro already creates an error message that includes the evaluated expression. If // needed an optional string can be passed that will be appended to the default error message. It is // also possible to use format specifiers to customize the string. // // It is also possible to pass the Severity used for logging as an additional argument. This is // required if using a custom error message. // // Example: // Expected DoSomething(); // Expected DoAnotherThing(); // // Expected foo(){ // RETURN_IF_ERROR(DoSomething()); // RETURN_IF_ERROR(DoAnotherThing(), Severity::WARNING); // RETURN_IF_ERROR(DoAnotherThing(), Severity::WARNING, "Custom error message."); // } #define RETURN_IF_ERROR(expression, ...) \ do { \ auto maybe_result = (expression); \ EXPECTED_MACRO_INTERNAL_CHECK_EXPRESSION_IS_RESULT(maybe_result) \ if (!nvidia::expected_macro::config::IsValid(maybe_result)) { \ EXPECTED_MACRO_INTERNAL_LOG_IN_EXPECT_MACRO(maybe_result, #expression, ##__VA_ARGS__) \ return nvidia::expected_macro::ProxyFactory::FromStatusOrUnwrappable(maybe_result); \ } \ } while (0) // Evaluates an expression that returns a type that can be casted to a boolean. If the expression is // false it returns an error. This macro can only be used in functions returning a result type. // // The difference to RETURN_IF_ERROR is that this macro will always cast the expression to a // boolean. Thus if your expression returns a status that can be more than just true/false you will // loose the additional information. In those cases RETURN_IF_ERROR is preferred. Use this macro // only to check preconditions like a < b, or c != nullptr. // // Per default the macro already creates an error message that includes the evaluated expression. If // needed an optional string can be passed that will be appended to the default error message. It is // also possible to use format specifiers to customize the string. // // It is also possible to pass the Severity used for logging as an additional argument. This is // required if using a custom error message. // // Example: // Expected foo(){ // RETURN_IF_FALSE(1 > 2); // RETURN_IF_FALSE(1 > 2, Severity::WARNING); // RETURN_IF_FALSE(1 > 2, Severity::WARNING, "1 is not bigger than 2"); // } #define RETURN_IF_FALSE(expression, ...) \ do { \ const bool result = static_cast(expression); \ if (!result) { \ EXPECTED_MACRO_INTERNAL_LOG_IN_EXPECT_MACRO(result, #expression, ##__VA_ARGS__) \ return nvidia::expected_macro::ProxyFactory::FromStatusOrUnwrappable(result); \ } \ } while (0) // Evaluates an expression that returns an unwrappable type. If the returned type contains an error // it returns the error, else it unwraps the value. This macro can only be used in functions // returning a result type. // // Per default the macro already creates an error message that includes the evaluated expression. If // needed an optional string can be passed that will be appended to the default error message. It is // also possible to use format specifiers to customize the string. // // It is also possible to pass the Severity used for logging as an additional argument. // // Note that this macro uses expression-statements (i.e. the ({ }) surrounding the macro) which are // a non-standard functionality. However they are present in almost all compilers. We currently only // know of MSVC that does not support this. // // Example: // Expected GetString(); // Expected GetAnotherString(); // // Expected CountCombinedStringLength(){ // const std::string str1 = UNWRAP_OR_RETURN(GetString()); // std::string str2; // str2 = UNWRAP_OR_RETURN(GetAnotherString(), "This should not fail. Str1 has value %s.", // str1.c_str()); // const std::string str3 = UNWRAP_OR_RETURN(GetAnotherString(), Severity::WARNING); // const std::string str4 = UNWRAP_OR_RETURN(GetAnotherString(), Severity::WARNING, // "Custom error message"); // return str1.size() + str2.size() + str3.size() + str4.size(); // } #define UNWRAP_OR_RETURN(expression, ...) \ ({ \ auto maybe_result = (expression); \ EXPECTED_MACRO_INTERNAL_CHECK_EXPRESSION_IS_UNWRAPPABLE(maybe_result) \ if (!nvidia::expected_macro::config::IsValid(maybe_result)) { \ EXPECTED_MACRO_INTERNAL_LOG_IN_EXPECT_MACRO(maybe_result, #expression, ##__VA_ARGS__) \ return nvidia::expected_macro::ProxyFactory::FromUnwrappable(maybe_result); \ } \ std::move(maybe_result.value()); \ }) // All functions in the following namespace have to be specialized for a given result type in order // to enable the macro for the type. namespace nvidia::expected_macro::config { // Type trait to check if a type can be used as a status. template struct IsStatus : std::false_type {}; // Type trait to check if a type can be used as an unwrappable. template struct IsUnwrappable : std::false_type {}; // The value that represents the default error for a given status type. template constexpr Status DefaultError(); // Check if a result types is valid. template constexpr bool IsValid(const Result& result) { return static_cast(result); } // Helper struct to get the status type of a result. This is needed for the StatusValue helper below // to automatically infer the return type. // // Per default we use the same type as the // result, which holds for all status types. Thus this only has to be specialized for unwrappable // types. template struct StatusType { using Type = Result; }; // Helper function to get the status of a result. We have to use a static member function instead of // a free function because we want the possibility for a user to only provide a partial template // specialization of this. template struct StatusValue { static constexpr typename StatusType::Type Get(const Result& result) { return result; } }; // Get the name corresponding to a status, s.t. it can be printed. template struct StatusName { static std::string Get(Status status); }; // Get the invalid unwrappable corresponding to an unwrappable. Eg. std::nullopt for std::optional. template struct InvalidUnwrappable { static Unwrappable Get(Status status); }; } // namespace nvidia::expected_macro::config namespace nvidia::expected_macro { // The default severity used for logging. constexpr ::nvidia::isaac::logger::Severity kDefaultSeverity = ::nvidia::isaac::logger::Severity::ERROR; // Syntactic sugar to get the status of a result without having to explicitly specify all template // arguments. template constexpr typename config::StatusType::Type GetStatus(const Result& result) { return config::StatusValue::Get(result); } // Syntactic sugar to get the status name without having to explicitly specify all template // arguments. template std::string GetStatusName(Status status) { return config::StatusName::Get(status); } // Syntactic sugar to get the invalid unwrappable without having to explicitly specify all template // arguments. template Unwrappable GetInvalidUnwrappable(Status status) { return config::InvalidUnwrappable::Get(status); } template class ResultProxy; // ProxyFactory to create an ResultProxy. We create a separate class for these functions // because ResultProxy is templated and thus could not be used without explicitly // specifying the template. class ProxyFactory { public: // Constructs the proxy from an unwrappable type. The unwrappable has to be in an error state. We // do not check this because the macro should have already done this check. We use static // methods instead of constructors to explicitly disallow construction from certain types in // different situations. template < typename Unwrappable, typename = std::enable_if_t::value>> static ResultProxy::Type> FromUnwrappable( const Unwrappable& unwrappable) { return ResultProxy(GetStatus(unwrappable)); } // Constructs the proxy from a status type. The status has to be in an error state. We do not // check this because the macro should have already done this check. We use static methods instead // of constructors to explicitly disallow construction from certain types in different situations. template static ResultProxy::Type> FromStatusOrUnwrappable( const Result& result) { return ResultProxy(GetStatus(result)); } }; // A proxy class to allow implicit casting of one result type to another result type. Thus in a // function that returns a result type one can simply return this proxy and then it will implicitly // cast to the appropriate return type. template class ResultProxy { public: // Casts the proxy to a status or unwrappable type. Note that this cast is not allowed to be // explicit. template < typename T, typename = std::enable_if_t::value || config::IsUnwrappable::value>> constexpr operator T() const { if constexpr (config::IsStatus::value) { return castToStatus(); } else { return castToInvalidUnwrappable(); } } private: // Constructs the proxy from a status type. The status has to be in an error state. // We do not check for this because we rely on the macro already having done that check. constexpr explicit ResultProxy(Status error) : error_(error) {} // Casts the proxy to a status type. If the error type is not equal to the proxy's error type, // a default error is used. template constexpr OtherStatus castToStatus() const { static_assert(config::IsStatus::value, "OtherStatus has to be a status type."); if constexpr (std::is_same_v) { return error_; } else { return config::DefaultError(); } } // Casts the proxy to an invalid unwrappable type (eg. std::nullopt or nvidia::Unexpected). template constexpr Unwrappable castToInvalidUnwrappable() const { static_assert( config::IsUnwrappable::value, "Unwrappable has to be a status type."); using OtherStatus = typename config::StatusType::Type; return GetInvalidUnwrappable(castToStatus()); } Status error_; // TODO: enable the following. // static_assert(config::IsStatus::value, "Status has to be a status type."); friend ProxyFactory; }; // Helper function for the logging in the above macros. This version should be used when the user // also specifies the logging severity. The variadic arguments can be used to do string // interpolation in the custom_text variable. template void LogHelper( const char* file, int line, const ExpressionResult& expression_result, const std::string& expression_string, ::nvidia::isaac::logger::Severity severity, const std::string& custom_txt = "", Args... args) { const auto error = GetStatus(expression_result); const std::string text = "Expression '" + expression_string + "' failed with error '" + GetStatusName(error) + "'. " + custom_txt; // GCC is not able to do format security validation when the string // is coming from a variadic template, even if the string is // originally a char* ignore this warning until a more recent GCC // version fixes this behavior #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wformat-security" ::nvidia::isaac::logger::Log(file, line, severity, text.c_str(), args...); #pragma GCC diagnostic pop } // Overload of the LogHelper above. This version does not take the severity as an argument and used // the default severity instead. template void LogHelper( const char* file, int line, const ExpressionResult& expression_result, const std::string& expression_string, const std::string& custom_text = "", Args... args) { LogHelper( file, line, expression_result, expression_string, kDefaultSeverity, custom_text, args...); } } // namespace nvidia::expected_macro ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/gxf_helpers/expected_macro_common.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/gxf_helpers/expected_macro_abstract.hpp" #include "magic_enum.hpp" // NOLINT(build/include) // This file contains the configuration to use the expected macro with different return types like // bool, int, std::optional (and in the future std::expected). ////////////////////////////////////////// // Configuration for using bool as status: ////////////////////////////////////////// namespace nvidia::expected_macro::config { template <> struct IsStatus : std::true_type {}; template <> constexpr bool DefaultError() { return false; } template <> struct StatusName { static std::string Get(bool status) { return status ? "Success" : "Failure"; } }; ///////////////////////////////////////// // Configuration for using int as status: ///////////////////////////////////////// template <> struct IsStatus : std::true_type {}; template <> constexpr bool IsValid(const int& status) { return status == 0; } template <> constexpr int DefaultError() { return 1; } template <> struct StatusName { static std::string Get(int status) { return std::to_string(status); } }; ////////////////////////////////////////// // Configuration for using enum as status: ////////////////////////////////////////// template struct StatusName>> { static std::string Get(EnumStatus status) { return std::string(magic_enum::enum_name(status)); } }; //////////////////////////////////////////////////////// // Configuration for using std::optional as unwrappable: //////////////////////////////////////////////////////// template struct IsUnwrappable> : std::true_type {}; template struct StatusType> { using Type = bool; }; template struct StatusValue> { static constexpr bool Get(const std::optional& optional) { return optional.has_value(); } }; template struct InvalidUnwrappable, bool> { static std::optional Get(bool status) { return std::nullopt; } }; } // namespace nvidia::expected_macro::config ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/gxf_helpers/expected_macro_cuda.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gxf/core/expected_macro.hpp" namespace nvidia::expected_macro { template <> struct IsStatus : std::true_type {}; template <> constexpr bool IsValid(const cudaError_t& status) { return status == cudaSuccess; } template <> constexpr cudaError_t DefaultError() { return cudaErrorUnknown; } template <> struct StatusName { static std::string Get(cudaError_t status) { return std::string(cudaGetErrorString(status)); } }; } // namespace nvidia::expected_macro ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/gxf_helpers/expected_macro_gxf.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2022-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "common/expected.hpp" #include "gxf/core/expected_macro.hpp" #include "gxf/core/gxf.h" ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/gxf_helpers/expected_macro_isaac.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/expected.hpp" #include "gxf/core/expected_macro.hpp" // This customizes the expected macro, s.t. it can be used with ::nvidia::isaac::Expected. namespace nvidia::expected_macro { ////////////////////////////////////////////////////////////////// // Configuration for using nvidia::isaac::Expected as unwrappable: ////////////////////////////////////////////////////////////////// template struct IsUnwrappable<::nvidia::isaac::Expected> : std::true_type {}; template struct StatusType<::nvidia::isaac::Expected> { using Type = Status; }; template struct StatusValue<::nvidia::isaac::Expected> { static constexpr Status Get(const ::nvidia::isaac::Expected& expected) { return expected.error(); } }; template struct InvalidUnwrappable<::nvidia::isaac::Expected, Status> { static ::nvidia::isaac::Expected Get(Status status) { return ::nvidia::isaac::Unexpected(status); } }; } // namespace nvidia::expected_macro ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/gxf_helpers/image_view.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2021-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include "gems/core/image/image.hpp" #include "gems/core/math/types.hpp" #include "gems/core/tensor/tensor.hpp" #include "gxf/core/expected.hpp" #include "gxf/std/tensor.hpp" namespace nvidia { namespace isaac { // Creates an Isaac image view of a GXF host tensor // Note that N here is the number of CHANNELS, not the number of dimensions. // N = 1: single-channel image, N = 3: 3-channel image, etc. template gxf::Expected<::nvidia::isaac::ImageView> ToIsaacImageView(gxf::Tensor& tensor) { if (tensor.storage_type() != gxf::MemoryStorageType::kHost) { return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } // Check if shape is compatible if (N < 1) { GXF_LOG_ERROR("Channel count (%d) must be at least 1", N); return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } else if (N == 1) { if (tensor.rank() != 2 && !(tensor.rank() == 3 && tensor.shape().dimension(2) == 1)) { GXF_LOG_ERROR("Either rank is 2, or rank is 3 and the number of channels is 1. " "Channel count: %d, rank: %d", N, tensor.rank()); return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } } else { // N > 1 if (tensor.rank() != 3) { GXF_LOG_ERROR("If channel count is greater than 1, rank must be 3." "Channel count: %d, rank: %d", N, tensor.rank()); return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } } const size_t rows = tensor.shape().dimension(0); const size_t cols = tensor.shape().dimension(1); auto maybe_ptr = tensor.data(); if (!maybe_ptr) { return gxf::ForwardError(maybe_ptr); } return ::nvidia::isaac::CreateImageView(maybe_ptr.value(), rows, cols); } // Creates an Isaac image const view of a GXF host tensor // Note that N here is the number of CHANNELS, not the number of dimensions. // N = 1: single-channel image, N = 3: 3-channel image, etc. template gxf::Expected<::nvidia::isaac::ImageConstView> ToIsaacImageView(const gxf::Tensor& tensor) { if (tensor.storage_type() != gxf::MemoryStorageType::kHost) { return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } if ((N == 1 && tensor.rank() != 2) || (N > 1 && tensor.rank() != 3)) { GXF_LOG_ERROR("N: %d Tensor rank: %d", N, tensor.rank()); return gxf::Unexpected{GXF_INVALID_DATA_FORMAT}; } const size_t rows = tensor.shape().dimension(0); const size_t cols = tensor.shape().dimension(1); auto maybe_ptr = tensor.data(); if (!maybe_ptr) { return gxf::ForwardError(maybe_ptr); } return ::nvidia::isaac::CreateImageConstView(maybe_ptr.value(), rows, cols); } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/image/color.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include "gems/core/image/image.hpp" #include "gems/core/math/utils.hpp" #include "gems/core/tensor/tensor.hpp" namespace nvidia { namespace isaac { // Maps the unit interval [0,1[ to a 8-bit unsigned integer clamping the value if out of bounds // This is the inverse function of MapUint8ToUnit. inline unsigned char MapUnitToUint8(float x) { return static_cast(Clamp(static_cast(255.0f * x + 0.5f), 0, 255)); } // Maps an 8-bit unsigned integer to the unit interval [0,1[ // This is the inverse function of MapUnitToUint8. inline float MapUint8ToUnit(unsigned char c) { return static_cast(c) / 255.0f; } // Converts a 3f pixel to a 3ub pixel by mapping [0,1] to [0,255] inline Pixel3ub ToPixel3ub(const Pixel3f& color) { return Pixel3ub{MapUnitToUint8(color[0]), MapUnitToUint8(color[1]), MapUnitToUint8(color[2])}; } // Combines a color with an alpha value. inline Pixel4ub WithAlpha(const Pixel3ub& color, uint8_t alpha) { return Pixel4ub{color[0], color[1], color[2], alpha}; } // Converts a 3ub pixel to a 3f pixel by mapping [0,255] to [0,1] inline Pixel3f ToPixel3f(const Pixel3ub& color) { return Pixel3f{MapUint8ToUnit(color[0]), MapUint8ToUnit(color[1]), MapUint8ToUnit(color[2])}; } // Interpolates a color inline Pixel3f Interpolate(const float p, const Pixel3f& a, const Pixel3f& b) { const float p0 = 1.0f - p; return Pixel3f{p0 * a[0] + p * b[0], p0 * a[1] + p * b[1], p0 * a[2] + p * b[2]}; } // Converts a color to hex representation, e.g. (255,128,0) -> "#ff8000" std::string ToHexString(const Pixel3ub& color); std::string ToHexString(const Pixel3ub& color, unsigned char alpha); // Some special colors struct Colors { static Pixel3ub Black() { return Pixel3ub{0, 0, 0}; } static Pixel3ub White() { return Pixel3ub{255, 255, 255}; } static Pixel3ub Pink() { return Pixel3ub{255, 20, 147}; } static Pixel3ub NvidiaGreen() { return Pixel3ub{118, 185, 0}; } static Pixel3ub NvidiaGreen2() { return Pixel3ub{0, 72, 49}; } static Pixel3ub NvidiaGreen3() { return Pixel3ub{0, 132, 113}; } static Pixel3ub Red() { return Pixel3ub{255, 0, 0}; } static Pixel3ub Orange() { return Pixel3ub{255, 128, 0}; } static Pixel3ub Yellow() { return Pixel3ub{255, 255, 0}; } static Pixel3ub Green() { return Pixel3ub{0, 255, 0}; } static Pixel3ub Cyan() { return Pixel3ub{0, 255, 255}; } static Pixel3ub Blue() { return Pixel3ub{0, 0, 255}; } static Pixel3ub Magenta() { return Pixel3ub{255, 0, 255}; } }; // A color gradient which can be used to interpolate a color based on a floating point number. class ColorGradient { public: // Creates a black -> white gradient ColorGradient() { setColors({Colors::Black(), Colors::White()}); } // Creates a gradient using the given colors ColorGradient(const std::vector& colors) { setColors(colors); } ColorGradient(const std::initializer_list& colors) { setColors(colors); } // Creates a gradient using the given colors ColorGradient(const std::vector& colors) : colors_(std::move(colors)) {} ColorGradient(std::initializer_list colors) : colors_(colors.begin(), colors.end()) {} // Sets the colors of the gradient void setColors(const std::vector& colors) { setColors(colors.begin(), colors.end()); } void setColors(const std::initializer_list& colors) { setColors(colors.begin(), colors.end()); } template void setColors(It begin, It end); // Get a color on the gradient for a value p between 0 and 1. p will be clamped if out of bounds. // If the gradient is empty pink will be returned. Pixel3ub operator()(float p) const; private: std::vector colors_; }; // Greyscale black to white color gradient ColorGradient BlackWhiteColorGradient(); // Color gradient inspired by "The Starry Night" painting ColorGradient StarryNightColorGradient(); // Color gradient to match the one above on positive value and extend it in the negative value ColorGradient StarryNightExtendedColorGradient(); // Color gradient going from black to Nvidia green ColorGradient BlackGreenColorGradient(); // All rainbow colors red to magenta ColorGradient RainbowColorGradient(); // Rainbow colors from green to magenta ColorGradient RainbowGreenMagentaColorGradient(); // From white to orange to black ColorGradient ErrorColorGradient(); // A gradient to visualize distances (from black to brown to white to light blue) ColorGradient DistanceColorGradient(); // A gradient going from red to blue over broken white ColorGradient RedBlueColorGradient(); // Colorizes an image of floats using a color gradient void Colorize( const ImageConstView1f& input, const ColorGradient& gradient, float min, float max, Image3ub& colored); // Colorizes an image of doubles using a color gradient void Colorize( const ImageConstView1d& input, const ColorGradient& gradient, double min, double max, Image3ub& colored); // Colorizes a tensor of floats using a color gradient void Colorize( const CpuTensorConstView2f& input, const ColorGradient& gradient, float min, float max, Image3ub& colored); // Colorizes a tensor of doubles using a color gradient void Colorize( const CpuTensorConstView2d& input, const ColorGradient& gradient, double min, double max, Image3ub& colored); // Colorizes an image of floats using a color gradient. This asserts if the input and colored image // dimensions (rows/columns) do not match void Colorize( const ImageConstView1f& input, const ColorGradient& gradient, float min, float max, ImageView3ub& colored); // Colorizes an image view of doubles using a color gradient. This asserts if the input and // colored image dimensions (rows/columns) do not match void Colorize( const ImageConstView1d& input, const ColorGradient& gradient, double min, double max, ImageView3ub& colored); // Colorizes a tensor of floats using a color gradient. This asserts if the input and colored // image dimensions (rows/columns) do not match void Colorize( const CpuTensorConstView2f& input, const ColorGradient& gradient, float min, float max, ImageView3ub& colored); // Colorizes a tensor of doubles using a color gradient. This asserts if the input and colored // image dimensions (rows/columns) do not match void Colorize( const CpuTensorConstView2d& input, const ColorGradient& gradient, double min, double max, ImageView3ub& colored); // A list of colors which can be used to get a color based on an integer class IndexedColors { public: // Creates a list with two colors: black and white IndexedColors() : colors_({Pixel3ub::Zero(), Pixel3ub{255, 255, 255}}) {} // Initializes the object with the given list of colors IndexedColors(std::initializer_list colors) : colors_(colors) {} // Creates a list of random colors IndexedColors(size_t count, size_t seed) : colors_(count) { colors_[0] = Pixel3ub::Zero(); std::default_random_engine rng(seed); std::uniform_int_distribution rnd(0, 255); for (size_t i = 1; i < colors_.size(); i++) { colors_[i] = Pixel3ub{rnd(rng), rnd(rng), rnd(rng)}; } } // Retrieves the color for the given index. If there are not enough colors the index is wrapped. const Pixel3ub& operator()(int index) const { const int value = index % colors_.size(); return colors_[value >= 0 ? value : (value + colors_.size())]; } private: std::vector colors_; }; // 256 random colors using a default seed IndexedColors Random256IndexedColors(); // 22 distinct colors after Sasha Trubetskoy IndexedColors Distinct22IndexedColors(); // Colorizes an image of indices using a list of colors template void ColorizeIndices( const ImageConstView& indices, const IndexedColors& colors, Image3ub& result) { const size_t rows = indices.rows(); const size_t cols = indices.cols(); result.resize(indices.dimensions()); for (size_t row = 0; row < rows; row++) { for (size_t col = 0; col < cols; col++) { result(row, col) = colors(indices(row, col)); } } } // Colorizes an image of indices using a list of colors. This asserts if the input and colored // image dimensions (rows/columns) do not match template void ColorizeIndices( const ImageConstView& indices, const IndexedColors& colors, ImageView3ub& result) { ASSERT( result.rows() == indices.rows() && result.cols() == indices.cols(), "Output dimension (%d, %d) != Input dimension (%d, %d)", result.rows(), result.cols(), indices.rows(), indices.cols()); const size_t rows = indices.rows(); const size_t cols = indices.cols(); for (size_t row = 0; row < rows; row++) { for (size_t col = 0; col < cols; col++) { result(row, col) = colors(indices(row, col)); } } } // ------------------------------------------------------------------------------------------------- template void ColorGradient::setColors(It begin, It end) { colors_.clear(); colors_.reserve(std::distance(begin, end)); for (; begin != end; ++begin) { colors_.push_back(ToPixel3f(*begin)); } } inline Pixel3ub ColorGradient::operator()(float p) const { if (colors_.empty()) { return Colors::Pink(); } const float pn = static_cast(colors_.size() - 1) * p; const int pi = std::floor(pn); if (pi < 0) { return ToPixel3ub(colors_.front()); } if (static_cast(pi + 1) >= colors_.size()) { return ToPixel3ub(colors_.back()); } const float pr = pn - static_cast(pi); return ToPixel3ub(Interpolate(pr, colors_[pi], colors_[pi + 1])); } // Converts a pixel from RGB scheme to HSV // Reference for conversion: https://en.wikipedia.org/wiki/HSL_and_HSV void ConvertRGBToHSV(PixelRef3ub pixel); // Converts a pixel from HSV scheme to RGB // Reference for conversion: https://en.wikipedia.org/wiki/HSL_and_HSV void ConvertHSVToRGB(PixelRef3ub pixel); } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/image/io.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gems/algorithm/string_utils.hpp" #include "gems/core/image/image.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { // Gets the dimensions of an image. The dimensions are written to `shape` in the order: // rows (0), cols (1), channels (2). bool LoadImageShape(const std::string& filename, Vector3i& shape); // Loads an image from a PNG file. The function will return false if the PNG could not be loaded. // This can for example happen if the filename is invalid or if the PNG doesn't have the requested // format. bool LoadPng(const std::string& filename, Image1ub& image); bool LoadPng(const std::string& filename, Image1ui16& image); bool LoadPng(const std::string& filename, Image3ub& image); bool LoadPng(const std::string& filename, Image4ub& image); bool LoadPng(const std::string& filename, ImageView1ub& tensor); bool LoadPng(const std::string& filename, ImageView3ub& tensor); bool LoadPng(const std::string& filename, CpuTensorView2ub& tensor); // Loads an image from a JPEG file. The function will return false if the JPEG could not be loaded. // This can for example happen if the filename is invalid or if the JPEG doesn't have the requested // format. bool LoadJpeg(const std::string& filename, Image1ub& image); bool LoadJpeg(const std::string& filename, Image3ub& image); bool LoadJpeg(const std::string& filename, ImageView1ub& image); bool LoadJpeg(const std::string& filename, ImageView3ub& image); // Loads an image from JPEG file or PNG file. The function will return false if the image could not // be loaded. bool LoadImage(const std::string& filename, Image1ub& image); bool LoadImage(const std::string& filename, Image3ub& image); bool LoadImage(const std::string& filename, ImageView1ub& image); bool LoadImage(const std::string& filename, ImageView3ub& image); // Saves an image to a file in the PNG format. The function will return false if the PNG could not // saved. This might for example happen if the file could not be opened. bool SavePng(const ImageConstView1ub& image, const std::string& filename); bool SavePng(const ImageConstView3ub& image, const std::string& filename); bool SavePng(const ImageConstView4ub& image, const std::string& filename); bool SavePng(const ImageConstView1ui16& image, const std::string& filename); // Saves an image to a file in the JPEG format. The function will return false if the JPEG could not // saved. This might for example happen, if the file could not be opened. Quality of 100 means // nearly lossless, but slow to encode and result in bigger images. While quality of 1 is fast // and produce very small image with a very low quality. (Note: 75 seems a good compromise) bool SaveJpeg(const ImageConstView1ub& image, const std::string& filename, const int quality = 75); bool SaveJpeg(const ImageConstView3ub& image, const std::string& filename, const int quality = 75); // Encodes an image into a buffer in the PNG format void EncodePng(const ImageConstView1ub& image, std::vector& encoded); void EncodePng(const ImageConstView3ub& image, std::vector& encoded); void EncodePng(const ImageConstView4ub& image, std::vector& encoded); // Encodes an image into a file in the JPEG format // Quality of 100 is nearly lossless but slow to encode and result in bigger images while 1 is fast // and produce very small image with a very low quality. (Note: 75 seems a good compromise) void EncodeJpeg(const ImageConstView1ub& image, int quality, std::vector& encoded); void EncodeJpeg(const ImageConstView3ub& image, int quality, std::vector& encoded); // Decodes a PNG encoded byte string. The function will return false if the PNG could not be // decoded, for example if the byte string is not a valid PNG. bool DecodePng(const std::string& bytes, Image1ub& image); bool DecodePng(const std::string& bytes, Image1ui16& image); bool DecodePng(const std::string& bytes, Image3ub& image); bool DecodePng(const std::string& bytes, Image4ub& image); bool DecodePng(const std::string& bytes, ImageView1ub& tensor); bool DecodePng(const std::string& bytes, ImageView3ub& tensor); bool DecodePng(const std::string& bytes, CpuTensorView2ub& tensor); // Gets the dimensions of an image from a PNG encoded byte string. The dimensions are written to // `shape` in the order: rows (0), cols (1), channels (2). bool DecodePngShape(const std::string& bytes, Vector3i& shape); } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/image/utils.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include #include "gems/core/assert.hpp" #include "gems/core/buffers/algorithm.hpp" #include "gems/core/image/image.hpp" #include "gems/core/math/types.hpp" namespace nvidia { namespace isaac { // Copies an image template void Copy(const ImageBase& source, ImageBase& target); // Sets all pixels of an image to the given value template void FillPixels(ImageBase& image, const Pixel& value); // Sets all elements of all pixels to the given `value` template void FillElements(ImageBase& image, K value); // Sets all elements of all pixels to 0 template void FillElementsWithZero(ImageBase& image) { FillElements(image, K(0)); } // Resize down an image by a factor N. template Image Reduce(const ImageBase& img); template Image Reduce(const ImageBase& img, int factor); // Enlarge an image by a factor N template Image Enlarge(const Image& img); // Convert an image from a format to another given a pixel conversion function template Out Convert(const In& img, F convert); template void Convert(const In& img, Out& out, F convert); // Normalizes an image template void Normalize(const ImageBase& input, Image1ub& output); template void Normalize(const ImageBase& input, K min, K max, Image1ub& output); // Crops the image template void Crop(const ImageBase& img, const Vector2i& crop_start, const Vector2i& crop_size, Image& dest_img); // Convert disparity to depth using baseline and focal length. // The disparity_img is expected to be in pixels // The depth will have same unit as baseline. The baseline, min_depth and max_depth should all be // in the same units. template ::value, int>::type = 0> void ConvertDisparityToDepth(const ImageBase& disparity_img, K baseline, K focal_length_px, K min_depth, K max_depth, Image& depth_img); // Stitches two images (with same number of rows) together side by side void JoinTwoImagesSideBySide(const ImageConstView3ub& left_image, const ImageConstView3ub& right_image, Image3ub& joint_image); // Splits an image into two halfs void SplitImages(const ImageConstView3ub& joint, Image3ub& left, Image3ub& right); // ------------------------------------------------------------------------------------------------- template void Copy(const ImageBase& source, ImageBase& target) { // Asserts that images have the same shape ASSERT(source.rows() == target.rows(), "row count mismatch: %zu vs %zu", source.rows(), target.rows()); ASSERT(source.cols() == target.cols(), "col count mismatch: %zu vs %zu", source.cols(), target.cols()); // Copy the bytes CopyMatrixRaw(reinterpret_cast(source.element_wise_begin()), source.getStride(), BufferTraits::kStorageMode, reinterpret_cast(target.element_wise_begin()), target.getStride(), BufferTraits::kStorageMode, source.rows(), source.cols() * N * sizeof(K)); } template void FillPixels(ImageBase& image, const Pixel& pixel) { for (int row = 0; row < image.rows(); row++) { for (int col = 0; col < image.cols(); col++) { image(row, col) = pixel; } } } template void FillPixels(ImageBase& image, K pixel) { // Use the faster FillElements for 1-channel images FillElements(image, pixel); } template void FillElements(ImageBase& image, K value) { const int elements_per_row = image.channels() * image.cols(); for (int row = 0; row < image.rows(); row++) { K* row_pointer = image.row_pointer(row); std::fill(row_pointer, row_pointer + elements_per_row, value); } } template Image Reduce(const ImageBase& img) { Image out(img.rows() / Factor, img.cols() / Factor); for (int row = 0; row < out.rows(); row++) { for (int col = 0; col < out.cols(); col++) { out(row, col) = img(Factor * row, Factor * col); } } return out; } template Image Reduce(const ImageBase& img, int factor) { Image out(img.rows() / factor, img.cols() / factor); for (int row = 0; row < out.rows(); row++) { for (int col = 0; col < out.cols(); col++) { out(row, col) = img(factor * row, factor * col); } } return out; } template Image Enlarge(const Image& img) { Image out(img.rows() * NRows, img.cols() * NCols); for (int row = 0; row < out.rows(); row++) { for (int col = 0; col < out.cols(); col++) { out(row, col) = img(row / NRows, col / NCols); } } return out; } template Out Convert(const In& img, F convert) { Out out(img.rows(), img.cols()); for (int pixel = 0; pixel < out.num_pixels(); pixel++) { out[pixel] = convert(img[pixel]); } return out; } template void Convert(const In& img, Out& out, F convert) { ASSERT(out.dimensions() == img.dimensions(), "dimensions mismatch"); for (int pixel = 0; pixel < out.num_pixels(); pixel++) { out[pixel] = convert(img[pixel]); } } template void Normalize(const ImageBase& input, Image1ub& output) { K min = input[0]; K max = input[0]; for (int pixel = 0; pixel < input.num_pixels(); pixel++) { min = std::min(min, input[pixel]); max = std::max(max, input[pixel]); } if (min == max) { min -= K(1.0); max += K(1.0); } output = Convert( input, [&](K val) { return static_cast(K(255.9) * (val - min) / (max - min)); }); } template void Normalize(const ImageBase& input, K min, K max, Image1ub& output) { ASSERT(min < max, "Invalid range"); Convert(input, output, [&](K val) { return static_cast(K(255.9) * Clamp01((val - min) / (max - min))); }); } template void Crop(const ImageBase& img, const Vector2i& crop_start, const Vector2i& crop_size, Image& dest_img) { ASSERT((crop_start.array() >= 0).all(), "Invalid crop start location."); ASSERT((crop_size.array() > 0).all(), "Invalid crop size."); Vector2i img_size{img.rows(), img.cols()}; ASSERT(((crop_start + crop_size).array() <= img_size.array()).all(), "Invalid crop size"); EigenImageConstMap eigen_img(img.element_wise_begin(), img.rows(), img.cols() * N); dest_img.resize(crop_size[0], crop_size[1]); EigenImageMap eigen_dest_img(dest_img.element_wise_begin(), dest_img.rows(), dest_img.cols() * N); eigen_dest_img = eigen_img.block(crop_start[0], crop_start[1] * N, crop_size[0], crop_size[1] * N); } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/pose_tree/pose_tree.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include // NOLINT(build/include_order) #include #include #include #include "common/unique_index_map.hpp" #include "gems/core/math/pose2.hpp" #include "gems/core/math/pose3.hpp" #include "gems/gxf_helpers/expected_macro_gxf.hpp" #include "gems/pose_tree/pose_tree_edge_history.hpp" #include "gxf/core/component.hpp" #include "gxf/std/gems/suballocators/first_fit_allocator.hpp" namespace nvidia { namespace isaac { // A temporal pose tree to store relative coordinate system transformations over time. // This implementation does not support multiple paths between the same coordinate systems at a // given time. It does however allow to disconnect edge and create new connection using a different // path. It also allows for multiple "roots". In fact the transformation relationships form an // acylic, bi-directional, not necessarily fully-connected graph. // This PoseTree assigned a different version id to each operation that affects it, and this version // can be used to make a query ignore later changes made to the tree. class PoseTree : public gxf::Component { public: // Error codes used by this class. enum class Error { // kInvalidArgument is returned when a function is called with argument that does not make sense // such as negative number of frames. kInvalidArgument = 0, // kOutOfMemory is returned if `initialize` failed to allocate the requested memory, or if an // edge/frame can't be added because we run out of the pre-allocated memory. kOutOfMemory = 1, // kFrameNotFound is returned if a query is made with a frame uid that does not match any // existing frame. kFrameNotFound = 2, // kAlreadyExists is returned if a frame or an edge that already exist is added. kAlreadyExists = 3, // kCyclingDependency is returned if a pose is added that would create a cycle in the PoseTree // structure. kCyclingDependency = 4, // kFramesNotLinked is returned if a query is made between two not connected frame or if we // attempt to disconnect/delete an edge that does not exist. kFramesNotLinked = 5, // kPoseOutOfOrder is returned if a query is made to update the three in the past. For example // if we try to disconnect or update a pose at a time older than the latest update on this edge. kPoseOutOfOrder = 6, // kLogicError is used whenever an error that should not have happened happened. This should // never happen and are here only to prevent crashes/assert, kLogicError = 7, }; // The maximum size for the name of a frame. An additional '\0' is added at the end to make it // 64 characters long. static constexpr int32_t kFrameNameMaximumLength = 63; // Auto generated frame names will start with this prefix, followed by the uid of the frame. static constexpr char const* kAutoGeneratedFrameNamePrefix = "_frame_"; // Expected type used by this class. template using Expected = nvidia::Expected; // Unexpected type used by this class. using Unexpected = nvidia::Unexpected; // Type used to uniquely identify a frame. using frame_t = uint64_t; // Type used for versioning the PoseTree. using version_t = uint64_t; // Type used as a key for the PoseTreeEdgeHistory map. using history_t = uint64_t; // Type for callback functions that are called every time a frame is created. using CreateFrameCallback = std::function; // Type for callback functions that are called every time an edge is set. using SetEdgeCallback = std::function; // Allocates space for a given number of total frames and total number of edges. // Total amount of memory required is approximately: // number_frames * 128 + number_edges * 64 + history_length * 72. Expected init(int32_t number_frames, int32_t number_edges, int32_t history_length, int32_t default_number_edges, int32_t default_history_length, int32_t edges_chunk_size, int32_t history_chunk_size); void deinit(); // Returns the current PoseTree version. version_t getPoseTreeVersion() const; // Creates a new frame in the PoseTree. An optional name may be given to give a human-readable // name to the frame. The name is a null-terminated string with at most 63 characters. User // defined name cannot start with "_", which is reserved for auto generated names such as // "_frame_i", where i is the uid of the frame. hint on the maximum number of edges this frame // will be connected to can be provided. Returns the frame id. Expected createFrame(const char* name, int32_t number_edges); Expected createFrame(const char* name); Expected createFrame(int32_t number_edges); Expected createFrame(); // Finds a frame with the given name, and returns the frame id. If no such frame exist, it returns // Error::kFrameNotFound Expected findFrame(const char* name) const; // Finds a frame with the given name, and returns the frame id. If no such frame exist, it creates // a new frame by calling the equivalent createFrame function. Expected findOrCreateFrame(const char* name); Expected findOrCreateFrame(const char* name, int32_t number_edges); // Creates an edge between the left hand side (lhs) frame and the right hand side (rhs) frame. // A hint on the maximum length needed can be provided. // Upon success, it returns the version id of the change. Expected createEdges(frame_t lhs, frame_t rhs); Expected createEdges(frame_t lhs, frame_t rhs, int32_t maximum_length); Expected createEdges(frame_t lhs, frame_t rhs, PoseTreeEdgeHistory::AccessMethod method); Expected createEdges(frame_t lhs, frame_t rhs, int32_t maximum_length, PoseTreeEdgeHistory::AccessMethod method); // Deletes a frame in the PoseTree and all its relations to other frames and frees its memory. // This action is permantly erasing the history information. // Upon success, it returns the version id of the change (however query made with a previous // version will also consider the frame as deleted). Expected deleteFrame(frame_t uid); // Deletes an edge and frees the memory. // This action is permantly erasing the history. // Upon success, it returns the version id of the change (however query made with a previous // version will also consider the edge as deleted). Expected deleteEdge(frame_t lhs, frame_t rhs); // Disconnects a frame from all the others starting at a given time. // Upon success, it returns the version id of the change. Expected disconnectFrame(frame_t uid, double time); // Disconnects an edge starting at a given time. // Upon success, it returns the version id of the change. Expected disconnectEdge(frame_t lhs, frame_t rhs, double time); // Disable all the implicit cast (to make sure to catch a call with the wrong type for the time) template Expected<::nvidia::isaac::Pose3d> disconnectFrame(Args&&... args) = delete; template Expected<::nvidia::isaac::Pose3d> disconnectEdge(Args&&... args) = delete; // Gets the name of a frame. Expected getFrameName(frame_t uid) const; // Gets the latest pose between two frames as well as the time of that pose. // The two poses needs to be directly linked Expected> getLatest(frame_t lhs, frame_t rhs) const; Expected> getLatest(const char* lhs, const char* rhs) const; // Gets the pose lhs_T_rhs between two frames in the PoseTree at the given time. If the poses are // not connected exactly at the given time, the indicated method is used to interpolate the data. Expected<::nvidia::isaac::Pose3d> get(frame_t lhs, frame_t rhs, double time, PoseTreeEdgeHistory::AccessMethod method, version_t version) const; Expected<::nvidia::isaac::Pose3d> get(frame_t lhs, frame_t rhs, double time, version_t version) const; Expected<::nvidia::isaac::Pose3d> get(frame_t lhs, frame_t rhs, double time, PoseTreeEdgeHistory::AccessMethod method) const; Expected<::nvidia::isaac::Pose3d> get(frame_t lhs, frame_t rhs, double time) const; // Same as above, but using the name as interface. Expected<::nvidia::isaac::Pose3d> get(const char* lhs, const char* rhs, double time, PoseTreeEdgeHistory::AccessMethod method, version_t version) const; Expected<::nvidia::isaac::Pose3d> get(const char* lhs, const char* rhs, double time, version_t version) const; Expected<::nvidia::isaac::Pose3d> get(const char* lhs, const char* rhs, double time, PoseTreeEdgeHistory::AccessMethod method) const; Expected<::nvidia::isaac::Pose3d> get(const char* lhs, const char* rhs, double time) const; // Disable all the implicit cast (to make sure to catch a call with the wrong type for the time) template Expected<::nvidia::isaac::Pose3d> get(Args&&... args) const = delete; // Helper function to get a Pose2d instead of Pose3d template Expected<::nvidia::isaac::Pose2d> getPose2XY(Args&&... args) const { return get(std::forward(args)...).map([](const ::nvidia::isaac::Pose3d& pose_3d) { return pose_3d.toPose2XY(); }); } // The last time at which the pose between two frames is specified. // TODO(bbutin): Implement the following methods. // Expected latest(frame_t lhs, frame_t rhs, version_t version) const; // Expected latest(frame_t lhs, frame_t rhs) const; // Sets the pose between two frames in the PoseTree. Note that poses can not be changed // retrospectively. Thus for example once the pose at time t=2.0 is set it is no longer allowed // to set the pose for time t <= 2.0. It is not allowed to form cycles. Frames are implicitly // linked. If more than the maximum number of allowed poses are set the oldest pose is deleted. // Upon success, it returns the version id of the change. Expected set(frame_t lhs, frame_t rhs, double time, const ::nvidia::isaac::Pose3d& lhs_T_rhs); // Same as above, but using the name as interface. Expected set(const char* lhs, const char* rhs, double time, const ::nvidia::isaac::Pose3d& lhs_T_rhs); // Helper function to set a Pose2d instead of Pose3d Expected set(frame_t lhs, frame_t rhs, double time, const ::nvidia::isaac::Pose2d& lhs_T_rhs) { return set(lhs, rhs, time, ::nvidia::isaac::Pose3d::FromPose2XY(lhs_T_rhs)); } // Same as above, but using the name as interface. Expected set(const char* lhs, const char* rhs, double time, const ::nvidia::isaac::Pose2d& lhs_T_rhs) { return set(lhs, rhs, time, ::nvidia::isaac::Pose3d::FromPose2XY(lhs_T_rhs)); } // Disable all the implicit cast (to make sure to catch a call with the wrong type for the time) // First we define a function that will match all the call with double and forward it to the // appropirate function. This is needed in case the Pose is provided by value. template Expected set(Frame lhs, Frame rhs, double time, const Pose lhs_T_rhs) { return set(lhs, rhs, time, lhs_T_rhs); } // Then we disable all the calls not made with double. template Expected set(Frame lhs, Frame rhs, T time, const Pose& lhs_T_rhs) = delete; // Get list of edges std::vector> edges() const; // Registers a callback function for every time a frame is created. If a callback function // does not already exist for the provided commponent id cid. Expected addCreateFrameCallback(gxf_uid_t cid, CreateFrameCallback callback); // Deregisters a callback function for time an edge is set. If there is no callback function for // the component id cid, this function returns an error. Expected removeCreateFrameCallback(gxf_uid_t cid); // Registers a callback function for every time an edge is set. If a callback function // does not already exist for the provided commponent id cid. Expected addSetEdgeCallback(gxf_uid_t cid, SetEdgeCallback callback); // Deregisters a callback function for time an edge is set. If there is no callback function for // the component id cid, this function returns an error. Expected removeSetEdgeCallback(gxf_uid_t cid); // Helper function to transform an error code into an human readable error. static const char* ErrorToStr(Error error); private: // Helper structure that stores the information about a frame. struct FrameInfo { // Array containg the list of edges. history_t* history; // Current number of edges int32_t number_edges; // Maximum number of edges allowed int32_t maximum_number_edges; // Name of the frame. It has to be null terminated, so it can hold at most 63 characters. char name[kFrameNameMaximumLength + 1]; // Hint to quickly find a path: // Store the distance from the node to the root (== 0 if this frame is the root) int32_t distance_to_root; // Frame to follow to reach the root frame_t node_to_root; // Name of the root frame_t root; // Some helper id to computer the path between two nodes mutable version_t hint_version; // Some helper to memorize the path we took during the dfs mutable frame_t dfs_link; // Name of the frame. frame_t uid; }; // Helper class to compare to const char* // TODO(ben): Remove once we get rid of map struct CharMapCompare { bool operator()(const char* lhs, const char* rhs) const { return std::strcmp(lhs, rhs) < 0; } }; // Implementation of findOrCreateFrame Expected findOrCreateFrameImpl(const char* name, int32_t number_edges); // Implementation of findFrame Expected findFrameImpl(const char* name) const; // Implementation of createFrame Expected createFrameImpl(const char* name, int32_t number_edges); // Implementation of createEdges Expected createEdgesImpl(frame_t lhs, frame_t rhs, int32_t maximum_length, PoseTreeEdgeHistory::AccessMethod method); // Implementation of deleteEdge Expected deleteEdgeImpl(frame_t lhs, frame_t rhs, version_t version); // Update the path to the root for a given connected component starting from the given node. Expected updateRoot(frame_t root); // Implementation of get using the pre-computed path to the root as a hint. If it fails, it falls // back to getDfsImpl. Expected<::nvidia::isaac::Pose3d> getImpl(frame_t lhs, frame_t rhs, double time, PoseTreeEdgeHistory::AccessMethod method, version_t version) const; // Implementation of get that do a dfs to see if a path exists at a given time. Expected<::nvidia::isaac::Pose3d> getDfsImpl(frame_t lhs, frame_t rhs, double time, PoseTreeEdgeHistory::AccessMethod method, version_t version) const; // Lock to protect access to the parameter below. mutable std::shared_timed_mutex mutex_; // Lock to protect access to getDfsImpl. This function is rarely called, but can be called while // mutex_ is lock in read access, and getDfsImpl is modifying the dfs_link of some frames as well // as using the frames_stack_. We need a special protection for this function while not blocking // all the concurrent read which most likely won't call it. mutable std::mutex dfs_mutex_; // Lock to protect create_frame_callbacks_ mutable std::shared_timed_mutex create_frame_callbacks_mutex_; // Callback functions for the create frame operation. // TODO(dbhaskara): Replace with UniqueIndexMap once it supports iteration through all elements std::unordered_map create_frame_callbacks_; // Lock to protect set_edge_callbacks_ mutable std::shared_timed_mutex set_edge_callbacks_mutex_; // Callback functions for the set edge operation. // TODO(dbhaskara): Replace with UniqueIndexMap once it supports iteration through all elements std::unordered_map set_edge_callbacks_; // Mapping from a frame to it's index. // TODO(ben): We need to get rid of std::map std::map, history_t> edges_map_; // TODO(ben): We need to get rid of std::map, but for now UniqueIndexMap does not support // iterating through all the elements. std::map name_to_uid_map_; // Store the list of the current frame of the PoseTree. UniqueIndexMap frame_map_; // Used to implement a dfs. std::unique_ptr frames_stack_; // Store the list of PoseTreeEdgeHistory used by the frames. Each PoseTreeEdgeHistory correspond // to a bi-directional edge. UniqueIndexMap histories_map_; // Helper to `allocate` an array of PoseTreeEdgeHistory (storing only the uid). gxf::FirstFitAllocator histories_management_; // Helper to `allocate` an array of TimedPose. gxf::FirstFitAllocator poses_management_; // Current version of the PoseTree. frame_t version_; // Version of the hint. Mostly used to know if a node in the stack has been processed already. mutable frame_t hint_version_; // Default maximum number of edges a given frame can have int32_t default_number_edges_; // Default length of the history used by an edge. int32_t default_history_length_; }; } // namespace isaac } // namespace nvidia // We configure the expected macro to work with PoseTree::Error. The configuration has to happen in // exactly this namespace. namespace nvidia::expected_macro { template <> struct IsStatus<::nvidia::isaac::PoseTree::Error> : std::true_type {}; } // namespace nvidia::expected_macro ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/pose_tree/pose_tree_edge_history.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2020-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/math/pose3.hpp" #include "gxf/core/expected.hpp" namespace nvidia { namespace isaac { // Class that stores an history of Poses (using pre-allocated memory and a cyclic buffer) and // provides helper function to add a new pose or query the pose at a given time. class PoseTreeEdgeHistory { public: // Interpolation method for accessing poses in the pose tree enum class AccessMethod { // Gets the value of the closest sample kNearest, // Interpolates linearly between adjacent samples. If the query is outside the validity range, // the closest pose will be returned. kInterpolateLinearly, // Inter- or extrapolates linearly based on neighbouring samples. This require at least two // valid poses or Error::kOutOfRange will be returned. kExtrapolateLinearly, // Interpolates with slerp between adjacent samples. If the query is outside the validity range, // the closest pose will be returned. kInterpolateSlerp, // Inter- or extrapolates with slerp based on neighbouring samples. This require at least two // valid poses or Error::kOutOfRange will be returned. kExtrapolateSlerp, // Use the latest Pose before a given time. kPrevious, // Fallback to the default interpolation kDefault, }; // Error codes used by this class. enum class Error { // kInvalidArgument is returned when a function is called with argument that does not make sense // such as querying a pose outside the valid range or provide a wrong interpolation method. kInvalidArgument, // kOutOfOrder is returned when a set/disconnected called is made with a version or time // lower than the latest TimedPose. Both time and version must be stricly increasing. kOutOfOrder, // kFramesNotLinked is returns if a get query is made and the tree is not connected at the given // time and version of the edge. kFramesNotLinked, // kOutOfRange is returned if not enough poses are available to do extrapolation or if the // available buffer is too small to store a new pose. kOutOfRange, }; // Expected type used by this class. template using Expected = nvidia::Expected; // Unexpected type used by this class. using Unexpected = nvidia::Unexpected; // Type used to uniquely identify a frame. using frame_t = uint64_t; // Type used for versioning the edge. using version_t = uint64_t; // Helper structure to store the pose at a given time on the edge. struct TimedPose { // 3D pose that transforms the lhs frame into the rhs frame. ::nvidia::isaac::Pose3d pose; // Time of the pose. Needs to be strictly increasing. double time; // Version ID of the pose. Needs to be strictly increasing. version_t version; // If false, then it marks the edge as being disconnected from this current time. The pose does // not matter. bool valid; }; // Default constructor used to be able to pre-allocate memory. PoseTreeEdgeHistory() = default; // Constructor to actually uses the object: // `buffer` is a pre allocated buffer that can old `maximum_size` elements. PoseTreeEdgeHistory(frame_t lhs, frame_t rhs, int32_t maximum_size, TimedPose* buffer); PoseTreeEdgeHistory(frame_t lhs, frame_t rhs, int32_t maximum_size, AccessMethod access_method, TimedPose* buffer); // Sets the pose at a given amount of time. If the array is empty Error::kOutOfMemory will be // returned, otherwise if a pose already exist and `time` or `version` <= pose.time/version then // Error::kOutOfOrder is returned. Otherwise it will succeed, and if the history already // contained maximum_size_ element, then the oldest pose will be forgotten. Expected set(double time, const ::nvidia::isaac::Pose3d& pose, version_t version); // Returns the TimedPose at a given position. If index is negative Error::kInvalidArgument will be // returned, and if index >= size, then Error::kOutOfRange will be returned. Expected at(int32_t index) const; // Returns the Pose3d at a given time using the given version of the PoseTree. // If no pose existed at the given time, Error::kFramesNotLinked will be returned. // The desired method can be provided, for kExtrapolateLinearly, at least two poses are required. Expected<::nvidia::isaac::Pose3d> get(double time, AccessMethod method, version_t version) const; // Disconnects a frame at a given time. Expected disconnect(double time, version_t version); // Returns whether or not the frame are current connected bool connected() const; // Resets the history, all the poses will be erased. void reset(); // Returns the information about the latest pose Expected latest() const; // Returns a pointer to the buffer. const TimedPose* data() const { return edges_info_; } // Returns the current size. int32_t size() const { return size_; } // Returns the maximum number of poses this edge can contain. int32_t maximum_size() const { return maximum_size_; } // This edge reprensent the transformation from the rhs frame to the lhs frame. This function // returns the uid of the lhs frame. frame_t lhs() const { return lhs_; } // This edge reprensent the transformation from the rhs frame to the lhs frame. This function // returns the uid of the rhs frame. frame_t rhs() const { return rhs_; } private: // Reserves a new pose for a given time/version and returns it's index. // If there exists another pose with a later time/version, it returns kOutOfOrder. Expected reserveNewPose(double time, version_t version); // Mutex to protect changes to this object. mutable std::shared_timed_mutex mutex_; // Pointers to the buffer that contains the list of TimedPose (we use a circulat buffer to access // it). TimedPose* edges_info_ = nullptr; // Name of the frame this edge connects to. frame_t lhs_, rhs_; // Size of the buffer, aka maximum number of elements this edge can store in the same time. int32_t maximum_size_ = 0; // Current number of poses on this edge. int32_t size_ = 0; // Position of the first pose in the circular buffer, int32_t pos_ = 0; // Default access method. AccessMethod default_access_method_; }; } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/serialization/base64.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/image/image.hpp" namespace nvidia { namespace isaac { namespace serialization { // Encodes an Image3ub image into a Bitmap image base 64 encoded ready to be used in HTML code. // WARNING: The image is converted to BMP format which requires the memory to be 4-alligned at the // beginning of each row. In order to avoid memory copy and keep the code efficient, the encoded // image might contain more additional columns filled with random data, it will be the // responsability of the consumer to ignore these columns. std::string Base64Encode(const Image1ub& image); std::string Base64Encode(const Image3ub& image); // Encodes some data in base 64. std::string Base64Encode(const uint8_t* bytes_to_encode, size_t in_len); // Decode a base 64 encoded string into its original format. std::string Base64Decode(const std::string& encoded_string); } // namespace serialization } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/serialization/json.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include "gems/core/optional.hpp" #include "third_party/nlohmann/json.hpp" namespace nvidia { namespace isaac { // We are using nlohmann::json as JSON using Json = nlohmann::json; namespace serialization { // Loads and parses a JSON object from a file Json LoadJsonFromFile(const std::string& filename); // Parses a JSON object from a text string // @deprecated Json LoadJsonFromText(const std::string& text); // Checks if the given file does not exist or is empty bool IsFileEmpty(const std::string& filename); // Appends two json objects into one: if the duplicate keys are found in the input objects, // values are appended as array in the output object, second value is appended at back of array // only works for the top level json. Combines the unqiue keys found in the input objects. Json AppendJson(const Json& a, const Json& b); // Loads and parses a JSON object from a file without ASSERT // Returns nullopt in case of failure std::optional TryLoadJsonFromFile(const std::string& filename); // Writes JSON to a file bool WriteJsonToFile(const std::string& filename, const Json& json); // Merges two JSON objects into one: if duplicate keys are found in the input objects, // the value of the second object is written to the merged object. // Combines the unqiue keys found in the input objects. Json MergeJson(const Json& a, const Json& b); // Replace keys in the top level of json. In the key_map, the first value is the existing key to // replace and second value is the new key with which to replace it. // Returns the number of keys that were replaced (renaming a key to same name counts as a // replacement). int ReplaceJsonKeys(const std::map& key_map, Json& json); // Parses a JSON object from a text string std::optional ParseJson(const std::string& text); // Parses a JSON object from a string coming from an object such as a JSON or YAML. // The string should be enclosed inside "" or '' and the internal strings have their delimiter // escaped. For example: "{\"age\": 42}". std::optional ParseJsonFromString(const std::string& str); // Helper class for combining values in multiple JSON files and/or objects into one JSON object class JsonOperator { public: using OperationFunction = std::function; JsonOperator(OperationFunction operation_func) : operation_function_(operation_func) {} // Add JSON file to be combined JsonOperator& withFile(const std::string& json_filename) & { json_ = operation_function_(json_, LoadJsonFromFile(json_filename)); return *this; } // Add JSON file to be combined JsonOperator&& withFile(const std::string& json_filename) && { json_ = operation_function_(json_, LoadJsonFromFile(json_filename)); return std::move(*this); } // Add JSON object to be combined JsonOperator& withJson(const Json& json) & { json_ = operation_function_(json_, json); return *this; } // Add JSON object to be combined JsonOperator&& withJson(const Json& json) && { json_ = operation_function_(json_, json); return std::move(*this); } // Convert to JSON using a copy operator Json() const& { return json_; } // Convert to JSON using a move operator Json() && { return std::move(json_); } private: // Operation function to combine JSON OperationFunction operation_function_; // JSON being combined Json json_; }; } // namespace serialization } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/serialization/json_formatter.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include #include #include "gems/core/image/image.hpp" #include "gems/core/math/pose2.hpp" #include "gems/core/math/pose3.hpp" #include "gems/core/math/so2.hpp" #include "gems/core/math/so3.hpp" #include "gems/core/math/types.hpp" #include "gems/core/optional.hpp" #include "gems/geometry/line_segment.hpp" #include "gems/geometry/n_cuboid.hpp" #include "gems/geometry/n_sphere.hpp" #include "gems/serialization/json.hpp" namespace nvidia { namespace isaac { using Json = nlohmann::json; namespace serialization { // Gets the value from the json for the given key. template std::optional TryGet(const Json& json); // Sets a value in the json under the given key. template void Set(Json& json, T value); // Extracts the value for the given key from a JSON object. If the key does not exist in the JSON // object, or if the type does not match the desired type nullopt will be returned. template std::optional TryGetFromMap(const Json& json, const std::string& key) { try { const auto it = json.find(key); if (it == json.end()) { return std::nullopt; } else { return TryGet(*it); } } catch (...) { return std::nullopt; } } // Similar to `TryGetFromMap`, but will use the given default if the value could not be read template T GetFromMapOrDefault(const Json& json, const std::string& key, T backup) { if (auto maybe = TryGetFromMap(json, key)) { return *maybe; } else { return std::move(backup); } } // Given key_prefix, tries to get the angle both in radians and degrees, e.g., // if the key_prefix is "yaw", checks both "yaw_radians" and "yaw_degrees" values. // If only one of these keys exist, returns the angle in radians. template ::value>> std::optional TryGetAngleInRadiansFromMap(const Json& json, const std::string& key_prefix) { const std::string key_radians = key_prefix + "_radians"; const std::string key_degrees = key_prefix + "_degrees"; auto maybe_radians = TryGetFromMap(json, key_radians); auto maybe_degrees = TryGetFromMap(json, key_degrees); if (maybe_radians && maybe_degrees) { LOG_ERROR("Please set \"%s\" or \"%s\" only.", key_radians.c_str(), key_degrees.c_str()); return std::nullopt; } else if (maybe_radians) { return *maybe_radians; } else if (maybe_degrees) { return DegToRad(*maybe_degrees); } // Angle is not set return std::nullopt; } //-------------------------------------------------------------------------------------------------- namespace json_formatter_details { // A helper class used to format data for json. // Synposis: // static std::optional TryGet(const Json::json& json); // static void Set(const Json::json& json, T value); template struct JsonSerializer { static std::optional TryGet(const Json& json) { try { T x; from_json(json, x); return std::move(x); } catch (...) { return std::nullopt; } } static void Set(Json& json, T value) { to_json(json, value); } }; // Support for getting JSON from JSON template <> struct JsonSerializer { static const Json& TryGet(const Json& json) { return json; } static void Set(Json& json, Json value) { json = std::move(value); } }; // Parameter support for basic types: string, int, float, double, bool #define ISAAC_JSON_FORMATTER_FLOAT_PRIMITIVE(TYPE) \ template <> \ struct JsonSerializer { \ static std::optional TryGet(const Json& json) { \ const double* double_ptr = json.get_ptr(); \ if (double_ptr != nullptr) { \ return static_cast(*double_ptr); \ } \ const int64_t* int_ptr = json.get_ptr(); \ if (int_ptr == nullptr) { \ return std::nullopt; \ } else { \ return static_cast(*int_ptr); \ } \ } \ static void Set(Json& json, TYPE value) { \ json = static_cast(value); \ } \ }; ISAAC_JSON_FORMATTER_FLOAT_PRIMITIVE(float); ISAAC_JSON_FORMATTER_FLOAT_PRIMITIVE(double); // Parameter support for basic types: string, int, float, double, bool #define ISAAC_JSON_FORMATTER_PRIMITIVE(TYPE, JTYPE) \ template <> \ struct JsonSerializer { \ static std::optional TryGet(const Json& json) { \ const JTYPE* ptr = json.get_ptr(); \ if (ptr == nullptr) { \ return std::nullopt; \ } else { \ return static_cast(*ptr); \ } \ } \ static void Set(Json& json, TYPE value) { \ json = static_cast(value); \ } \ }; ISAAC_JSON_FORMATTER_PRIMITIVE(uint64_t, uint64_t); ISAAC_JSON_FORMATTER_PRIMITIVE(int64_t, int64_t); ISAAC_JSON_FORMATTER_PRIMITIVE(int, int64_t); ISAAC_JSON_FORMATTER_PRIMITIVE(bool, bool); ISAAC_JSON_FORMATTER_PRIMITIVE(std::string, std::string); // Parameter support for compile-sized Vectors. It uses doubles to store elements in the json. template struct JsonSerializer> { static std::optional> TryGet(const Json& json) { if (!json.is_array()) { return std::nullopt; } const int json_size = static_cast(json.size()); if (N != Eigen::Dynamic && json_size != N) { return std::nullopt; } Vector result(json_size); for (int i = 0; i < json_size; i++) { auto maybe = ::nvidia::isaac::serialization::TryGet(json[i]); if (!maybe) { return std::nullopt; } result[i] = *maybe; } return result; } static void Set(Json& json, const Vector& value) { json = Json(std::vector(value.data(), value.data() + value.size())); } template static void Set(Json& json, const Vector& value) { std::array data; for (int i = 0; i < M; i++) { data[i] = value[i]; } json = Json(data); } }; // For std::vector template struct JsonSerializer> { static std::optional> TryGet(const Json& json) { if (!json.is_array()) { return std::nullopt; } const size_t size = json.size(); std::vector result; result.reserve(size); for (size_t i = 0; i < size; i++) { auto maybe = ::nvidia::isaac::serialization::TryGet(json[i]); if (!maybe) { return std::nullopt; } result.push_back(*maybe); } return result; } static void Set(Json& json, const std::vector& value) { json = Json::array(); for (const auto& v : value) { Json vjson; ::nvidia::isaac::serialization::Set(vjson, v); json.push_back(vjson); } } }; // For std::array template struct JsonSerializer> { static std::optional> TryGet(const Json& json) { if (!json.is_array()) { return std::nullopt; } if (json.size() != N) { return std::nullopt; } std::array result; for (size_t i = 0; i < N; i++) { auto maybe = ::nvidia::isaac::serialization::TryGet(json[i]); if (!maybe) { return std::nullopt; } result[i] = *maybe; } return result; } static void Set(Json& json, const std::array& value) { json = Json::array(); // TODO reserve for (const auto& v : value) { Json vjson; ::nvidia::isaac::serialization::Set(vjson, v); json.push_back(vjson); } } }; // For std::pair template struct JsonSerializer> { static std::optional> TryGet(const Json& json) { if (!json.is_array()) { return std::nullopt; } if (json.size() != 2) { return std::nullopt; } auto maybe1 = ::nvidia::isaac::serialization::TryGet(json[0]); if (!maybe1) { return std::nullopt; } auto maybe2 = ::nvidia::isaac::serialization::TryGet(json[1]); if (!maybe2) { return std::nullopt; } return std::pair{*maybe1, *maybe2}; } static void Set(Json& json, const std::pair& value) { Json value1; ::nvidia::isaac::serialization::Set(value1, value.first); Json value2; ::nvidia::isaac::serialization::Set(value2, value.second); json = Json::array({value1, value2}); } }; // For std::map // Supporting general std::map would require array json, which we want to avoid for the time // being template struct JsonSerializer> { static std::optional> TryGet(const Json& json) { if (!json.is_object()) { return std::nullopt; } std::map result; for (const auto& val : json.items()) { auto maybe = ::nvidia::isaac::serialization::TryGet(val.value()); if (!maybe) { return std::nullopt; } result.emplace(val.key(), *maybe); } return result; } static void Set(Json& json, const std::map& value) { json = Json::object(); for (const auto& v : value) { json.emplace(v.first, v.second); } } }; // Parameter support for SO3. It uses doubles to store elements in the json. template struct JsonSerializer> { // Tries to get pose in two ways. The first method is kept for backward compatibility. static std::optional> TryGet(const Json& json) { // First method for backward compatibility. // Expected four elements are (w, x, y, z) values for the quaternion. // Example: [0.0, 0.0, 0.0, 1.0] if (json.is_array()) { auto maybe = JsonSerializer>::TryGet(json); if (!maybe) { return std::nullopt; } const auto& array = *maybe; return SO3::FromQuaternion(Quaternion{array[0], array[1], array[2], array[3]}); } // Second method for convenience. // Rotation can set by one of: // { "axis": [x, y, z], "angle_radians": a } // { "axis": [x, y, z], "angle_degrees": a } // { "roll_radians": r, "pitch_radians": p, "yaw_radians": y } // { "roll_degrees": r, "pitch_degrees": p, "yaw_degrees": y } // { "qx": x, "qy": y, "qz": z, "qw": w } // We'll demand one and only one way to be used. size_t num_rotation_ways_set = 0; // If error message gets populated, this function will return null. // This variable will help us prioritize num_rotation_ways_set check when printing an error. std::string error_message; SO3 rotation = SO3::Identity(); // { "axis": [x, y, z], "angle_radians": a } // { "axis": [x, y, z], "angle_degrees": a } auto maybe_axis = TryGetFromMap>(json, "axis"); auto maybe_angle = TryGetAngleInRadiansFromMap(json, "angle"); if (maybe_axis || maybe_angle) { num_rotation_ways_set++; if (maybe_angle && maybe_axis) { rotation = SO3::FromAngleAxis(*maybe_angle, *maybe_axis); } else { error_message = "Both \"axis\" and \"angle\" need to be set."; } } // { "roll_radians": r, "pitch_radians": p, "yaw_radians": y } // { "roll_degrees": r, "pitch_degrees": p, "yaw_degrees": y } auto maybe_roll = TryGetAngleInRadiansFromMap(json, "roll"); auto maybe_pitch = TryGetAngleInRadiansFromMap(json, "pitch"); auto maybe_yaw = TryGetAngleInRadiansFromMap(json, "yaw"); if (maybe_roll || maybe_pitch || maybe_yaw) { num_rotation_ways_set++; if (!maybe_roll) maybe_roll = 0.0; if (!maybe_pitch) maybe_pitch = 0.0; if (!maybe_yaw) maybe_yaw = 0.0; rotation = SO3::FromEulerAnglesRPY(*maybe_roll, *maybe_pitch, *maybe_yaw); } // { "qx": x, "qy": y, "qz": z, "qw": w } auto maybe_qx = TryGetFromMap(json, "qx"); auto maybe_qy = TryGetFromMap(json, "qy"); auto maybe_qz = TryGetFromMap(json, "qz"); auto maybe_qw = TryGetFromMap(json, "qw"); if (maybe_qx || maybe_qy || maybe_qz || maybe_qw) { num_rotation_ways_set++; if (maybe_qx && maybe_qy && maybe_qz && maybe_qw) { rotation = SO3::FromQuaternion(Quaternion{*maybe_qw, *maybe_qx, *maybe_qy, *maybe_qz}); } else { error_message = "\"qx\", \"qy\", \"qz\" and \"qw\" all need to be set."; } } // check that only one way is used. if (num_rotation_ways_set != 1) { LOG_ERROR("Rotation can be one of:"); LOG_ERROR("{ \"axis\": [x, y, z], \"angle\": a }"); LOG_ERROR("{ \"roll\": r, \"pitch\": p, \"yaw\": y }"); LOG_ERROR("{ \"qx\": x, \"qy\": y, \"qz\": z, \"qw\": w }"); LOG_ERROR("Please set one and only one of them."); return std::nullopt; } // If we had an issue, print the error and return null if (!error_message.empty()) { LOG_ERROR(error_message.c_str()); return std::nullopt; } return rotation; } static void Set(Json& json, const SO3& value) { json = Json(std::array{ {value.quaternion().w(), value.quaternion().x(), value.quaternion().y(), value.quaternion().z()}}); } }; // Parameter support for NSphere (where N is the dimension of the sphere) // Input serialization formats // In order of priority TryGet() will look in "json" for: // (1) A std::pair for which the first component contains an array of N numbers which represent // the center coordinates of the NSphere and the second component contains a single scalar // value representing the radius of the NSphere. // Ex. Json json = {{1.0, 2.0}, 3.0}; // represents a circle with center (1.0, 2.0) and radius 3.0 // (2) A Json object named "center" containing an array of N numbers which represent the center // coordinates of the NSphere AND a Json object named "radius" containing a single scalar // value representing the radius of the NSphere // Ex. Json json; // json["center"] = {1.0, 2.0, 3.0}; // json["radius"] = 4.0; // represents a sphere with center (1.0, 2.0, 3.0) and radius 4.0 // If neither format is available, std::nullopt will be returned. // Output serialization format: // A std::pair for which the first component contains an array of N numbers which represent the // center coordinates of the NSphere and the second component contains a single scalar value // representing the radius of the NSphere. template struct JsonSerializer> { using Sphere_t = geometry::NSphere; using Vector_t = typename geometry::NSphere::Vector_t; using Scalar_t = typename geometry::NSphere::Scalar; static std::optional TryGet(const Json& json) { // Try to get NSphere from format: {center_vector, radius_scalar} auto maybe = JsonSerializer>::TryGet(json); if (maybe) { return Sphere_t{maybe->first, maybe->second}; } // Try to get NSphere from named attributes for center and radius auto maybe_center = TryGetFromMap(json, "center"); auto maybe_radius = TryGetFromMap(json, "radius"); if (maybe_center && maybe_radius) { return Sphere_t{*maybe_center, *maybe_radius}; } return std::nullopt; } static void Set(Json& json, const Sphere_t& value) { ::nvidia::isaac::serialization::Set( json, std::pair{value.center, value.radius}); } }; // Parameter support for NCuboid (where N is the dimension of the cuboid) // Input serialization formats // In order of priority TryGet() will look in "json" for: // (1) A std::array of length N, for which each component contains an the minimum and maximum // bound for the Nth dimension. // Ex. Json json = {{-1.0, 1.0}, {-2.0, 2.0}}; // represents a rectangle with the x dimension spanning -1.0 to 1.0 and the y dimension // spanning -2.0 to 2.0. // (2) A Json object named "bounds" containing an array of length the N, for which each // component contains an the minimum and maximum bound for that dimension. // Ex. Json json; // json["bounds"] = {{-1.0, 1.0}, {-2.0, 2.0}}; // represents a rectangle with the x dimension spanning -1.0 to 1.0 and the y dimension // spanning -2.0 to 2.0. // (3) A Json object named "corner_1" containing an array of length the N representing the // coordinates of one corner AND another Json object named "corner_2" containing an array of // length the N representing the coordinates of the opposite corner. // Ex. Json json; // json["corner_1"] = {-1.0, -2.0}; // json["corner_2"] = { 1.0, 2.0}; // represents a rectangle with the x dimension spanning -1.0 to 1.0 and the y dimension // spanning -2.0 to 2.0. // (4) A Json object named "center" containing an array of length the N representing the // coordinates of the center of the NCuboid AND another Json object named "dimensions" // containing an array of length the N representing the length of each dimension. // Ex. Json json; // json["center"] = {0.0, 0.0}; // json["dimension"] = {2.0, 4.0}; // represents a rectangle with the x dimension spanning -1.0 to 1.0 and the y dimension // spanning -2.0 to 2.0. // If none of these formats are available, std::nullopt will be returned. // Output serialization format: // A std::array of length N, for which each component contains an the minimum and maximum // bound for the Nth dimension. template struct JsonSerializer> { using Cube_t = geometry::NCuboid; using Vector_t = typename geometry::NCuboid::Vector_t; using Vector2K = Vector; using ArrayNVector2K = std::array; static std::optional TryGet(const Json& json) { // Try to get NCuboid from bounding cuboid format: // {{min_dim_0, max_dim_0}, {min_dim_1, max_dim_1}, ... {min_dim_N, max_dim_N}} auto maybe = JsonSerializer>::TryGet(json); if (maybe) { return Cube_t::FromBoundingCuboid(*maybe); } // Try to get NCuboid from named bounds auto maybe_bounds = TryGetFromMap(json, "bounds"); if (maybe_bounds) { return Cube_t::FromBoundingCuboid(*maybe_bounds); } // Try to get NCuboid from named opposite corners auto maybe_corner_1 = TryGetFromMap(json, "corner_1"); auto maybe_corner_2 = TryGetFromMap(json, "corner_2"); if (maybe_corner_1 && maybe_corner_2) { return Cube_t::FromOppositeCorners(*maybe_corner_1, *maybe_corner_2); } // Try to get NCuboid from named center and dimensions auto maybe_center = TryGetFromMap(json, "center"); auto maybe_dimensions = TryGetFromMap(json, "dimensions"); if (maybe_center && maybe_dimensions) { return Cube_t::FromSizes(*maybe_center, *maybe_dimensions); } return std::nullopt; } static void Set(Json& json, const Cube_t& value) { ArrayNVector2K bounds; for (size_t dim = 0; dim < N; dim++) { bounds[dim] = Vector2K(value.min()[dim], value.max()[dim]); } ::nvidia::isaac::serialization::Set(json, ArrayNVector2K{bounds}); } }; // Parameter support for LineSegment // Input serialization formats // In order of priority TryGet() will look in "json" for: // (1) A std::pair for which the first component contains an array of N numbers which represent // the coordinates of the first endpoint and the second component contains an array of N // numbers which represent the coordinates of the second endpoint. // Ex. Json json = {{1.0, 2.0}, {3.0, 4.0}}; // represents a 2D line segment spanning from (1.0, 2.0) to (3.0, 4.0). // (2) A Json object named "point_1" containing an array of N numbers which represent the // coordinates of the first endpoint AND a Json object named "point_2" containing an array // of N numbers which represent the coordinates of the second endpoint. // Ex. Json json; // json["point_1"] = {1.0, 2.0}; // json["point_2"] = {3.0, 4.0}; // represents a 2D line segment spanning from (1.0, 2.0) to (3.0, 4.0). // If neither format is available, std::nullopt will be returned. // Output serialization format: // A std::pair for which the first component contains an array of N numbers which represent the // coordinates of the first endpoint and the second component contains an array of N numbers which // represent the coordinates of the second endpoint. template struct JsonSerializer> { using LineSegment_t = geometry::LineSegment; using Vector_t = typename geometry::LineSegment::Vector_t; static std::optional TryGet(const Json& json) { // Try to get LineSegment from format: {point_1_vector, point_2_vector} auto maybe = JsonSerializer>::TryGet(json); if (maybe) { return LineSegment_t{maybe->first, maybe->second}; } // Try to get LineSegment from named attributes for point_1 and point_2 auto maybe_point_1 = TryGetFromMap(json, "point_1"); auto maybe_point_2 = TryGetFromMap(json, "point_2"); if (maybe_point_1 && maybe_point_2) { return LineSegment_t{*maybe_point_1, *maybe_point_2}; } return std::nullopt; } static void Set(Json& json, const LineSegment_t& value) { ::nvidia::isaac::serialization::Set(json, std::pair{value.a(), value.b()}); } }; // Parameter support for Pose3. It uses doubles to store elements in the json. template struct JsonSerializer> { // Tries to get pose in two ways. The first method is kept for backward compatibility. static std::optional> TryGet(const Json& json) { // First method for backward compatibility. // First four elements are (w, x, y, z) values for the quaternion. // Last three elements are (x, y, z) locations. // Example: [0.0, 0.0, 0.0, 1.0, 25.0, 20.0, 0.0] if (json.is_array()) { auto maybe = JsonSerializer>::TryGet(json); if (!maybe) { return std::nullopt; } const auto& array = *maybe; return Pose3{ SO3::FromQuaternion(Quaternion{array[0], array[1], array[2], array[3]}), Vector3{array[4], array[5], array[6]}}; } // Second method for convenience. // User can supply a translation. If not supplied, zero translation will be used. // User can also supply a rotation. If not supplied, identity matrix (zero rotation) will be // used. // The expected format is: // { // "translation": [x, y, z], // "rotation": R // } // where acceptable formats for R are listed in SO3 serialization. Vector3 translation = GetFromMapOrDefault>(json, "translation", Vector3::Zero()); SO3 rotation = GetFromMapOrDefault>(json, "rotation", SO3::Identity()); return Pose3{rotation, translation}; } static void Set(Json& json, const Pose3& value) { json = Json(std::array{ {value.rotation.quaternion().w(), value.rotation.quaternion().x(), value.rotation.quaternion().y(), value.rotation.quaternion().z(), value.translation.x(), value.translation.y(), value.translation.z()}}); } }; // Parameter support for Pose2. It uses doubles to store elements in the json. template struct JsonSerializer> { static std::optional> TryGet(const Json& json) { auto maybe = JsonSerializer>::TryGet(json); if (!maybe) { return std::nullopt; } const auto& array = *maybe; return Pose2{SO2::FromAngle(array[0]), Vector2{array[1], array[2]}}; } static void Set(Json& json, const Pose2& value) { json = Json( std::array{{value.rotation.angle(), value.translation.x(), value.translation.y()}}); } }; // Helper function to validate json color inputs for Pixel3ub and Pixel4ub inline bool ValidateColorInput(const std::vector& color_array) { if (!(color_array.size() == 3 || color_array.size() == 4)) { LOG_WARNING("Color must have three (RGB) or four (RGBA) components"); return false; } for (int component : color_array) { if (!(component >= 0 && component <= 255)) { LOG_WARNING("Color component must be in range 0-255"); return false; } } return true; } // Parameter support for Pixel3ub. It uses uint8_t to store elements in the json. template <> struct JsonSerializer { static std::optional TryGet(const Json& json) { auto maybe = JsonSerializer>::TryGet(json); if (!maybe) { return std::nullopt; } const auto& array = *maybe; if (ValidateColorInput(array)) { return Pixel3ub{ static_cast(array[0]), static_cast(array[1]), static_cast(array[2]), }; } else { LOG_WARNING("Invalid color input"); return std::nullopt; } } static void Set(Json& json, const Pixel3ub& value) { json = Json(std::array{{value[0], value[1], value[2]}}); } }; // Parameter support for Pixel4ub. It uses uint8_t to store elements in the json. template <> struct JsonSerializer { static std::optional TryGet(const Json& json) { auto maybe = JsonSerializer>::TryGet(json); if (!maybe) { return std::nullopt; } auto& array = *maybe; if (ValidateColorInput(array)) { // Add opaque alpha channel if not supplied in Json file if (array.size() == 3) { array.push_back(255); } return Pixel4ub{ static_cast(array[0]), static_cast(array[1]), static_cast(array[2]), static_cast(array[3])}; } else { LOG_WARNING("Invalid color input"); return std::nullopt; } } static void Set(Json& json, const Pixel4ub& value) { json = Json(std::array{{value[0], value[1], value[2], value[3]}}); } }; } // namespace json_formatter_details template std::optional TryGet(const Json& json) { return json_formatter_details::JsonSerializer::TryGet(json); } template void Set(Json& json, T value) { json_formatter_details::JsonSerializer::Set(json, std::move(value)); } } // namespace serialization } // namespace isaac } // namespace nvidia namespace Eigen { // Conversion from Eigen types like Vector2d to Json template void to_json(nlohmann::json& json, const T& value) { ::nvidia::isaac::serialization::Set(json, value); } // Conversion from Json to Eigen types like Vector2d template void from_json(const nlohmann::json& json, T& value) { if (auto maybe = ::nvidia::isaac::serialization::TryGet(json)) { value = *maybe; } } } // namespace Eigen ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/sight/sop.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include #include #include "gems/sight/sop_geometry.hpp" #include "gems/sight/sop_serializer.hpp" #include "gems/sight/sop_style.hpp" #include "gems/sight/sop_transform.hpp" namespace nvidia { namespace isaac { namespace sight { // Contains sight operation as a Tree structure: // - Each internal node contains a potential style (default for its children), a transformation to // apply before rendering the children // - Each leaf contains a simple primitive (or SopImage) to be rendered using the current default // style and using the composition of all the transformation above. class Sop : public SopSerializer { public: // Simple constructor Sop() = default; Sop(Sop&&) = default; Sop(const Sop&) = delete; // Add a SopSerializer Sop(SopSerializer* sop) { list_.emplace_back(sop); } // Add a primitive without a transform or style template , int> = 0> void add(Primitive primitive) { list_.emplace_back(new Primitive(std::move(primitive))); } // Add a primitive with a given transform template , int> = 0> void add(Primitive primitive, const SopTransform& transform) { Sop* sop = new Sop(new Primitive(std::move(primitive))); sop->transform = transform; list_.emplace_back(static_cast(sop)); } // Add a primitive with a given style template , int> = 0> void add(Primitive primitive, const SopStyle& style) { Sop* sop = new Sop(new Primitive(std::move(primitive))); sop->style = style; list_.emplace_back(static_cast(sop)); } // Add a primitive with a given transform and style template , int> = 0> void add(Primitive primitive, const SopStyle& style, const SopTransform& transform) { Sop* sop = new Sop(new Primitive(std::move(primitive))); sop->style = style; sop->transform = transform; list_.emplace_back(static_cast(sop)); } // Add a primitive with a given transform template void add(const Args&... args) { list_.emplace_back(new Primitive(args...)); } // Add a primitive with a given transform template void add(const SopTransform& transform, const Args&... args) { Sop* sop = new Sop(new Primitive(args...)); sop->transform = transform; list_.emplace_back(static_cast(sop)); } // Add a primitive with a given style template void add(const SopStyle& style, const Args&... args) { Sop* sop = new Sop(new Primitive(args...)); sop->style = style; list_.emplace_back(static_cast(sop)); } // Add a primitive with a given transform and style template void add(const SopStyle& style, const SopTransform& transform, const Args&... args) { Sop* sop = new Sop(new Primitive(args...)); sop->style = style; sop->transform = transform; list_.emplace_back(static_cast(sop)); } template , int> = 0> void add(F f) { Sop* sop = new Sop(); f(*sop); list_.emplace_back(static_cast(sop)); } // Make a sop static, it will be rendered at the latest time from the PoseTree. void makeStatic(); uint8_t key() const; bool toBinary(BufferSerialization& buffer) const override; bool fromBinary(BufferSerialization& buffer) override; // Optional style to be apply to the children std::optional style; // Optional transformation to apply to the the subtree std::optional transform; private: bool static_ = false; std::vector> list_; }; } // namespace sight } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/sight/sop_asset.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/sight/sop_serializer.hpp" namespace nvidia { namespace isaac { namespace sight { // Sight Operation Asset. // TODO(bbutin): Right it now it contains only a name to an asset, later we need to add information // about the asset as well. class SopAsset : public SopSerializer { public: // Creates empty SopAsset SopAsset() = default; SopAsset(SopAsset&&) = default; ~SopAsset() override = default; // Creates an asset with a name SopAsset(std::string text); // Construct a sop by calling fromBinary SopAsset(BufferSerialization& buffer); bool toBinary(BufferSerialization& buffer) const override; bool fromBinary(BufferSerialization& buffer) override; private: std::string name_ = ""; }; } // namespace sight } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/sight/sop_image.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/image/image.hpp" #include "gems/core/math/types.hpp" #include "gems/image/io.hpp" #include "gems/sight/sop_serializer.hpp" namespace nvidia { namespace isaac { namespace sight { // Sight Operation Image. // Helper to serialize an image in JPG (default) or PNG format class SopImage : public SopSerializer { public: // Creates empty image SopImage() = default; SopImage(SopImage&&) = default; ~SopImage() override = default; // Create an image in png or jpg format and whether or not you flip it. template SopImage(const Image& img, bool png, bool flip) { if (!img.empty()) { flip_ = flip; if (png) { ::nvidia::isaac::EncodePng(img, image_); } else { ::nvidia::isaac::EncodeJpeg(img, /* quality = */ 50, image_); } } } // Create an image in png or jpg format. template SopImage(const Image& img, bool png) { if (!img.empty()) { flip_ = false; if (png) { ::nvidia::isaac::EncodePng(img, image_); } else { ::nvidia::isaac::EncodeJpeg(img, /* quality = */ 50, image_); } } } // Create an image in jpg format with a custom quality. template static SopImage Jpg(const Image& img, int quality) { SopImage sop; if (!img.empty()) { sop.flip_ = false; ::nvidia::isaac::EncodeJpeg(img, quality, sop.image_); } return sop; } // Create an image in jpg format with a custom quality and whether or not you flip it. template static SopImage Jpg(const Image& img, int quality, bool flip) { SopImage sop; if (!img.empty()) { sop.flip_ = flip; ::nvidia::isaac::EncodeJpeg(img, quality, sop.image_); } return sop; } // Create an image in jpg format. template SopImage(const Image& img) { if (!img.empty()) { flip_ = false; ::nvidia::isaac::EncodeJpeg(img, 50, image_); } } // Construct a sop by calling fromBinary SopImage(BufferSerialization& buffer); bool toBinary(BufferSerialization& buffer) const override; bool fromBinary(BufferSerialization& buffer) override; private: bool flip_; std::vector image_; }; } // namespace sight } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/sight/sop_mesh.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/math/types.hpp" #include "gems/sight/sop_serializer.hpp" namespace nvidia { namespace isaac { namespace sight { // Sight Operation for a mesh. class SopMesh : public SopSerializer { public: SopMesh() = default; SopMesh(SopMesh&&) = default; ~SopMesh() override = default; // Creates a new SopMesh, `append` indicates whether or not it's an update or if we should restart // from scratch. SopMesh(bool append); // Adds a new block to the mesh. // Parameters: // - name: the name of the block. // - num_points: the number of points (N) // - points: a vector of coordinates, size 3N, contains [x0,y0,z0, x1,y1,z1, ...,] // - num_triangles: the number of triangles, (M) // - triangles: indices of points that form a triangle, size 3M, the first three indices // correspond to the first triangle, the next three to the second triangle, and so on // - colors: if not null, it contains the color of each point in order. The format is RGB. // - normals: if not null, it contains the normal vector of each point, [nx0,ny0,nz0, ...] void add(std::string name, int num_points, const float* points, int num_triangles, const uint16_t* triangles, const uint8_t* colors = nullptr, const float* normals = nullptr); void add(std::string name, std::vector points, std::vector triangles, std::vector colors, std::vector normals); // Construct a sop by calling fromBinary SopMesh(BufferSerialization& buffer); bool toBinary(BufferSerialization& buffer) const override; bool fromBinary(BufferSerialization& buffer) override; private: // Hold the information about a single block. struct Block { std::string name; std::vector points; std::vector normals; std::vector colors; std::vector triangles; }; bool append_ = true; std::list blocks_; }; } // namespace sight } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/sight/sop_point_cloud.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include "gems/core/math/types.hpp" #include "gems/core/tensor/sample_cloud.hpp" #include "gems/sight/sop_serializer.hpp" namespace nvidia { namespace isaac { namespace sight { // Sight show operation for point clouds. class SopPointCloud : public SopSerializer { public: SopPointCloud() = default; SopPointCloud(SopPointCloud&&) = default; ~SopPointCloud() override = default; // Creates a SopPointCloud with 2d points SopPointCloud(::nvidia::isaac::SampleCloudConstView2f points, int downsample_stride = 1); SopPointCloud(::nvidia::isaac::SampleCloudConstView2f points, ::nvidia::isaac::SampleCloudConstView3ub colors, int downsample_stride = 1); // Creates a SopPointCloud with 3d points SopPointCloud(::nvidia::isaac::SampleCloudConstView3f points, int downsample_stride = 1); SopPointCloud(::nvidia::isaac::SampleCloudConstView3f points, ::nvidia::isaac::SampleCloudConstView3ub colors, int downsample_stride = 1); // Construct a sop by calling fromBinary SopPointCloud(BufferSerialization& buffer); bool toBinary(BufferSerialization& buffer) const override; bool fromBinary(BufferSerialization& buffer) override; private: int dim_ = 0; std::vector pts_; std::vector colors_; }; } // namespace sight } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/sight/sop_style.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/image/image.hpp" #include "gems/sight/sop_serializer.hpp" namespace nvidia { namespace isaac { namespace sight { // Sight Operation Style // Contains optional information to apply to the sight operation struct SopStyle : public SopSerializer { // Creates empty style SopStyle() = default; ~SopStyle() override = default; // Creates a style with a color (valid javascript format: e.g. '#abc' '#123456' 'rgb(0, 1, 2)', // 'white', etc...) SopStyle(std::string color); SopStyle(const char* color); SopStyle(const ::nvidia::isaac::Pixel3ub& col); SopStyle(const ::nvidia::isaac::Pixel4ub& col); // Helper == operator for testing deserialize. bool operator==(const SopStyle& style) const; // Creates a style with a color and whether object should be filled or not. template SopStyle(const C& color, bool fill) : SopStyle(color) { fill_ = fill; } // Creates a style with a color, whether object should be filled or not, and a default size. template SopStyle(const C& color, bool fill, double size) : SopStyle(color, fill) { size_ = size; } // Creates a style with a color, whether object should be filled or not, a default size, and an // alpha value to control transparency. If a Pixel4ub is provided for color, it's alpha component // will be overwritten by the alpha value provided as a double. template SopStyle(const C& color, bool fill, double size, double alpha) : SopStyle(color, fill, size) { alpha_ = static_cast(std::clamp(256.0 * alpha, 0.0, 255.0)); } bool toBinary(BufferSerialization& buffer) const override; bool fromBinary(BufferSerialization& buffer) override; private: std::optional color_str_; std::optional<::nvidia::isaac::Pixel3ub> color_; std::optional alpha_; std::optional fill_; std::optional size_; }; } // namespace sight } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/sight/sop_text.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/math/types.hpp" #include "gems/sight/sop_serializer.hpp" namespace nvidia { namespace isaac { namespace sight { // Sight Operation Text // Can be used to display text at a given position class SopText : public SopSerializer { public: // Creates empty SopText SopText() = default; SopText(SopText&&) = default; ~SopText() override = default; // Creates a text with not other information (will be rendered at (0, 0)) SopText(std::string text); // Creates a style with a color and wether object should be filled or not. template SopText(std::string text, const ::nvidia::isaac::Vector2& pos) : SopText(std::move(text)) { position_ = pos.template cast(); } // Creates a SopText setup to center the text. template SopText(std::string text, const ::nvidia::isaac::Vector2& pos, bool center) : SopText(std::move(text), pos) { center_ = center; } // Construct a sop by calling fromBinary SopText(BufferSerialization& buffer); bool toBinary(BufferSerialization& buffer) const override; bool fromBinary(BufferSerialization& buffer) override; private: std::string text_ = ""; bool center_ = false; std::optional<::nvidia::isaac::Vector2f> position_; }; } // namespace sight } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/sight/sop_transform.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include #include "gems/core/math/pose2.hpp" #include "gems/core/math/pose3.hpp" #include "gems/geometry/pinhole.hpp" #include "gems/sight/sop_serializer.hpp" namespace nvidia { namespace isaac { namespace sight { // Sight Operation Transform // Contains the Pose2 or Pose3 transform or frame as well as a scale factor and a pinhole model. struct SopTransform : public SopSerializer { // Creates empty transform SopTransform() = default; ~SopTransform() override = default; // Creates a SopTransform using the canvas pixel frame (allow you to draw directly at a given // position on a canvas). // Note: this only works for 2D and the Sop will not be rendered in 3D. static SopTransform CanvasFrame(); // Creates a SopTransform using a reference frame from uid SopTransform(uint64_t uid); // Creates a SopTransform using a reference frame SopTransform(const std::string& reference_frame); // Creates a SopTransform using a Pose2 template SopTransform(const ::nvidia::isaac::Pose2& pose) { pose2_ = pose.template cast(); } // Creates a SopTransform using a Pose3 template SopTransform(const ::nvidia::isaac::Pose3& pose) { pose3_ = pose.template cast(); } // Creates a transform with a Pose and a scale template SopTransform(const Pose& pose, double scale) : SopTransform(pose) { scale_ = scale; } // Creates a transform with a Pose and a pinhole projection template SopTransform(const Pose& pose, const ::nvidia::isaac::geometry::Pinhole& pinhole) : SopTransform(pose) { pinhole_ = pinhole.template cast(); } // Creates a transform with a Pose and a scale template SopTransform(const Pose& pose, double scale, const ::nvidia::isaac::geometry::Pinhole& pinhole) : SopTransform(pose, pinhole) { scale_ = scale; } // Helper == operator for testing deserialize. bool operator==(const SopTransform& style) const; bool toBinary(BufferSerialization& buffer) const override; bool fromBinary(BufferSerialization& buffer) override; private: bool canvas_ = false; std::optional uid_; std::optional frame_; std::optional<::nvidia::isaac::Pose2f> pose2_; std::optional<::nvidia::isaac::Pose3f> pose3_; std::optional scale_; std::optional<::nvidia::isaac::geometry::Pinhole> pinhole_; }; } // namespace sight } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/uuid/uuid.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2018-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include namespace nvidia { namespace isaac { // A universally unique identifier (UUID) class Uuid { public: static constexpr int kNumBytes = 16; // Generates a new UUID static Uuid Generate(); // Creates a UUID from a string. If the string has "unparsed" UUID format it will be parsed as a // UUID string. Otherwise it will be treated as an ASCII string. An unparsed UUID string has the // format "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" with XXX alpha-numeric characters. May assert // if neither form of parsing succeeds, e.g. if the string is too long. static Uuid FromString(const std::string& str); // Parses a string as an ASCII string. Will assert if the string is too long. static Uuid FromAsciiString(const std::string& str); // Creates a UUID from a serialized UUID string. This will assert in case the string does not // have the right format. static Uuid FromUuidString(const std::string& str); // Creates UUID from two 64-bit integers static Uuid FromUInt64(uint64_t lower, uint64_t upper) { Uuid uuid; uuid.longs_[0] = lower; uuid.longs_[1] = upper; uuid.is_uuid_ = true; // FIXME return uuid; } // Creates an invalid (whatever that means) UUID with all 0 Uuid() { longs_[0] = 0; longs_[1] = 0; is_uuid_ = false; } // Iterator interface const unsigned char* begin() const { return bytes_; } unsigned char* begin() { return bytes_; } const unsigned char* end() const { return bytes_ + kNumBytes; } unsigned char* end() { return bytes_ + kNumBytes; } uint64_t lower() const { return longs_[0]; } uint64_t upper() const { return longs_[1]; } // A hash value so that we can use the UUID as a key size_t hash() const { // Should be way faster than a string-based hash return lower() ^ upper(); } // Gets an unparsed string representation for the UUID const std::string& str() const { if (str_.empty()) { unparse(); } return str_; } // Same as str() but directly returns a null-terminated C-string const char* c_str() const { return str().c_str(); } // Comparison operators friend bool operator==(const Uuid& lhs, const Uuid& rhs) { return lhs.lower() == rhs.lower() && lhs.upper() == rhs.upper(); } friend bool operator!=(const Uuid& lhs, const Uuid& rhs) { return !(lhs == rhs); } friend bool operator<(const Uuid& lhs, const Uuid& rhs) { return lhs.upper() < rhs.upper() || (lhs.upper() == rhs.upper() && lhs.lower() < rhs.lower()); } private: // Use both 8-bit unsigned and bytes representations union { unsigned char bytes_[kNumBytes]; uint64_t longs_[2]; }; // True if this is actually a UUID and not a string chosen by the user. bool is_uuid_; // Cached string version of uuid used for printing mutable std::string str_; // Computes the unparsed string version of the UUID void unparse() const; }; } // namespace isaac } // namespace nvidia namespace std { // Overload for std::hash to be compatible with standard containers template <> struct hash { size_t operator()(const nvidia::isaac::Uuid& x) const { return x.hash(); } }; } // namespace std ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/gems/video_buffer/allocator.hpp ================================================ // SPDX-FileCopyrightText: NVIDIA CORPORATION & AFFILIATES // Copyright (c) 2023-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // // SPDX-License-Identifier: Apache-2.0 #pragma once #include #include #include "gxf/multimedia/video.hpp" #include "gxf/std/allocator.hpp" namespace nvidia { namespace isaac { template struct NoPaddingColorPlanes {}; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({gxf::ColorPlane("RGB", 3, width * 3)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("BGR", 3, width * 3)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("RGBA", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("BGRA", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("RGB", 6, width * 6)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("BGR", 6, width * 6)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("RGB", 12, width * 12)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("BGR", 12, width * 12)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("gray", 1, width)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("gray", 2, width * 2)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("gray", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("gray", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("Y", 1, width), nvidia::gxf::ColorPlane("UV", 2, width)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("Y", 1, width), nvidia::gxf::ColorPlane("UV", 2, width)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("Y", 1, width), nvidia::gxf::ColorPlane("UV", 2, width * 2)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("Y", 1, width), nvidia::gxf::ColorPlane("UV", 2, width * 2)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes({gxf::ColorPlane("R", 1, width), gxf::ColorPlane("G", 1, width), gxf::ColorPlane("B", 1, width)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes({gxf::ColorPlane("R", 2, width * 2), gxf::ColorPlane("G", 2, width * 2), gxf::ColorPlane("B", 2, width * 2)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes( {gxf::ColorPlane("R", 4, width * 4), gxf::ColorPlane("G", 4, width * 4), gxf::ColorPlane("B", 4, width * 4)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes({gxf::ColorPlane("B", 1, width), gxf::ColorPlane("G", 1, width), gxf::ColorPlane("R", 1, width)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes( {gxf::ColorPlane("R", 2, width * 2), gxf::ColorPlane("G", 2, width * 2), gxf::ColorPlane("B", 2, width * 2)}) {} std::array planes; }; template<> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(size_t width) : planes( {gxf::ColorPlane("B", 4, width * 4), gxf::ColorPlane("G", 4, width * 4), gxf::ColorPlane("R", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("D", 4, width * 4)}) {} std::array planes; }; template <> struct NoPaddingColorPlanes { explicit NoPaddingColorPlanes(uint32_t width) : planes({nvidia::gxf::ColorPlane("D", 8, width * 8)}) {} std::array planes; }; // This includes the list of video buffer formats that supported for the allocator constexpr bool IsSupportedVideoFormat(const gxf::VideoFormat format) { return format == gxf::VideoFormat::GXF_VIDEO_FORMAT_RGB || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_BGR || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_RGBA || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_BGRA || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_RGB16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_BGR16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_RGB32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_BGR32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_GRAY || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_GRAY16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_GRAY32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_GRAY32F || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_R8_G8_B8 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_B8_G8_R8 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_R16_G16_B16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_B16_G16_R16 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_R32_G32_B32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_B32_G32_R32 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_NV12 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_NV12_ER || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_NV24 || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_NV24_ER || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_D32F || format == gxf::VideoFormat::GXF_VIDEO_FORMAT_D64F; } template::type* = nullptr> gxf::Expected AllocateUnpaddedVideoBuffer( gxf::Handle frame, uint32_t width, uint32_t height, gxf::MemoryStorageType storage_type, gxf::Handle allocator) { GXF_LOG_ERROR("Received unsupported video format!"); return gxf::Unexpected{GXF_FAILURE}; } template::type* = nullptr> gxf::Expected AllocateUnpaddedVideoBuffer( gxf::Handle frame, uint32_t width, uint32_t height, gxf::MemoryStorageType storage_type, gxf::Handle allocator) { if (width % 2 != 0 || height % 2 != 0) { GXF_LOG_ERROR( "Error: expected even width and height but received %u width and %u height", width, height); return gxf::Unexpected{GXF_FAILURE}; } NoPaddingColorPlanes nopadding_planes(width); gxf::VideoFormatSize video_format_size; auto size = video_format_size.size(width, height, nopadding_planes.planes); std::vector color_planes{ nopadding_planes.planes.begin(), nopadding_planes.planes.end()}; gxf::VideoBufferInfo buffer_info{width, height, T, color_planes, gxf::SurfaceLayout::GXF_SURFACE_LAYOUT_PITCH_LINEAR}; return frame->resizeCustom(buffer_info, size, storage_type, allocator); } template gxf::Expected AllocateVideoBuffer( gxf::Handle frame, uint32_t width, uint32_t height, gxf::SurfaceLayout layout, gxf::MemoryStorageType storage_type, gxf::Handle allocator) { return frame->resize(width, height, layout, storage_type, allocator); } } // namespace isaac } // namespace nvidia ================================================ FILE: isaac_ros_gxf_extensions/gxf_isaac_gems/gxf/third_party/nlohmann/json.hpp ================================================ // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT /****************************************************************************\ * Note on documentation: The source files contain links to the online * * documentation of the public API at https://json.nlohmann.me. This URL * * contains the most recent documentation and should also be applicable to * * previous versions; documentation for deprecated functions is not * * removed, but marked deprecated. See "Generate documentation" section in * * file docs/README.md. * \****************************************************************************/ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ #include // all_of, find, for_each #include // nullptr_t, ptrdiff_t, size_t #include // hash, less #include // initializer_list #ifndef JSON_NO_IO #include // istream, ostream #endif // JSON_NO_IO #include // random_access_iterator_tag #include // unique_ptr #include // accumulate #include // string, stoi, to_string #include // declval, forward, move, pair, swap #include // vector // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT // This file contains all macro definitions affecting or depending on the ABI #ifndef JSON_SKIP_LIBRARY_VERSION_CHECK #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 2 #warning "Already included a different version of the library!" #endif #endif #endif #define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) #define NLOHMANN_JSON_VERSION_PATCH 2 // NOLINT(modernize-macro-to-enum) #ifndef JSON_DIAGNOSTICS #define JSON_DIAGNOSTICS 0 #endif #ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 #endif #if JSON_DIAGNOSTICS #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag #else #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS #endif #if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp #else #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON #endif #ifndef NLOHMANN_JSON_NAMESPACE_NO_VERSION #define NLOHMANN_JSON_NAMESPACE_NO_VERSION 0 #endif // Construct the namespace ABI tags component #define NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) json_abi ## a ## b #define NLOHMANN_JSON_ABI_TAGS_CONCAT(a, b) \ NLOHMANN_JSON_ABI_TAGS_CONCAT_EX(a, b) #define NLOHMANN_JSON_ABI_TAGS \ NLOHMANN_JSON_ABI_TAGS_CONCAT( \ NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) // Construct the namespace version component #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) \ _v ## major ## _ ## minor ## _ ## patch #define NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(major, minor, patch) \ NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT_EX(major, minor, patch) #if NLOHMANN_JSON_NAMESPACE_NO_VERSION #define NLOHMANN_JSON_NAMESPACE_VERSION #else #define NLOHMANN_JSON_NAMESPACE_VERSION \ NLOHMANN_JSON_NAMESPACE_VERSION_CONCAT(NLOHMANN_JSON_VERSION_MAJOR, \ NLOHMANN_JSON_VERSION_MINOR, \ NLOHMANN_JSON_VERSION_PATCH) #endif // Combine namespace components #define NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) a ## b #define NLOHMANN_JSON_NAMESPACE_CONCAT(a, b) \ NLOHMANN_JSON_NAMESPACE_CONCAT_EX(a, b) #ifndef NLOHMANN_JSON_NAMESPACE #define NLOHMANN_JSON_NAMESPACE \ nlohmann::NLOHMANN_JSON_NAMESPACE_CONCAT( \ NLOHMANN_JSON_ABI_TAGS, \ NLOHMANN_JSON_NAMESPACE_VERSION) #endif #ifndef NLOHMANN_JSON_NAMESPACE_BEGIN #define NLOHMANN_JSON_NAMESPACE_BEGIN \ namespace nlohmann \ { \ inline namespace NLOHMANN_JSON_NAMESPACE_CONCAT( \ NLOHMANN_JSON_ABI_TAGS, \ NLOHMANN_JSON_NAMESPACE_VERSION) \ { #endif #ifndef NLOHMANN_JSON_NAMESPACE_END #define NLOHMANN_JSON_NAMESPACE_END \ } /* namespace (inline namespace) NOLINT(readability/namespace) */ \ } // namespace nlohmann #endif // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // transform #include // array #include // forward_list #include // inserter, front_inserter, end #include // map #include // string #include // tuple, make_tuple #include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible #include // unordered_map #include // pair, declval #include // valarray // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // nullptr_t #include // exception #include // runtime_error #include // to_string #include // vector // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // array #include // size_t #include // uint8_t #include // string // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // declval, pair // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT // #include NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { template struct make_void { using type = void; }; template using void_t = typename make_void::type; } // namespace detail NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { // https://en.cppreference.com/w/cpp/experimental/is_detected struct nonesuch { nonesuch() = delete; ~nonesuch() = delete; nonesuch(nonesuch const&) = delete; nonesuch(nonesuch const&&) = delete; void operator=(nonesuch const&) = delete; void operator=(nonesuch&&) = delete; }; template class Op, class... Args> struct detector { using value_t = std::false_type; using type = Default; }; template class Op, class... Args> struct detector>, Op, Args...> { using value_t = std::true_type; using type = Op; }; template class Op, class... Args> using is_detected = typename detector::value_t; template class Op, class... Args> struct is_detected_lazy : is_detected { }; template class Op, class... Args> using detected_t = typename detector::type; template class Op, class... Args> using detected_or = detector; template class Op, class... Args> using detected_or_t = typename detected_or::type; template class Op, class... Args> using is_detected_exact = std::is_same>; template class Op, class... Args> using is_detected_convertible = std::is_convertible, To>; } // namespace detail NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-FileCopyrightText: 2016-2021 Evan Nemerson // SPDX-License-Identifier: MIT /* Hedley - https://nemequ.github.io/hedley * Created by Evan Nemerson */ #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) #if defined(JSON_HEDLEY_VERSION) #undef JSON_HEDLEY_VERSION #endif #define JSON_HEDLEY_VERSION 15 #if defined(JSON_HEDLEY_STRINGIFY_EX) #undef JSON_HEDLEY_STRINGIFY_EX #endif #define JSON_HEDLEY_STRINGIFY_EX(x) #x #if defined(JSON_HEDLEY_STRINGIFY) #undef JSON_HEDLEY_STRINGIFY #endif #define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) #if defined(JSON_HEDLEY_CONCAT_EX) #undef JSON_HEDLEY_CONCAT_EX #endif #define JSON_HEDLEY_CONCAT_EX(a,b) a##b #if defined(JSON_HEDLEY_CONCAT) #undef JSON_HEDLEY_CONCAT #endif #define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) #if defined(JSON_HEDLEY_CONCAT3_EX) #undef JSON_HEDLEY_CONCAT3_EX #endif #define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c #if defined(JSON_HEDLEY_CONCAT3) #undef JSON_HEDLEY_CONCAT3 #endif #define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c) #if defined(JSON_HEDLEY_VERSION_ENCODE) #undef JSON_HEDLEY_VERSION_ENCODE #endif #define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) #if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) #undef JSON_HEDLEY_VERSION_DECODE_MAJOR #endif #define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) #if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) #undef JSON_HEDLEY_VERSION_DECODE_MINOR #endif #define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) #if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) #undef JSON_HEDLEY_VERSION_DECODE_REVISION #endif #define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) #if defined(JSON_HEDLEY_GNUC_VERSION) #undef JSON_HEDLEY_GNUC_VERSION #endif #if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) #elif defined(__GNUC__) #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) #endif #if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) #undef JSON_HEDLEY_GNUC_VERSION_CHECK #endif #if defined(JSON_HEDLEY_GNUC_VERSION) #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_MSVC_VERSION) #undef JSON_HEDLEY_MSVC_VERSION #endif #if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) #elif defined(_MSC_FULL_VER) && !defined(__ICL) #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) #elif defined(_MSC_VER) && !defined(__ICL) #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) #endif #if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) #undef JSON_HEDLEY_MSVC_VERSION_CHECK #endif #if !defined(JSON_HEDLEY_MSVC_VERSION) #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) #elif defined(_MSC_VER) && (_MSC_VER >= 1400) #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) #elif defined(_MSC_VER) && (_MSC_VER >= 1200) #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) #else #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) #endif #if defined(JSON_HEDLEY_INTEL_VERSION) #undef JSON_HEDLEY_INTEL_VERSION #endif #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) #elif defined(__INTEL_COMPILER) && !defined(__ICL) #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) #endif #if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) #undef JSON_HEDLEY_INTEL_VERSION_CHECK #endif #if defined(JSON_HEDLEY_INTEL_VERSION) #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_INTEL_CL_VERSION) #undef JSON_HEDLEY_INTEL_CL_VERSION #endif #if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) #endif #if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK #endif #if defined(JSON_HEDLEY_INTEL_CL_VERSION) #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_PGI_VERSION) #undef JSON_HEDLEY_PGI_VERSION #endif #if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) #endif #if defined(JSON_HEDLEY_PGI_VERSION_CHECK) #undef JSON_HEDLEY_PGI_VERSION_CHECK #endif #if defined(JSON_HEDLEY_PGI_VERSION) #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_SUNPRO_VERSION) #undef JSON_HEDLEY_SUNPRO_VERSION #endif #if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) #elif defined(__SUNPRO_C) #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) #elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) #elif defined(__SUNPRO_CC) #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) #endif #if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK #endif #if defined(JSON_HEDLEY_SUNPRO_VERSION) #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) #undef JSON_HEDLEY_EMSCRIPTEN_VERSION #endif #if defined(__EMSCRIPTEN__) #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) #endif #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK #endif #if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_ARM_VERSION) #undef JSON_HEDLEY_ARM_VERSION #endif #if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) #elif defined(__CC_ARM) && defined(__ARMCC_VERSION) #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) #endif #if defined(JSON_HEDLEY_ARM_VERSION_CHECK) #undef JSON_HEDLEY_ARM_VERSION_CHECK #endif #if defined(JSON_HEDLEY_ARM_VERSION) #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_IBM_VERSION) #undef JSON_HEDLEY_IBM_VERSION #endif #if defined(__ibmxl__) #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) #elif defined(__xlC__) && defined(__xlC_ver__) #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) #elif defined(__xlC__) #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) #endif #if defined(JSON_HEDLEY_IBM_VERSION_CHECK) #undef JSON_HEDLEY_IBM_VERSION_CHECK #endif #if defined(JSON_HEDLEY_IBM_VERSION) #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_TI_VERSION) #undef JSON_HEDLEY_TI_VERSION #endif #if \ defined(__TI_COMPILER_VERSION__) && \ ( \ defined(__TMS470__) || defined(__TI_ARM__) || \ defined(__MSP430__) || \ defined(__TMS320C2000__) \ ) #if (__TI_COMPILER_VERSION__ >= 16000000) #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) #endif #endif #if defined(JSON_HEDLEY_TI_VERSION_CHECK) #undef JSON_HEDLEY_TI_VERSION_CHECK #endif #if defined(JSON_HEDLEY_TI_VERSION) #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_TI_CL2000_VERSION) #undef JSON_HEDLEY_TI_CL2000_VERSION #endif #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) #endif #if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK #endif #if defined(JSON_HEDLEY_TI_CL2000_VERSION) #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_TI_CL430_VERSION) #undef JSON_HEDLEY_TI_CL430_VERSION #endif #if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) #endif #if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK #endif #if defined(JSON_HEDLEY_TI_CL430_VERSION) #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_TI_ARMCL_VERSION) #undef JSON_HEDLEY_TI_ARMCL_VERSION #endif #if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) #endif #if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK #endif #if defined(JSON_HEDLEY_TI_ARMCL_VERSION) #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_TI_CL6X_VERSION) #undef JSON_HEDLEY_TI_CL6X_VERSION #endif #if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) #endif #if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK #endif #if defined(JSON_HEDLEY_TI_CL6X_VERSION) #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_TI_CL7X_VERSION) #undef JSON_HEDLEY_TI_CL7X_VERSION #endif #if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) #endif #if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK #endif #if defined(JSON_HEDLEY_TI_CL7X_VERSION) #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_TI_CLPRU_VERSION) #undef JSON_HEDLEY_TI_CLPRU_VERSION #endif #if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) #endif #if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK #endif #if defined(JSON_HEDLEY_TI_CLPRU_VERSION) #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_CRAY_VERSION) #undef JSON_HEDLEY_CRAY_VERSION #endif #if defined(_CRAYC) #if defined(_RELEASE_PATCHLEVEL) #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) #else #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) #endif #endif #if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) #undef JSON_HEDLEY_CRAY_VERSION_CHECK #endif #if defined(JSON_HEDLEY_CRAY_VERSION) #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_IAR_VERSION) #undef JSON_HEDLEY_IAR_VERSION #endif #if defined(__IAR_SYSTEMS_ICC__) #if __VER__ > 1000 #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) #else #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) #endif #endif #if defined(JSON_HEDLEY_IAR_VERSION_CHECK) #undef JSON_HEDLEY_IAR_VERSION_CHECK #endif #if defined(JSON_HEDLEY_IAR_VERSION) #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_TINYC_VERSION) #undef JSON_HEDLEY_TINYC_VERSION #endif #if defined(__TINYC__) #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) #endif #if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) #undef JSON_HEDLEY_TINYC_VERSION_CHECK #endif #if defined(JSON_HEDLEY_TINYC_VERSION) #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_DMC_VERSION) #undef JSON_HEDLEY_DMC_VERSION #endif #if defined(__DMC__) #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) #endif #if defined(JSON_HEDLEY_DMC_VERSION_CHECK) #undef JSON_HEDLEY_DMC_VERSION_CHECK #endif #if defined(JSON_HEDLEY_DMC_VERSION) #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_COMPCERT_VERSION) #undef JSON_HEDLEY_COMPCERT_VERSION #endif #if defined(__COMPCERT_VERSION__) #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) #endif #if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK #endif #if defined(JSON_HEDLEY_COMPCERT_VERSION) #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_PELLES_VERSION) #undef JSON_HEDLEY_PELLES_VERSION #endif #if defined(__POCC__) #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) #endif #if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) #undef JSON_HEDLEY_PELLES_VERSION_CHECK #endif #if defined(JSON_HEDLEY_PELLES_VERSION) #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_MCST_LCC_VERSION) #undef JSON_HEDLEY_MCST_LCC_VERSION #endif #if defined(__LCC__) && defined(__LCC_MINOR__) #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) #endif #if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK #endif #if defined(JSON_HEDLEY_MCST_LCC_VERSION) #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_GCC_VERSION) #undef JSON_HEDLEY_GCC_VERSION #endif #if \ defined(JSON_HEDLEY_GNUC_VERSION) && \ !defined(__clang__) && \ !defined(JSON_HEDLEY_INTEL_VERSION) && \ !defined(JSON_HEDLEY_PGI_VERSION) && \ !defined(JSON_HEDLEY_ARM_VERSION) && \ !defined(JSON_HEDLEY_CRAY_VERSION) && \ !defined(JSON_HEDLEY_TI_VERSION) && \ !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ !defined(JSON_HEDLEY_TI_CL430_VERSION) && \ !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ !defined(__COMPCERT__) && \ !defined(JSON_HEDLEY_MCST_LCC_VERSION) #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION #endif #if defined(JSON_HEDLEY_GCC_VERSION_CHECK) #undef JSON_HEDLEY_GCC_VERSION_CHECK #endif #if defined(JSON_HEDLEY_GCC_VERSION) #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) #else #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) #endif #if defined(JSON_HEDLEY_HAS_ATTRIBUTE) #undef JSON_HEDLEY_HAS_ATTRIBUTE #endif #if \ defined(__has_attribute) && \ ( \ (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \ ) # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) #else # define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) #endif #if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE #endif #if defined(__has_attribute) #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) #else #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE #endif #if defined(__has_attribute) #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) #else #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE #endif #if \ defined(__has_cpp_attribute) && \ defined(__cplusplus) && \ (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) #else #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) #endif #if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS #endif #if !defined(__cplusplus) || !defined(__has_cpp_attribute) #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) #elif \ !defined(JSON_HEDLEY_PGI_VERSION) && \ !defined(JSON_HEDLEY_IAR_VERSION) && \ (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) #else #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) #endif #if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE #endif #if defined(__has_cpp_attribute) && defined(__cplusplus) #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) #else #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE #endif #if defined(__has_cpp_attribute) && defined(__cplusplus) #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) #else #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_HAS_BUILTIN) #undef JSON_HEDLEY_HAS_BUILTIN #endif #if defined(__has_builtin) #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) #else #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) #endif #if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) #undef JSON_HEDLEY_GNUC_HAS_BUILTIN #endif #if defined(__has_builtin) #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) #else #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) #undef JSON_HEDLEY_GCC_HAS_BUILTIN #endif #if defined(__has_builtin) #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) #else #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_HAS_FEATURE) #undef JSON_HEDLEY_HAS_FEATURE #endif #if defined(__has_feature) #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) #else #define JSON_HEDLEY_HAS_FEATURE(feature) (0) #endif #if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) #undef JSON_HEDLEY_GNUC_HAS_FEATURE #endif #if defined(__has_feature) #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) #else #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_GCC_HAS_FEATURE) #undef JSON_HEDLEY_GCC_HAS_FEATURE #endif #if defined(__has_feature) #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) #else #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_HAS_EXTENSION) #undef JSON_HEDLEY_HAS_EXTENSION #endif #if defined(__has_extension) #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) #else #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) #endif #if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) #undef JSON_HEDLEY_GNUC_HAS_EXTENSION #endif #if defined(__has_extension) #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) #else #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) #undef JSON_HEDLEY_GCC_HAS_EXTENSION #endif #if defined(__has_extension) #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) #else #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE #endif #if defined(__has_declspec_attribute) #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) #else #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) #endif #if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE #endif #if defined(__has_declspec_attribute) #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) #else #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE #endif #if defined(__has_declspec_attribute) #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) #else #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_HAS_WARNING) #undef JSON_HEDLEY_HAS_WARNING #endif #if defined(__has_warning) #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) #else #define JSON_HEDLEY_HAS_WARNING(warning) (0) #endif #if defined(JSON_HEDLEY_GNUC_HAS_WARNING) #undef JSON_HEDLEY_GNUC_HAS_WARNING #endif #if defined(__has_warning) #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) #else #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_GCC_HAS_WARNING) #undef JSON_HEDLEY_GCC_HAS_WARNING #endif #if defined(__has_warning) #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) #else #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #endif #if \ (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ defined(__clang__) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) #define JSON_HEDLEY_PRAGMA(value) __pragma(value) #else #define JSON_HEDLEY_PRAGMA(value) #endif #if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) #undef JSON_HEDLEY_DIAGNOSTIC_PUSH #endif #if defined(JSON_HEDLEY_DIAGNOSTIC_POP) #undef JSON_HEDLEY_DIAGNOSTIC_POP #endif #if defined(__clang__) #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) #elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") #elif \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") #else #define JSON_HEDLEY_DIAGNOSTIC_PUSH #define JSON_HEDLEY_DIAGNOSTIC_POP #endif /* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ #endif #if defined(__cplusplus) # if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") # if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") # if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ xpr \ JSON_HEDLEY_DIAGNOSTIC_POP # else # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ xpr \ JSON_HEDLEY_DIAGNOSTIC_POP # endif # else # define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ xpr \ JSON_HEDLEY_DIAGNOSTIC_POP # endif # endif #endif #if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x #endif #if defined(JSON_HEDLEY_CONST_CAST) #undef JSON_HEDLEY_CONST_CAST #endif #if defined(__cplusplus) # define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast(expr)) #elif \ JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) # define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ ((T) (expr)); \ JSON_HEDLEY_DIAGNOSTIC_POP \ })) #else # define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) #endif #if defined(JSON_HEDLEY_REINTERPRET_CAST) #undef JSON_HEDLEY_REINTERPRET_CAST #endif #if defined(__cplusplus) #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast(expr)) #else #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr)) #endif #if defined(JSON_HEDLEY_STATIC_CAST) #undef JSON_HEDLEY_STATIC_CAST #endif #if defined(__cplusplus) #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast(expr)) #else #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) #endif #if defined(JSON_HEDLEY_CPP_CAST) #undef JSON_HEDLEY_CPP_CAST #endif #if defined(__cplusplus) # if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") # define JSON_HEDLEY_CPP_CAST(T, expr) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \ ((T) (expr)) \ JSON_HEDLEY_DIAGNOSTIC_POP # elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0) # define JSON_HEDLEY_CPP_CAST(T, expr) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ _Pragma("diag_suppress=Pe137") \ JSON_HEDLEY_DIAGNOSTIC_POP # else # define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr)) # endif #else # define JSON_HEDLEY_CPP_CAST(T, expr) (expr) #endif #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED #endif #if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786)) #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") #elif \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") #else #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED #endif #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS #endif #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161)) #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") #elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) #elif \ JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") #else #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS #endif #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES #endif #if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") #elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") #elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") #elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292)) #elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) #elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") #elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") #elif \ JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") #else #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES #endif #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL #endif #if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") #elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") #else #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL #endif #if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION #endif #if JSON_HEDLEY_HAS_WARNING("-Wunused-function") #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") #elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") #elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505)) #elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") #else #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION #endif #if defined(JSON_HEDLEY_DEPRECATED) #undef JSON_HEDLEY_DEPRECATED #endif #if defined(JSON_HEDLEY_DEPRECATED_FOR) #undef JSON_HEDLEY_DEPRECATED_FOR #endif #if \ JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) #elif \ (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) #elif defined(__cplusplus) && (__cplusplus >= 201402L) #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) #elif \ JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") #else #define JSON_HEDLEY_DEPRECATED(since) #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) #endif #if defined(JSON_HEDLEY_UNAVAILABLE) #undef JSON_HEDLEY_UNAVAILABLE #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) #else #define JSON_HEDLEY_UNAVAILABLE(available_since) #endif #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) #undef JSON_HEDLEY_WARN_UNUSED_RESULT #endif #if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) #elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) #elif defined(_Check_return_) /* SAL */ #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ #else #define JSON_HEDLEY_WARN_UNUSED_RESULT #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) #endif #if defined(JSON_HEDLEY_SENTINEL) #undef JSON_HEDLEY_SENTINEL #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) #else #define JSON_HEDLEY_SENTINEL(position) #endif #if defined(JSON_HEDLEY_NO_RETURN) #undef JSON_HEDLEY_NO_RETURN #endif #if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #define JSON_HEDLEY_NO_RETURN __noreturn #elif \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) #elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L #define JSON_HEDLEY_NO_RETURN _Noreturn #elif defined(__cplusplus) && (__cplusplus >= 201103L) #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) #elif \ JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) #else #define JSON_HEDLEY_NO_RETURN #endif #if defined(JSON_HEDLEY_NO_ESCAPE) #undef JSON_HEDLEY_NO_ESCAPE #endif #if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) #else #define JSON_HEDLEY_NO_ESCAPE #endif #if defined(JSON_HEDLEY_UNREACHABLE) #undef JSON_HEDLEY_UNREACHABLE #endif #if defined(JSON_HEDLEY_UNREACHABLE_RETURN) #undef JSON_HEDLEY_UNREACHABLE_RETURN #endif #if defined(JSON_HEDLEY_ASSUME) #undef JSON_HEDLEY_ASSUME #endif #if \ JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_ASSUME(expr) __assume(expr) #elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) #elif \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) #if defined(__cplusplus) #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) #else #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) #endif #endif #if \ (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \ JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() #elif defined(JSON_HEDLEY_ASSUME) #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) #endif #if !defined(JSON_HEDLEY_ASSUME) #if defined(JSON_HEDLEY_UNREACHABLE) #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) #else #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) #endif #endif #if defined(JSON_HEDLEY_UNREACHABLE) #if \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) #else #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() #endif #else #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) #endif #if !defined(JSON_HEDLEY_UNREACHABLE) #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) #endif JSON_HEDLEY_DIAGNOSTIC_PUSH #if JSON_HEDLEY_HAS_WARNING("-Wpedantic") #pragma clang diagnostic ignored "-Wpedantic" #endif #if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" #endif #if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) #if defined(__clang__) #pragma clang diagnostic ignored "-Wvariadic-macros" #elif defined(JSON_HEDLEY_GCC_VERSION) #pragma GCC diagnostic ignored "-Wvariadic-macros" #endif #endif #if defined(JSON_HEDLEY_NON_NULL) #undef JSON_HEDLEY_NON_NULL #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) #else #define JSON_HEDLEY_NON_NULL(...) #endif JSON_HEDLEY_DIAGNOSTIC_POP #if defined(JSON_HEDLEY_PRINTF_FORMAT) #undef JSON_HEDLEY_PRINTF_FORMAT #endif #if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) #elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) #elif \ JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) #elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) #else #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) #endif #if defined(JSON_HEDLEY_CONSTEXPR) #undef JSON_HEDLEY_CONSTEXPR #endif #if defined(__cplusplus) #if __cplusplus >= 201103L #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) #endif #endif #if !defined(JSON_HEDLEY_CONSTEXPR) #define JSON_HEDLEY_CONSTEXPR #endif #if defined(JSON_HEDLEY_PREDICT) #undef JSON_HEDLEY_PREDICT #endif #if defined(JSON_HEDLEY_LIKELY) #undef JSON_HEDLEY_LIKELY #endif #if defined(JSON_HEDLEY_UNLIKELY) #undef JSON_HEDLEY_UNLIKELY #endif #if defined(JSON_HEDLEY_UNPREDICTABLE) #undef JSON_HEDLEY_UNPREDICTABLE #endif #if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) #endif #if \ (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) # define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability)) # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability)) # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability)) # define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 ) # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 ) #elif \ (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \ JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) # define JSON_HEDLEY_PREDICT(expr, expected, probability) \ (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ (__extension__ ({ \ double hedley_probability_ = (probability); \ ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ })) # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ (__extension__ ({ \ double hedley_probability_ = (probability); \ ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ })) # define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) # define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) #else # define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) # define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) # define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) # define JSON_HEDLEY_LIKELY(expr) (!!(expr)) # define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) #endif #if !defined(JSON_HEDLEY_UNPREDICTABLE) #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) #endif #if defined(JSON_HEDLEY_MALLOC) #undef JSON_HEDLEY_MALLOC #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_MALLOC __declspec(restrict) #else #define JSON_HEDLEY_MALLOC #endif #if defined(JSON_HEDLEY_PURE) #undef JSON_HEDLEY_PURE #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) # define JSON_HEDLEY_PURE __attribute__((__pure__)) #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) # define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") #elif defined(__cplusplus) && \ ( \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \ ) # define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") #else # define JSON_HEDLEY_PURE #endif #if defined(JSON_HEDLEY_CONST) #undef JSON_HEDLEY_CONST #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_CONST __attribute__((__const__)) #elif \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) #define JSON_HEDLEY_CONST _Pragma("no_side_effect") #else #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE #endif #if defined(JSON_HEDLEY_RESTRICT) #undef JSON_HEDLEY_RESTRICT #endif #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) #define JSON_HEDLEY_RESTRICT restrict #elif \ JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ defined(__clang__) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_RESTRICT __restrict #elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) #define JSON_HEDLEY_RESTRICT _Restrict #else #define JSON_HEDLEY_RESTRICT #endif #if defined(JSON_HEDLEY_INLINE) #undef JSON_HEDLEY_INLINE #endif #if \ (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ (defined(__cplusplus) && (__cplusplus >= 199711L)) #define JSON_HEDLEY_INLINE inline #elif \ defined(JSON_HEDLEY_GCC_VERSION) || \ JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) #define JSON_HEDLEY_INLINE __inline__ #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_INLINE __inline #else #define JSON_HEDLEY_INLINE #endif #if defined(JSON_HEDLEY_ALWAYS_INLINE) #undef JSON_HEDLEY_ALWAYS_INLINE #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) # define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) # define JSON_HEDLEY_ALWAYS_INLINE __forceinline #elif defined(__cplusplus) && \ ( \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \ ) # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) # define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") #else # define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE #endif #if defined(JSON_HEDLEY_NEVER_INLINE) #undef JSON_HEDLEY_NEVER_INLINE #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) #elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") #elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") #elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) #elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) #else #define JSON_HEDLEY_NEVER_INLINE #endif #if defined(JSON_HEDLEY_PRIVATE) #undef JSON_HEDLEY_PRIVATE #endif #if defined(JSON_HEDLEY_PUBLIC) #undef JSON_HEDLEY_PUBLIC #endif #if defined(JSON_HEDLEY_IMPORT) #undef JSON_HEDLEY_IMPORT #endif #if defined(_WIN32) || defined(__CYGWIN__) # define JSON_HEDLEY_PRIVATE # define JSON_HEDLEY_PUBLIC __declspec(dllexport) # define JSON_HEDLEY_IMPORT __declspec(dllimport) #else # if \ JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ ( \ defined(__TI_EABI__) && \ ( \ (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \ ) \ ) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) # define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) # define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) # else # define JSON_HEDLEY_PRIVATE # define JSON_HEDLEY_PUBLIC # endif # define JSON_HEDLEY_IMPORT extern #endif #if defined(JSON_HEDLEY_NO_THROW) #undef JSON_HEDLEY_NO_THROW #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) #define JSON_HEDLEY_NO_THROW __declspec(nothrow) #else #define JSON_HEDLEY_NO_THROW #endif #if defined(JSON_HEDLEY_FALL_THROUGH) #undef JSON_HEDLEY_FALL_THROUGH #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) #elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) #elif defined(__fallthrough) /* SAL */ #define JSON_HEDLEY_FALL_THROUGH __fallthrough #else #define JSON_HEDLEY_FALL_THROUGH #endif #if defined(JSON_HEDLEY_RETURNS_NON_NULL) #undef JSON_HEDLEY_RETURNS_NON_NULL #endif #if \ JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) #elif defined(_Ret_notnull_) /* SAL */ #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ #else #define JSON_HEDLEY_RETURNS_NON_NULL #endif #if defined(JSON_HEDLEY_ARRAY_PARAM) #undef JSON_HEDLEY_ARRAY_PARAM #endif #if \ defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ !defined(__STDC_NO_VLA__) && \ !defined(__cplusplus) && \ !defined(JSON_HEDLEY_PGI_VERSION) && \ !defined(JSON_HEDLEY_TINYC_VERSION) #define JSON_HEDLEY_ARRAY_PARAM(name) (name) #else #define JSON_HEDLEY_ARRAY_PARAM(name) #endif #if defined(JSON_HEDLEY_IS_CONSTANT) #undef JSON_HEDLEY_IS_CONSTANT #endif #if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) #undef JSON_HEDLEY_REQUIRE_CONSTEXPR #endif /* JSON_HEDLEY_IS_CONSTEXPR_ is for HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ #if defined(JSON_HEDLEY_IS_CONSTEXPR_) #undef JSON_HEDLEY_IS_CONSTEXPR_ #endif #if \ JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) #endif #if !defined(__cplusplus) # if \ JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) #if defined(__INTPTR_TYPE__) #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) #else #include #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) #endif # elif \ ( \ defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ !defined(JSON_HEDLEY_PGI_VERSION) && \ !defined(JSON_HEDLEY_IAR_VERSION)) || \ (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) #if defined(__INTPTR_TYPE__) #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) #else #include #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) #endif # elif \ defined(JSON_HEDLEY_GCC_VERSION) || \ defined(JSON_HEDLEY_INTEL_VERSION) || \ defined(JSON_HEDLEY_TINYC_VERSION) || \ defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \ defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ defined(__clang__) # define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ sizeof(void) != \ sizeof(*( \ 1 ? \ ((void*) ((expr) * 0L) ) : \ ((struct { char v[sizeof(void) * 2]; } *) 1) \ ) \ ) \ ) # endif #endif #if defined(JSON_HEDLEY_IS_CONSTEXPR_) #if !defined(JSON_HEDLEY_IS_CONSTANT) #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) #endif #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) #else #if !defined(JSON_HEDLEY_IS_CONSTANT) #define JSON_HEDLEY_IS_CONSTANT(expr) (0) #endif #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) #endif #if defined(JSON_HEDLEY_BEGIN_C_DECLS) #undef JSON_HEDLEY_BEGIN_C_DECLS #endif #if defined(JSON_HEDLEY_END_C_DECLS) #undef JSON_HEDLEY_END_C_DECLS #endif #if defined(JSON_HEDLEY_C_DECL) #undef JSON_HEDLEY_C_DECL #endif #if defined(__cplusplus) #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { #define JSON_HEDLEY_END_C_DECLS } #define JSON_HEDLEY_C_DECL extern "C" #else #define JSON_HEDLEY_BEGIN_C_DECLS #define JSON_HEDLEY_END_C_DECLS #define JSON_HEDLEY_C_DECL #endif #if defined(JSON_HEDLEY_STATIC_ASSERT) #undef JSON_HEDLEY_STATIC_ASSERT #endif #if \ !defined(__cplusplus) && ( \ (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ defined(_Static_assert) \ ) # define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) #elif \ (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) # define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) #else # define JSON_HEDLEY_STATIC_ASSERT(expr, message) #endif #if defined(JSON_HEDLEY_NULL) #undef JSON_HEDLEY_NULL #endif #if defined(__cplusplus) #if __cplusplus >= 201103L #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) #elif defined(NULL) #define JSON_HEDLEY_NULL NULL #else #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) #endif #elif defined(NULL) #define JSON_HEDLEY_NULL NULL #else #define JSON_HEDLEY_NULL ((void*) 0) #endif #if defined(JSON_HEDLEY_MESSAGE) #undef JSON_HEDLEY_MESSAGE #endif #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") # define JSON_HEDLEY_MESSAGE(msg) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ JSON_HEDLEY_PRAGMA(message msg) \ JSON_HEDLEY_DIAGNOSTIC_POP #elif \ JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) #elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) #elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) #elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) # define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) #else # define JSON_HEDLEY_MESSAGE(msg) #endif #if defined(JSON_HEDLEY_WARNING) #undef JSON_HEDLEY_WARNING #endif #if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") # define JSON_HEDLEY_WARNING(msg) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ JSON_HEDLEY_PRAGMA(clang warning msg) \ JSON_HEDLEY_DIAGNOSTIC_POP #elif \ JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) #elif \ JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) #else # define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) #endif #if defined(JSON_HEDLEY_REQUIRE) #undef JSON_HEDLEY_REQUIRE #endif #if defined(JSON_HEDLEY_REQUIRE_MSG) #undef JSON_HEDLEY_REQUIRE_MSG #endif #if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) # if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") # define JSON_HEDLEY_REQUIRE(expr) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ __attribute__((diagnose_if(!(expr), #expr, "error"))) \ JSON_HEDLEY_DIAGNOSTIC_POP # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ __attribute__((diagnose_if(!(expr), msg, "error"))) \ JSON_HEDLEY_DIAGNOSTIC_POP # else # define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) # endif #else # define JSON_HEDLEY_REQUIRE(expr) # define JSON_HEDLEY_REQUIRE_MSG(expr,msg) #endif #if defined(JSON_HEDLEY_FLAGS) #undef JSON_HEDLEY_FLAGS #endif #if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) #else #define JSON_HEDLEY_FLAGS #endif #if defined(JSON_HEDLEY_FLAGS_CAST) #undef JSON_HEDLEY_FLAGS_CAST #endif #if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) # define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ JSON_HEDLEY_DIAGNOSTIC_PUSH \ _Pragma("warning(disable:188)") \ ((T) (expr)); \ JSON_HEDLEY_DIAGNOSTIC_POP \ })) #else # define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) #endif #if defined(JSON_HEDLEY_EMPTY_BASES) #undef JSON_HEDLEY_EMPTY_BASES #endif #if \ (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \ JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) #else #define JSON_HEDLEY_EMPTY_BASES #endif /* Remaining macros are deprecated. */ #if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK #endif #if defined(__clang__) #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) #else #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) #endif #if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE #endif #define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) #if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE #endif #define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) #if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) #undef JSON_HEDLEY_CLANG_HAS_BUILTIN #endif #define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) #if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) #undef JSON_HEDLEY_CLANG_HAS_FEATURE #endif #define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) #if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) #undef JSON_HEDLEY_CLANG_HAS_EXTENSION #endif #define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) #if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE #endif #define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) #if defined(JSON_HEDLEY_CLANG_HAS_WARNING) #undef JSON_HEDLEY_CLANG_HAS_WARNING #endif #define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ // This file contains all internal macro definitions (except those affecting ABI) // You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them // #include // exclude unsupported compilers #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) #if defined(__clang__) #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" #endif #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" #endif #endif #endif // C++ language standard detection // if the user manually specified the used c++ version this is skipped #if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) #define JSON_HAS_CPP_20 #define JSON_HAS_CPP_17 #define JSON_HAS_CPP_14 #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 #define JSON_HAS_CPP_17 #define JSON_HAS_CPP_14 #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) #define JSON_HAS_CPP_14 #endif // the cpp 11 flag is always specified because it is the minimal required version #define JSON_HAS_CPP_11 #endif #ifdef __has_include #if __has_include() #include #endif #endif #if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) #ifdef JSON_HAS_CPP_17 #if defined(__cpp_lib_filesystem) #define JSON_HAS_FILESYSTEM 1 #elif defined(__cpp_lib_experimental_filesystem) #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #elif !defined(__has_include) #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #elif __has_include() #define JSON_HAS_FILESYSTEM 1 #elif __has_include() #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 #endif // std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/ #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif // no filesystem support before GCC 8: https://en.cppreference.com/w/cpp/compiler_support #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif // no filesystem support before Clang 7: https://en.cppreference.com/w/cpp/compiler_support #if defined(__clang_major__) && __clang_major__ < 7 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif // no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support #if defined(_MSC_VER) && _MSC_VER < 1914 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif // no filesystem support before iOS 13 #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif // no filesystem support before macOS Catalina #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif #endif #endif #ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0 #endif #ifndef JSON_HAS_FILESYSTEM #define JSON_HAS_FILESYSTEM 0 #endif #ifndef JSON_HAS_THREE_WAY_COMPARISON #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \ && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L #define JSON_HAS_THREE_WAY_COMPARISON 1 #else #define JSON_HAS_THREE_WAY_COMPARISON 0 #endif #endif #ifndef JSON_HAS_RANGES // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 #define JSON_HAS_RANGES 0 #elif defined(__cpp_lib_ranges) #define JSON_HAS_RANGES 1 #else #define JSON_HAS_RANGES 0 #endif #endif #ifdef JSON_HAS_CPP_17 #define JSON_INLINE_VARIABLE inline #else #define JSON_INLINE_VARIABLE #endif #if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address) #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]] #else #define JSON_NO_UNIQUE_ADDRESS #endif // disable documentation warnings on clang #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdocumentation" #pragma clang diagnostic ignored "-Wdocumentation-unknown-command" #endif // allow disabling exceptions #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) #define JSON_THROW(exception) throw exception #define JSON_TRY try #define JSON_CATCH(exception) catch(exception) #define JSON_INTERNAL_CATCH(exception) catch(exception) #else #include #define JSON_THROW(exception) std::abort() #define JSON_TRY if(true) #define JSON_CATCH(exception) if(false) #define JSON_INTERNAL_CATCH(exception) if(false) #endif // override exception macros #if defined(JSON_THROW_USER) #undef JSON_THROW #define JSON_THROW JSON_THROW_USER #endif #if defined(JSON_TRY_USER) #undef JSON_TRY #define JSON_TRY JSON_TRY_USER #endif #if defined(JSON_CATCH_USER) #undef JSON_CATCH #define JSON_CATCH JSON_CATCH_USER #undef JSON_INTERNAL_CATCH #define JSON_INTERNAL_CATCH JSON_CATCH_USER #endif #if defined(JSON_INTERNAL_CATCH_USER) #undef JSON_INTERNAL_CATCH #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER #endif // allow overriding assert #if !defined(JSON_ASSERT) #include // assert #define JSON_ASSERT(x) assert(x) #endif // allow to access some private functions (needed by the test suite) #if defined(JSON_TESTS_PRIVATE) #define JSON_PRIVATE_UNLESS_TESTED public #else #define JSON_PRIVATE_UNLESS_TESTED private #endif /*! @brief macro to briefly define a mapping between an enum and JSON @def NLOHMANN_JSON_SERIALIZE_ENUM @since version 3.4.0 */ #define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ template \ inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ { \ static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ static const std::pair m[] = __VA_ARGS__; \ auto it = std::find_if(std::begin(m), std::end(m), \ [e](const std::pair& ej_pair) -> bool \ { \ return ej_pair.first == e; \ }); \ j = ((it != std::end(m)) ? it : std::begin(m))->second; \ } \ template \ inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ { \ static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ static const std::pair m[] = __VA_ARGS__; \ auto it = std::find_if(std::begin(m), std::end(m), \ [&j](const std::pair& ej_pair) -> bool \ { \ return ej_pair.second == j; \ }); \ e = ((it != std::end(m)) ? it : std::begin(m))->first; \ } // Ugly macros to avoid uglier copy-paste when specializing basic_json. They // may be removed in the future once the class is split. #define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ template class ObjectType, \ template class ArrayType, \ class StringType, class BooleanType, class NumberIntegerType, \ class NumberUnsignedType, class NumberFloatType, \ template class AllocatorType, \ template class JSONSerializer, \ class BinaryType> #define NLOHMANN_BASIC_JSON_TPL \ basic_json // Macros to simplify conversion from/to types #define NLOHMANN_JSON_EXPAND( x ) x #define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME #define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ NLOHMANN_JSON_PASTE64, \ NLOHMANN_JSON_PASTE63, \ NLOHMANN_JSON_PASTE62, \ NLOHMANN_JSON_PASTE61, \ NLOHMANN_JSON_PASTE60, \ NLOHMANN_JSON_PASTE59, \ NLOHMANN_JSON_PASTE58, \ NLOHMANN_JSON_PASTE57, \ NLOHMANN_JSON_PASTE56, \ NLOHMANN_JSON_PASTE55, \ NLOHMANN_JSON_PASTE54, \ NLOHMANN_JSON_PASTE53, \ NLOHMANN_JSON_PASTE52, \ NLOHMANN_JSON_PASTE51, \ NLOHMANN_JSON_PASTE50, \ NLOHMANN_JSON_PASTE49, \ NLOHMANN_JSON_PASTE48, \ NLOHMANN_JSON_PASTE47, \ NLOHMANN_JSON_PASTE46, \ NLOHMANN_JSON_PASTE45, \ NLOHMANN_JSON_PASTE44, \ NLOHMANN_JSON_PASTE43, \ NLOHMANN_JSON_PASTE42, \ NLOHMANN_JSON_PASTE41, \ NLOHMANN_JSON_PASTE40, \ NLOHMANN_JSON_PASTE39, \ NLOHMANN_JSON_PASTE38, \ NLOHMANN_JSON_PASTE37, \ NLOHMANN_JSON_PASTE36, \ NLOHMANN_JSON_PASTE35, \ NLOHMANN_JSON_PASTE34, \ NLOHMANN_JSON_PASTE33, \ NLOHMANN_JSON_PASTE32, \ NLOHMANN_JSON_PASTE31, \ NLOHMANN_JSON_PASTE30, \ NLOHMANN_JSON_PASTE29, \ NLOHMANN_JSON_PASTE28, \ NLOHMANN_JSON_PASTE27, \ NLOHMANN_JSON_PASTE26, \ NLOHMANN_JSON_PASTE25, \ NLOHMANN_JSON_PASTE24, \ NLOHMANN_JSON_PASTE23, \ NLOHMANN_JSON_PASTE22, \ NLOHMANN_JSON_PASTE21, \ NLOHMANN_JSON_PASTE20, \ NLOHMANN_JSON_PASTE19, \ NLOHMANN_JSON_PASTE18, \ NLOHMANN_JSON_PASTE17, \ NLOHMANN_JSON_PASTE16, \ NLOHMANN_JSON_PASTE15, \ NLOHMANN_JSON_PASTE14, \ NLOHMANN_JSON_PASTE13, \ NLOHMANN_JSON_PASTE12, \ NLOHMANN_JSON_PASTE11, \ NLOHMANN_JSON_PASTE10, \ NLOHMANN_JSON_PASTE9, \ NLOHMANN_JSON_PASTE8, \ NLOHMANN_JSON_PASTE7, \ NLOHMANN_JSON_PASTE6, \ NLOHMANN_JSON_PASTE5, \ NLOHMANN_JSON_PASTE4, \ NLOHMANN_JSON_PASTE3, \ NLOHMANN_JSON_PASTE2, \ NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) #define NLOHMANN_JSON_PASTE2(func, v1) func(v1) #define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2) #define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3) #define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4) #define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5) #define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6) #define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7) #define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8) #define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9) #define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10) #define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) #define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) #define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) #define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) #define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) #define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) #define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) #define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) #define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) #define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) #define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) #define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) #define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) #define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) #define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) #define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) #define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) #define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) #define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) #define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) #define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) #define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) #define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) #define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) #define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) #define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) #define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) #define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) #define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) #define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) #define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) #define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) #define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) #define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) #define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) #define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) #define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) #define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) #define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) #define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) #define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) #define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) #define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) #define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) #define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) #define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) #define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) #define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) #define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) #define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) #define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) #define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) #define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); #define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1); /*! @brief macro @def NLOHMANN_DEFINE_TYPE_INTRUSIVE @since version 3.9.0 */ #define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } #define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } /*! @brief macro @def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE @since version 3.9.0 */ #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } #define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } // inspired from https://stackoverflow.com/a/26745591 // allows to call any std function as if (e.g. with begin): // using std::begin; begin(x); // // it allows using the detected idiom to retrieve the return type // of such an expression #define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ namespace detail { \ using std::std_name; \ \ template \ using result_of_##std_name = decltype(std_name(std::declval()...)); \ } \ \ namespace detail2 { \ struct std_name##_tag \ { \ }; \ \ template \ std_name##_tag std_name(T&&...); \ \ template \ using result_of_##std_name = decltype(std_name(std::declval()...)); \ \ template \ struct would_call_std_##std_name \ { \ static constexpr auto const value = ::nlohmann::detail:: \ is_detected_exact::value; \ }; \ } /* namespace detail2 */ \ \ template \ struct would_call_std_##std_name : detail2::would_call_std_##std_name \ { \ } #ifndef JSON_USE_IMPLICIT_CONVERSIONS #define JSON_USE_IMPLICIT_CONVERSIONS 1 #endif #if JSON_USE_IMPLICIT_CONVERSIONS #define JSON_EXPLICIT #else #define JSON_EXPLICIT explicit #endif #ifndef JSON_DISABLE_ENUM_SERIALIZATION #define JSON_DISABLE_ENUM_SERIALIZATION 0 #endif #ifndef JSON_USE_GLOBAL_UDLS #define JSON_USE_GLOBAL_UDLS 1 #endif #if JSON_HAS_THREE_WAY_COMPARISON #include // partial_ordering #endif NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { /////////////////////////// // JSON type enumeration // /////////////////////////// /*! @brief the JSON type enumeration This enumeration collects the different JSON types. It is internally used to distinguish the stored values, and the functions @ref basic_json::is_null(), @ref basic_json::is_object(), @ref basic_json::is_array(), @ref basic_json::is_string(), @ref basic_json::is_boolean(), @ref basic_json::is_number() (with @ref basic_json::is_number_integer(), @ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), @ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and @ref basic_json::is_structured() rely on it. @note There are three enumeration entries (number_integer, number_unsigned, and number_float), because the library distinguishes these three types for numbers: @ref basic_json::number_unsigned_t is used for unsigned integers, @ref basic_json::number_integer_t is used for signed integers, and @ref basic_json::number_float_t is used for floating-point numbers or to approximate integers which do not fit in the limits of their respective type. @sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON value with the default value for a given type @since version 1.0.0 */ enum class value_t : std::uint8_t { null, ///< null value object, ///< object (unordered set of name/value pairs) array, ///< array (ordered collection of values) string, ///< string value boolean, ///< boolean value number_integer, ///< number value (signed integer) number_unsigned, ///< number value (unsigned integer) number_float, ///< number value (floating-point) binary, ///< binary array (ordered collection of bytes) discarded ///< discarded by the parser callback function }; /*! @brief comparison operator for JSON types Returns an ordering that is similar to Python: - order: null < boolean < number < object < array < string < binary - furthermore, each type is not smaller than itself - discarded values are not comparable - binary is represented as a b"" string in python and directly comparable to a string; however, making a binary array directly comparable with a string would be surprising behavior in a JSON file. @since version 1.0.0 */ #if JSON_HAS_THREE_WAY_COMPARISON inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD* #else inline bool operator<(const value_t lhs, const value_t rhs) noexcept #endif { static constexpr std::array order = {{ 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, 6 /* binary */ } }; const auto l_index = static_cast(lhs); const auto r_index = static_cast(rhs); #if JSON_HAS_THREE_WAY_COMPARISON if (l_index < order.size() && r_index < order.size()) { return order[l_index] <=> order[r_index]; // *NOPAD* } return std::partial_ordering::unordered; #else return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; #endif } // GCC selects the built-in operator< over an operator rewritten from // a user-defined spaceship operator // Clang, MSVC, and ICC select the rewritten candidate // (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200) #if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) inline bool operator<(const value_t lhs, const value_t rhs) noexcept { return std::is_lt(lhs <=> rhs); // *NOPAD* } #endif } // namespace detail NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT // #include NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { /*! @brief replace all occurrences of a substring by another string @param[in,out] s the string to manipulate; changed so that all occurrences of @a f are replaced with @a t @param[in] f the substring to replace with @a t @param[in] t the string to replace @a f @pre The search string @a f must not be empty. **This precondition is enforced with an assertion.** @since version 2.0.0 */ template inline void replace_substring(StringType& s, const StringType& f, const StringType& t) { JSON_ASSERT(!f.empty()); for (auto pos = s.find(f); // find first occurrence of f pos != StringType::npos; // make sure f was found s.replace(pos, f.size(), t), // replace with t, and pos = s.find(f, pos + t.size())) // find next occurrence of f {} } /*! * @brief string escaping as described in RFC 6901 (Sect. 4) * @param[in] s string to escape * @return escaped string * * Note the order of escaping "~" to "~0" and "/" to "~1" is important. */ template inline StringType escape(StringType s) { replace_substring(s, StringType{"~"}, StringType{"~0"}); replace_substring(s, StringType{"/"}, StringType{"~1"}); return s; } /*! * @brief string unescaping as described in RFC 6901 (Sect. 4) * @param[in] s string to unescape * @return unescaped string * * Note the order of escaping "~1" to "/" and "~0" to "~" is important. */ template static void unescape(StringType& s) { replace_substring(s, StringType{"~1"}, StringType{"/"}); replace_substring(s, StringType{"~0"}, StringType{"~"}); } } // namespace detail NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // size_t // #include NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { /// struct to capture the start position of the current token struct position_t { /// the total number of characters read std::size_t chars_read_total = 0; /// the number of characters read in the current line std::size_t chars_read_current_line = 0; /// the number of lines read std::size_t lines_read = 0; /// conversion to size_t to preserve SAX interface constexpr operator size_t() const { return chars_read_total; } }; } // namespace detail NLOHMANN_JSON_NAMESPACE_END // #include // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-FileCopyrightText: 2018 The Abseil Authors // SPDX-License-Identifier: MIT #include // array #include // size_t #include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type #include // index_sequence, make_index_sequence, index_sequence_for // #include NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { template using uncvref_t = typename std::remove_cv::type>::type; #ifdef JSON_HAS_CPP_14 // the following utilities are natively available in C++14 using std::enable_if_t; using std::index_sequence; using std::make_index_sequence; using std::index_sequence_for; #else // alias templates to reduce boilerplate template using enable_if_t = typename std::enable_if::type; // The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h // which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. //// START OF CODE FROM GOOGLE ABSEIL // integer_sequence // // Class template representing a compile-time integer sequence. An instantiation // of `integer_sequence` has a sequence of integers encoded in its // type through its template arguments (which is a common need when // working with C++11 variadic templates). `absl::integer_sequence` is designed // to be a drop-in replacement for C++14's `std::integer_sequence`. // // Example: // // template< class T, T... Ints > // void user_function(integer_sequence); // // int main() // { // // user_function's `T` will be deduced to `int` and `Ints...` // // will be deduced to `0, 1, 2, 3, 4`. // user_function(make_integer_sequence()); // } template struct integer_sequence { using value_type = T; static constexpr std::size_t size() noexcept { return sizeof...(Ints); } }; // index_sequence // // A helper template for an `integer_sequence` of `size_t`, // `absl::index_sequence` is designed to be a drop-in replacement for C++14's // `std::index_sequence`. template using index_sequence = integer_sequence; namespace utility_internal { template struct Extend; // Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. template struct Extend, SeqSize, 0> { using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >; }; template struct Extend, SeqSize, 1> { using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >; }; // Recursion helper for 'make_integer_sequence'. // 'Gen::type' is an alias for 'integer_sequence'. template struct Gen { using type = typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type; }; template struct Gen { using type = integer_sequence; }; } // namespace utility_internal // Compile-time sequences of integers // make_integer_sequence // // This template alias is equivalent to // `integer_sequence`, and is designed to be a drop-in // replacement for C++14's `std::make_integer_sequence`. template using make_integer_sequence = typename utility_internal::Gen::type; // make_index_sequence // // This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, // and is designed to be a drop-in replacement for C++14's // `std::make_index_sequence`. template using make_index_sequence = make_integer_sequence; // index_sequence_for // // Converts a typename pack into an index sequence of the same length, and // is designed to be a drop-in replacement for C++14's // `std::index_sequence_for()` template using index_sequence_for = make_index_sequence; //// END OF CODE FROM GOOGLE ABSEIL #endif // dispatch utility (taken from ranges-v3) template struct priority_tag : priority_tag < N - 1 > {}; template<> struct priority_tag<0> {}; // taken from ranges-v3 template struct static_const { static JSON_INLINE_VARIABLE constexpr T value{}; }; #ifndef JSON_HAS_CPP_17 template constexpr T static_const::value; #endif template inline constexpr std::array make_array(Args&& ... args) { return std::array {{static_cast(std::forward(args))...}}; } } // namespace detail NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // numeric_limits #include // false_type, is_constructible, is_integral, is_same, true_type #include // declval #include // tuple // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #include // random_access_iterator_tag // #include // #include // #include NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { template struct iterator_types {}; template struct iterator_types < It, void_t> { using difference_type = typename It::difference_type; using value_type = typename It::value_type; using pointer = typename It::pointer; using reference = typename It::reference; using iterator_category = typename It::iterator_category; }; // This is required as some compilers implement std::iterator_traits in a way that // doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. template struct iterator_traits { }; template struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> : iterator_types { }; template struct iterator_traits::value>> { using iterator_category = std::random_access_iterator_tag; using value_type = T; using difference_type = ptrdiff_t; using pointer = T*; using reference = T&; }; } // namespace detail NLOHMANN_JSON_NAMESPACE_END // #include // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT // #include NLOHMANN_JSON_NAMESPACE_BEGIN NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); NLOHMANN_JSON_NAMESPACE_END // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT // #include NLOHMANN_JSON_NAMESPACE_BEGIN NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); NLOHMANN_JSON_NAMESPACE_END // #include // #include // #include // __ _____ _____ _____ // __| | __| | | | JSON for Modern C++ // | | |__ | | | | | | version 3.11.2 // |_____|_____|_____|_|___| https://github.com/nlohmann/json // // SPDX-FileCopyrightText: 2013-2022 Niels Lohmann // SPDX-License-Identifier: MIT #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ #include // int64_t, uint64_t #include // map #include // allocator #include // string #include // vector // #include /*! @brief namespace for Niels Lohmann @see https://github.com/nlohmann @since version 1.0.0 */ NLOHMANN_JSON_NAMESPACE_BEGIN /*! @brief default JSONSerializer template argument This serializer ignores the template arguments and uses ADL ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) for serialization. */ template struct adl_serializer; /// a class to store JSON values /// @sa https://json.nlohmann.me/api/basic_json/ template class ObjectType = std::map, template class ArrayType = std::vector, class StringType = std::string, class BooleanType = bool, class NumberIntegerType = std::int64_t, class NumberUnsignedType = std::uint64_t, class NumberFloatType = double, template class AllocatorType = std::allocator, template class JSONSerializer = adl_serializer, class BinaryType = std::vector> class basic_json; /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document /// @sa https://json.nlohmann.me/api/json_pointer/ template class json_pointer; /*! @brief default specialization @sa https://json.nlohmann.me/api/json/ */ using json = basic_json<>; /// @brief a minimal map-like container that preserves insertion order /// @sa https://json.nlohmann.me/api/ordered_map/ template struct ordered_map; /// @brief specialization that maintains the insertion order of object keys /// @sa https://json.nlohmann.me/api/ordered_json/ using ordered_json = basic_json; NLOHMANN_JSON_NAMESPACE_END #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ NLOHMANN_JSON_NAMESPACE_BEGIN /*! @brief detail namespace with internal helper functions This namespace collects functions that should not be exposed, implementations of some @ref basic_json methods, and meta-programming helpers. @since version 2.1.0 */ namespace detail { ///////////// // helpers // ///////////// // Note to maintainers: // // Every trait in this file expects a non CV-qualified type. // The only exceptions are in the 'aliases for detected' section // (i.e. those of the form: decltype(T::member_function(std::declval()))) // // In this case, T has to be properly CV-qualified to constraint the function arguments // (e.g. to_json(BasicJsonType&, const T&)) template struct is_basic_json : std::false_type {}; NLOHMANN_BASIC_JSON_TPL_DECLARATION struct is_basic_json : std::true_type {}; // used by exceptions create() member functions // true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t // false_type otherwise template struct is_basic_json_context : std::integral_constant < bool, is_basic_json::type>::type>::value || std::is_same::value > {}; ////////////////////// // json_ref helpers // ////////////////////// template class json_ref; template struct is_json_ref : std::false_type {}; template struct is_json_ref> : std::true_type {}; ////////////////////////// // aliases for detected // ////////////////////////// template using mapped_type_t = typename T::mapped_type; template using key_type_t = typename T::key_type; template using value_type_t = typename T::value_type; template using difference_type_t = typename T::difference_type; template using pointer_t = typename T::pointer; template using reference_t = typename T::reference; template using iterator_category_t = typename T::iterator_category; template using to_json_function = decltype(T::to_json(std::declval()...)); template using from_json_function = decltype(T::from_json(std::declval()...)); template using get_template_function = decltype(std::declval().template get()); // trait checking if JSONSerializer::from_json(json const&, udt&) exists template struct has_from_json : std::false_type {}; // trait checking if j.get is valid // use this trait instead of std::is_constructible or std::is_convertible, // both rely on, or make use of implicit conversions, and thus fail when T // has several constructors/operator= (see https://github.com/nlohmann/json/issues/958) template struct is_getable { static constexpr bool value = is_detected::value; }; template struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> { using serializer = typename BasicJsonType::template json_serializer; static constexpr bool value = is_detected_exact::value; }; // This trait checks if JSONSerializer::from_json(json const&) exists // this overload is used for non-default-constructible user-defined-types template struct has_non_default_from_json : std::false_type {}; template struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> { using serializer = typename BasicJsonType::template json_serializer; static constexpr bool value = is_detected_exact::value; }; // This trait checks if BasicJsonType::json_serializer::to_json exists // Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion. template struct has_to_json : std::false_type {}; template struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> { using serializer = typename BasicJsonType::template json_serializer; static constexpr bool value = is_detected_exact::value; }; template using detect_key_compare = typename T::key_compare; template struct has_key_compare : std::integral_constant::value> {}; // obtains the actual object key comparator template struct actual_object_comparator { using object_t = typename BasicJsonType::object_t; using object_comparator_t = typename BasicJsonType::default_object_comparator_t; using type = typename std::conditional < has_key_compare::value, typename object_t::key_compare, object_comparator_t>::type; }; template using actual_object_comparator_t = typename actual_object_comparator::type; /////////////////// // is_ functions // /////////////////// // https://en.cppreference.com/w/cpp/types/conjunction template struct conjunction : std::true_type { }; template struct conjunction : B { }; template struct conjunction : std::conditional(B::value), conjunction, B>::type {}; // https://en.cppreference.com/w/cpp/types/negation template struct negation : std::integral_constant < bool, !B::value > { }; // Reimplementation of is_constructible and is_default_constructible, due to them being broken for // std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). // This causes compile errors in e.g. clang 3.5 or gcc 4.9. template struct is_default_constructible : std::is_default_constructible {}; template struct is_default_constructible> : conjunction, is_default_constructible> {}; template struct is_default_constructible> : conjunction, is_default_constructible> {}; template struct is_default_constructible> : conjunction...> {}; template struct is_default_constructible> : conjunction...> {}; template struct is_constructible : std::is_constructible {}; template struct is_constructible> : is_default_constructible> {}; template struct is_constructible> : is_default_constructible> {}; template struct is_constructible> : is_default_constructible> {}; template struct is_constructible> : is_default_constructible> {}; template struct is_iterator_traits : std::false_type {}; template struct is_iterator_traits> { private: using traits = iterator_traits; public: static constexpr auto value = is_detected::value && is_detected::value && is_detected::value && is_detected::value && is_detected::value; }; template struct is_range { private: using t_ref = typename std::add_lvalue_reference::type; using iterator = detected_t; using sentinel = detected_t; // to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator // and https://en.cppreference.com/w/cpp/iterator/sentinel_for // but reimplementing these would be too much work, as a lot of other concepts are used underneath static constexpr auto is_iterator_begin = is_iterator_traits>::value; public: static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; }; template using iterator_t = enable_if_t::value, result_of_begin())>>; template using range_value_t = value_type_t>>; // The following implementation of is_complete_type is taken from // https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ // and is written by Xiang Fan who agreed to using it in this library. template struct is_complete_type : std::false_type {}; template struct is_complete_type : std::true_type {}; template struct is_compatible_object_type_impl : std::false_type {}; template struct is_compatible_object_type_impl < BasicJsonType, CompatibleObjectType, enable_if_t < is_detected::value&& is_detected::value >> { using object_t = typename BasicJsonType::object_t; // macOS's is_constructible does not play well with nonesuch... static constexpr bool value = is_constructible::value && is_constructible::value; }; template struct is_compatible_object_type : is_compatible_object_type_impl {}; template struct is_constructible_object_type_impl : std::false_type {}; template struct is_constructible_object_type_impl < BasicJsonType, ConstructibleObjectType, enable_if_t < is_detected::value&& is_detected::value >> { using object_t = typename BasicJsonType::object_t; static constexpr bool value = (is_default_constructible::value && (std::is_move_assignable::value || std::is_copy_assignable::value) && (is_constructible::value && std::is_same < typename object_t::mapped_type, typename ConstructibleObjectType::mapped_type >::value)) || (has_from_json::value || has_non_default_from_json < BasicJsonType, typename ConstructibleObjectType::mapped_type >::value); }; template struct is_constructible_object_type : is_constructible_object_type_impl {}; template struct is_compatible_string_type { static constexpr auto value = is_constructible::value; }; template struct is_constructible_string_type { // launder type through decltype() to fix compilation failure on ICPC #ifdef __INTEL_COMPILER using laundered_type = decltype(std::declval()); #else using laundered_type = ConstructibleStringType; #endif static constexpr auto value = conjunction < is_constructible, is_detected_exact>::value; }; template struct is_compatible_array_type_impl : std::false_type {}; template struct is_compatible_array_type_impl < BasicJsonType, CompatibleArrayType, enable_if_t < is_detected::value&& is_iterator_traits>>::value&& // special case for types like std::filesystem::path whose iterator's value_type are themselves // c.f. https://github.com/nlohmann/json/pull/3073 !std::is_same>::value >> { static constexpr bool value = is_constructible>::value; }; template struct is_compatible_array_type : is_compatible_array_type_impl {}; template struct is_constructible_array_type_impl : std::false_type {}; template struct is_constructible_array_type_impl < BasicJsonType, ConstructibleArrayType, enable_if_t::value >> : std::true_type {}; template struct is_constructible_array_type_impl < BasicJsonType, ConstructibleArrayType, enable_if_t < !std::is_same::value&& !is_compatible_string_type::value&& is_default_constructible::value&& (std::is_move_assignable::value || std::is_copy_assignable::value)&& is_detected::value&& is_iterator_traits>>::value&& is_detected::value&& // special case for types like std::filesystem::path whose iterator's value_type are themselves // c.f. https://github.com/nlohmann/json/pull/3073 !std::is_same>::value&& is_complete_type < detected_t>::value >> { using value_type = range_value_t; static constexpr bool value = std::is_same::value || has_from_json::value || has_non_default_from_json < BasicJsonType, value_type >::value; }; template struct is_constructible_array_type : is_constructible_array_type_impl {}; template struct is_compatible_integer_type_impl : std::false_type {}; template struct is_compatible_integer_type_impl < RealIntegerType, CompatibleNumberIntegerType, enable_if_t < std::is_integral::value&& std::is_integral::value&& !std::is_same::value >> { // is there an assert somewhere on overflows? using RealLimits = std::numeric_limits; using CompatibleLimits = std::numeric_limits; static constexpr auto value = is_constructible::value && CompatibleLimits::is_integer && RealLimits::is_signed == CompatibleLimits::is_signed; }; template struct is_compatible_integer_type : is_compatible_integer_type_impl {}; template struct is_compatible_type_impl: std::false_type {}; template struct is_compatible_type_impl < BasicJsonType, CompatibleType, enable_if_t::value >> { static constexpr bool value = has_to_json::value; }; template struct is_compatible_type : is_compatible_type_impl {}; template struct is_constructible_tuple : std::false_type {}; template struct is_constructible_tuple> : conjunction...> {}; template struct is_json_iterator_of : std::false_type {}; template struct is_json_iterator_of : std::true_type {}; template struct is_json_iterator_of : std::true_type {}; // checks if a given type T is a template specialization of Primary template