diff --git a/litert/c/internal/litert_runtime_c_api.h b/litert/c/internal/litert_runtime_c_api.h index e699f6eaec..1858c43bca 100644 --- a/litert/c/internal/litert_runtime_c_api.h +++ b/litert/c/internal/litert_runtime_c_api.h @@ -36,8 +36,6 @@ extern "C" { -// TODO(b/475253786): Clean up build time macros in the function table. - // A struct that contains all the LiteRT runtime C API functions. // // This struct is used to provide a unified interface for the LiteRT runtime @@ -414,7 +412,6 @@ typedef struct LiteRtRuntimeCApiStruct { // litert_tensor_buffer.h: LiteRtGetTensorBufferHostMemory LiteRtStatus (*litert_get_tensor_buffer_host_memory)( LiteRtTensorBuffer tensor_buffer, void** host_memory_addr); -#if LITERT_HAS_AHWB_SUPPORT // litert_tensor_buffer.h: LiteRtCreateTensorBufferFromAhwb LiteRtStatus (*litert_create_tensor_buffer_from_ahwb)( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, @@ -423,8 +420,6 @@ typedef struct LiteRtRuntimeCApiStruct { // litert_tensor_buffer.h: LiteRtGetTensorBufferAhwb LiteRtStatus (*litert_get_tensor_buffer_ahwb)( LiteRtTensorBuffer tensor_buffer, AHardwareBuffer** ahwb); -#endif // LITERT_HAS_AHWB_SUPPORT -#if LITERT_HAS_ION_SUPPORT // litert_tensor_buffer.h: LiteRtCreateTensorBufferFromIonBuffer LiteRtStatus (*litert_create_tensor_buffer_from_ion_buffer)( const LiteRtRankedTensorType* tensor_type, void* ion_buffer_addr, @@ -434,8 +429,6 @@ typedef struct LiteRtRuntimeCApiStruct { LiteRtStatus (*litert_get_tensor_buffer_ion_buffer)(LiteRtTensorBuffer buffer, void** ion_buffer_addr, int* ion_buffer_fd); -#endif // LITERT_HAS_ION_SUPPORT -#if LITERT_HAS_DMABUF_SUPPORT // litert_tensor_buffer.h: LiteRtCreateTensorBufferFromDmaBufBuffer LiteRtStatus (*litert_create_tensor_buffer_from_dma_buf_buffer)( const LiteRtRankedTensorType* tensor_type, void* dmabuf_buffer_addr, @@ -446,8 +439,6 @@ typedef struct LiteRtRuntimeCApiStruct { LiteRtStatus (*litert_get_tensor_buffer_dma_buf_buffer)( LiteRtTensorBuffer tensor_buffer, void** dmabuf_buffer_addr, int* dmabuf_buffer_fd); -#endif // LITERT_HAS_DMABUF_SUPPORT -#if LITERT_HAS_FASTRPC_SUPPORT // litert_tensor_buffer.h: LiteRtCreateTensorBufferFromFastRpcBuffer LiteRtStatus (*litert_create_tensor_buffer_from_fast_rpc_buffer)( const LiteRtRankedTensorType* tensor_type, void* fastrpc_buffer_addr, @@ -457,8 +448,6 @@ typedef struct LiteRtRuntimeCApiStruct { LiteRtStatus (*litert_get_tensor_buffer_fast_rpc_buffer)( LiteRtTensorBuffer tensor_buffer, void** fastrpc_buffer_addr, int* fastrpc_buffer_fd); -#endif // LITERT_HAS_FASTRPC_SUPPORT -#if LITERT_HAS_OPENCL_SUPPORT // litert_tensor_buffer.h: LiteRtCreateTensorBufferFromOpenClMemory LiteRtStatus (*litert_create_tensor_buffer_from_opencl_memory)( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, @@ -468,7 +457,6 @@ typedef struct LiteRtRuntimeCApiStruct { // litert_tensor_buffer.h: LiteRtGetTensorBufferOpenClMemory LiteRtStatus (*litert_get_tensor_buffer_opencl_memory)( LiteRtTensorBuffer tensor_buffer, LiteRtClMem* cl_mem_addr); -#endif // LITERT_HAS_OPENCL_SUPPORT // litert_tensor_buffer.h: LiteRtGetTensorBufferCustomTensorBufferHandle LiteRtStatus (*litert_get_tensor_buffer_custom_tensor_buffer_handle)( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle); @@ -491,7 +479,6 @@ typedef struct LiteRtRuntimeCApiStruct { LiteRtStatus (*litert_get_tensor_buffer_gl_texture)( LiteRtTensorBuffer tensor_buffer, LiteRtGLenum* target, LiteRtGLuint* id, LiteRtGLenum* format, size_t* size_bytes, LiteRtGLint* layer); -#if LITERT_HAS_WEBGPU_SUPPORT // litert_tensor_buffer.h: LiteRtCreateTensorBufferFromWebGpuBuffer LiteRtStatus (*litert_create_tensor_buffer_from_web_gpu_buffer)( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, @@ -506,8 +493,6 @@ typedef struct LiteRtRuntimeCApiStruct { void* webgpu_texture, size_t webgpu_texture_size, LiteRtWebGpuTextureDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer); -#endif // LITERT_HAS_WEBGPU_SUPPORT -#if LITERT_HAS_METAL_SUPPORT // litert_tensor_buffer.h: LiteRtCreateTensorBufferFromMetalMemory LiteRtStatus (*litert_create_tensor_buffer_from_metal_memory)( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, @@ -517,12 +502,9 @@ typedef struct LiteRtRuntimeCApiStruct { // litert_tensor_buffer.h: LiteRtGetTensorBufferMetalMemory LiteRtStatus (*litert_get_tensor_buffer_metal_memory)( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle); -#endif // LITERT_HAS_METAL_SUPPORT -#if LITERT_HAS_VULKAN_SUPPORT // litert_tensor_buffer.h: LiteRtGetTensorBufferVulkanMemory LiteRtStatus (*litert_get_tensor_buffer_vulkan_memory)( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle); -#endif // LITERT_HAS_VULKAN_SUPPORT // litert_tensor_buffer.h: LiteRtCreateManagedTensorBuffer LiteRtStatus (*litert_create_managed_tensor_buffer)( LiteRtEnvironment env, LiteRtTensorBufferType buffer_type, diff --git a/litert/c/litert_tensor_buffer.cc b/litert/c/litert_tensor_buffer.cc index 06a9ed8bf5..e40950ce43 100644 --- a/litert/c/litert_tensor_buffer.cc +++ b/litert/c/litert_tensor_buffer.cc @@ -52,11 +52,11 @@ LiteRtStatus LiteRtCreateTensorBufferFromHostMemory( return kLiteRtStatusOk; } -#if LITERT_HAS_AHWB_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromAhwb( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, AHardwareBuffer* ahwb, size_t ahwb_offset, LiteRtAhwbDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_AHWB_SUPPORT if (!tensor_type || !ahwb || !tensor_buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -66,10 +66,14 @@ LiteRtStatus LiteRtCreateTensorBufferFromAhwb( deallocator)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_AHWB_SUPPORT } LiteRtStatus LiteRtGetTensorBufferAhwb(LiteRtTensorBuffer tensor_buffer, AHardwareBuffer** ahwb) { +#if LITERT_HAS_AHWB_SUPPORT if (!tensor_buffer || !ahwb) { return kLiteRtStatusErrorInvalidArgument; } @@ -78,14 +82,16 @@ LiteRtStatus LiteRtGetTensorBufferAhwb(LiteRtTensorBuffer tensor_buffer, *ahwb = ahwb_buffer; return kLiteRtStatusOk; -} +#else + return kLiteRtStatusErrorUnsupported; #endif // LITERT_HAS_AHWB_SUPPORT +} -#if LITERT_HAS_ION_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromIonBuffer( const LiteRtRankedTensorType* tensor_type, void* ion_buffer_addr, int ion_buffer_fd, size_t ion_buffer_size, size_t ion_buffer_offset, LiteRtIonDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_ION_SUPPORT if (!tensor_type || !tensor_buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -95,11 +101,15 @@ LiteRtStatus LiteRtCreateTensorBufferFromIonBuffer( ion_buffer_size, ion_buffer_offset, deallocator)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_ION_SUPPORT } LiteRtStatus LiteRtGetTensorBufferIonBuffer(LiteRtTensorBuffer tensor_buffer, void** ion_buffer_addr, int* ion_buffer_fd) { +#if LITERT_HAS_ION_SUPPORT if (!tensor_buffer || !ion_buffer_addr || !ion_buffer_fd) { return kLiteRtStatusErrorInvalidArgument; } @@ -109,15 +119,17 @@ LiteRtStatus LiteRtGetTensorBufferIonBuffer(LiteRtTensorBuffer tensor_buffer, *ion_buffer_addr = ion_buffer.first; *ion_buffer_fd = ion_buffer.second; return kLiteRtStatusOk; -} +#else + return kLiteRtStatusErrorUnsupported; #endif // LITERT_HAS_ION_SUPPORT +} -#if LITERT_HAS_DMABUF_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromDmaBufBuffer( const LiteRtRankedTensorType* tensor_type, void* dmabuf_buffer_addr, int dmabuf_buffer_fd, size_t dmabuf_buffer_size, size_t dmabuf_buffer_offset, LiteRtDmaBufDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_DMABUF_SUPPORT if (!tensor_type || !tensor_buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -128,11 +140,15 @@ LiteRtStatus LiteRtCreateTensorBufferFromDmaBufBuffer( dmabuf_buffer_size, dmabuf_buffer_offset, deallocator)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_DMABUF_SUPPORT } LiteRtStatus LiteRtGetTensorBufferDmaBufBuffer(LiteRtTensorBuffer tensor_buffer, void** dmabuf_buffer_addr, int* dmabuf_buffer_fd) { +#if LITERT_HAS_DMABUF_SUPPORT if (!tensor_buffer || !dmabuf_buffer_addr || !dmabuf_buffer_fd) { return kLiteRtStatusErrorInvalidArgument; } @@ -142,15 +158,17 @@ LiteRtStatus LiteRtGetTensorBufferDmaBufBuffer(LiteRtTensorBuffer tensor_buffer, *dmabuf_buffer_addr = dmabuf_buffer.first; *dmabuf_buffer_fd = dmabuf_buffer.second; return kLiteRtStatusOk; -} +#else + return kLiteRtStatusErrorUnsupported; #endif // LITERT_HAS_DMABUF_SUPPORT +} -#if LITERT_HAS_OPENCL_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromOpenClMemory( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, LiteRtClMem cl_mem_addr, size_t opencl_buffer_size, LiteRtOpenClDeallocator deallocator, LiteRtTensorBuffer* buffer) { +#if LITERT_HAS_OPENCL_SUPPORT if (!tensor_type || !buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -160,10 +178,14 @@ LiteRtStatus LiteRtCreateTensorBufferFromOpenClMemory( opencl_buffer_size, deallocator)); *buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_OPENCL_SUPPORT } LiteRtStatus LiteRtGetTensorBufferOpenClMemory(LiteRtTensorBuffer tensor_buffer, LiteRtClMem* cl_mem_addr) { +#if LITERT_HAS_OPENCL_SUPPORT if (!tensor_buffer || !cl_mem_addr) { return kLiteRtStatusErrorInvalidArgument; } @@ -172,8 +194,10 @@ LiteRtStatus LiteRtGetTensorBufferOpenClMemory(LiteRtTensorBuffer tensor_buffer, *cl_mem_addr = opencl_memory->GetMemoryPtr(); return kLiteRtStatusOk; -} +#else + return kLiteRtStatusErrorUnsupported; #endif // LITERT_HAS_OPENCL_SUPPORT +} LiteRtStatus LiteRtGetTensorBufferCustomTensorBufferHandle( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle) { @@ -187,12 +211,12 @@ LiteRtStatus LiteRtGetTensorBufferCustomTensorBufferHandle( return kLiteRtStatusOk; } -#if LITERT_HAS_METAL_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromMetalMemory( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, void* metal_buffer, size_t metal_buffer_size, LiteRtMetalDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_METAL_SUPPORT if (!tensor_type || !tensor_buffer || !metal_buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -202,10 +226,14 @@ LiteRtStatus LiteRtCreateTensorBufferFromMetalMemory( env, *tensor_type, buffer_type, metal_buffer, metal_buffer_size)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_METAL_SUPPORT } LiteRtStatus LiteRtGetTensorBufferMetalMemory( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle) { +#if LITERT_HAS_METAL_SUPPORT if (!tensor_buffer || !hw_memory_handle) { return kLiteRtStatusErrorInvalidArgument; } @@ -214,16 +242,17 @@ LiteRtStatus LiteRtGetTensorBufferMetalMemory( *hw_memory_handle = custom_buffer->raw_handle(); return kLiteRtStatusOk; -} - +#else + return kLiteRtStatusErrorUnsupported; #endif // LITERT_HAS_METAL_SUPPORT +} -#if LITERT_HAS_FASTRPC_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromFastRpcBuffer( const LiteRtRankedTensorType* tensor_type, void* fastrpc_buffer_addr, int fastrpc_buffer_fd, size_t fastrpc_buffer_size, size_t fastrpc_buffer_offset, LiteRtFastRpcDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_FASTRPC_SUPPORT if (!tensor_type || !tensor_buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -234,11 +263,15 @@ LiteRtStatus LiteRtCreateTensorBufferFromFastRpcBuffer( fastrpc_buffer_size, fastrpc_buffer_offset, deallocator)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_FASTRPC_SUPPORT } LiteRtStatus LiteRtGetTensorBufferFastRpcBuffer( LiteRtTensorBuffer tensor_buffer, void** fastrpc_buffer_addr, int* fastrpc_buffer_fd) { +#if LITERT_HAS_FASTRPC_SUPPORT if (!tensor_buffer || !fastrpc_buffer_addr || !fastrpc_buffer_fd) { return kLiteRtStatusErrorInvalidArgument; } @@ -249,14 +282,16 @@ LiteRtStatus LiteRtGetTensorBufferFastRpcBuffer( *fastrpc_buffer_addr = fastrpc_buffer.first; *fastrpc_buffer_fd = fastrpc_buffer.second; return kLiteRtStatusOk; -} +#else + return kLiteRtStatusErrorUnsupported; #endif // LITERT_HAS_FASTRPC_SUPPORT +} -#if LITERT_HAS_OPENGL_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromGlBuffer( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtGLenum target, LiteRtGLuint id, size_t size_bytes, size_t offset, LiteRtGlBufferDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_OPENGL_SUPPORT if (!tensor_type || !tensor_buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -266,12 +301,16 @@ LiteRtStatus LiteRtCreateTensorBufferFromGlBuffer( size_bytes, offset, deallocator)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_OPENGL_SUPPORT } LiteRtStatus LiteRtGetTensorBufferGlBuffer(LiteRtTensorBuffer tensor_buffer, LiteRtGLenum* target, LiteRtGLuint* id, size_t* size_bytes, size_t* offset) { +#if LITERT_HAS_OPENGL_SUPPORT if (!tensor_buffer || !target || !id) { return kLiteRtStatusErrorInvalidArgument; } @@ -283,29 +322,17 @@ LiteRtStatus LiteRtGetTensorBufferGlBuffer(LiteRtTensorBuffer tensor_buffer, *size_bytes = gl_buffer->size_bytes(); *offset = gl_buffer->offset(); return kLiteRtStatusOk; -} #else -LiteRtStatus LiteRtCreateTensorBufferFromGlBuffer( - LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, - LiteRtGLenum target, LiteRtGLuint id, size_t size_bytes, size_t offset, - LiteRtGlBufferDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { - return kLiteRtStatusErrorUnsupported; -} - -LiteRtStatus LiteRtGetTensorBufferGlBuffer(LiteRtTensorBuffer tensor_buffer, - LiteRtGLenum* target, - LiteRtGLuint* id, size_t* size_bytes, - size_t* offset) { return kLiteRtStatusErrorUnsupported; -} #endif // LITERT_HAS_OPENGL_SUPPORT +} -#if LITERT_HAS_OPENGL_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromGlTexture( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtGLenum target, LiteRtGLuint id, LiteRtGLenum format, size_t size_bytes, LiteRtGLint layer, LiteRtGlTextureDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_OPENGL_SUPPORT if (!tensor_type || !tensor_buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -315,11 +342,15 @@ LiteRtStatus LiteRtCreateTensorBufferFromGlTexture( layer, deallocator)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_OPENGL_SUPPORT } LiteRtStatus LiteRtGetTensorBufferGlTexture( LiteRtTensorBuffer tensor_buffer, LiteRtGLenum* target, LiteRtGLuint* id, LiteRtGLenum* format, size_t* size_bytes, LiteRtGLint* layer) { +#if LITERT_HAS_OPENGL_SUPPORT if (!tensor_buffer || !target || !id || !format || !size_bytes || !layer) { return kLiteRtStatusErrorInvalidArgument; } @@ -330,29 +361,17 @@ LiteRtStatus LiteRtGetTensorBufferGlTexture( *size_bytes = gl_texture->size_bytes(); *layer = gl_texture->layer(); return kLiteRtStatusOk; -} #else -LiteRtStatus LiteRtCreateTensorBufferFromGlTexture( - LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, - LiteRtGLenum target, LiteRtGLuint id, LiteRtGLenum format, - size_t size_bytes, LiteRtGLint layer, - LiteRtGlTextureDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { - return kLiteRtStatusErrorUnsupported; -} - -LiteRtStatus LiteRtGetTensorBufferGlTexture( - LiteRtTensorBuffer tensor_buffer, LiteRtGLenum* target, LiteRtGLuint* id, - LiteRtGLenum* format, size_t* size_bytes, LiteRtGLint* layer) { return kLiteRtStatusErrorUnsupported; -} #endif // LITERT_HAS_OPENGL_SUPPORT +} -#if LITERT_HAS_WEBGPU_SUPPORT LiteRtStatus LiteRtCreateTensorBufferFromWebGpuBuffer( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, LiteRtWGPUBuffer wgpu_buffer, size_t wgpu_buffer_size, LiteRtWebGpuBufferDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_WEBGPU_SUPPORT if (!tensor_type || !tensor_buffer) { return kLiteRtStatusErrorInvalidArgument; } @@ -362,6 +381,9 @@ LiteRtStatus LiteRtCreateTensorBufferFromWebGpuBuffer( env, *tensor_type, buffer_type, wgpu_buffer, wgpu_buffer_size)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_WEBGPU_SUPPORT } LiteRtStatus LiteRtCreateTensorBufferFromWebGpuTexture( @@ -369,6 +391,7 @@ LiteRtStatus LiteRtCreateTensorBufferFromWebGpuTexture( void* webgpu_texture, size_t webgpu_texture_size, LiteRtWebGpuTextureDeallocator deallocator, LiteRtTensorBuffer* tensor_buffer) { +#if LITERT_HAS_WEBGPU_SUPPORT if (!tensor_type || !tensor_buffer || !webgpu_texture) { return kLiteRtStatusErrorInvalidArgument; } @@ -378,11 +401,15 @@ LiteRtStatus LiteRtCreateTensorBufferFromWebGpuTexture( env, *tensor_type, webgpu_texture, webgpu_texture_size)); *tensor_buffer = created_tensor_buffer.release(); return kLiteRtStatusOk; +#else + return kLiteRtStatusErrorUnsupported; +#endif // LITERT_HAS_WEBGPU_SUPPORT } // Return an error if the backing buffer is not a WebGpu buffer. LiteRtStatus LiteRtGetTensorBufferWebGpuBuffer( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle) { +#if LITERT_HAS_WEBGPU_SUPPORT if (!tensor_buffer || !hw_memory_handle) { return kLiteRtStatusErrorInvalidArgument; } @@ -391,12 +418,14 @@ LiteRtStatus LiteRtGetTensorBufferWebGpuBuffer( *hw_memory_handle = webgpu_buffer->hw_buffer_handle(); return kLiteRtStatusOk; -} +#else + return kLiteRtStatusErrorUnsupported; #endif // LITERT_HAS_WEBGPU_SUPPORT +} -#if LITERT_HAS_VULKAN_SUPPORT LiteRtStatus LiteRtGetTensorBufferVulkanMemory( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle) { +#if LITERT_HAS_VULKAN_SUPPORT if (!tensor_buffer || !hw_memory_handle) { return kLiteRtStatusErrorInvalidArgument; } @@ -405,8 +434,10 @@ LiteRtStatus LiteRtGetTensorBufferVulkanMemory( *hw_memory_handle = custom_buffer->hw_buffer_handle(); return kLiteRtStatusOk; -} +#else + return kLiteRtStatusErrorUnsupported; #endif // LITERT_HAS_VULKAN_SUPPORT +} LiteRtStatus LiteRtCreateManagedTensorBuffer( LiteRtEnvironment env, LiteRtTensorBufferType buffer_type, diff --git a/litert/c/litert_tensor_buffer.h b/litert/c/litert_tensor_buffer.h index 219518e977..e1823e5401 100644 --- a/litert/c/litert_tensor_buffer.h +++ b/litert/c/litert_tensor_buffer.h @@ -51,7 +51,6 @@ LiteRtStatus LiteRtCreateTensorBufferFromHostMemory( LiteRtStatus LiteRtGetTensorBufferHostMemory(LiteRtTensorBuffer tensor_buffer, void** host_memory_addr); -#if LITERT_HAS_AHWB_SUPPORT // Create a tensor buffer from an existing AHardwareBuffer, with optional // AHardwareBuffer deallocator (it can be NULL). An non-zero `buffer_offset` can // be used to specify multiple tensor buffers sharing the same underlying AHWB, @@ -62,17 +61,19 @@ LiteRtStatus LiteRtGetTensorBufferHostMemory(LiteRtTensorBuffer tensor_buffer, // calling LiteRtDestroyTensorBuffer() to release the object. // NULL deallocator means that the AHardwareBuffer is not managed by the tensor // buffer and therefore must be released separately by the caller. +// +// @warning kLiteRtStatusErrorUnsupported is returned if AHWB is not supported. LiteRtStatus LiteRtCreateTensorBufferFromAhwb( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, AHardwareBuffer* ahwb, size_t ahwb_offset, LiteRtAhwbDeallocator deallocator, LiteRtTensorBuffer* buffer); // Return an error if the backing buffer is not an AhardwareBuffer. +// +// @warning kLiteRtStatusErrorUnsupported is returned if AHWB is not supported. LiteRtStatus LiteRtGetTensorBufferAhwb(LiteRtTensorBuffer tensor_buffer, AHardwareBuffer** ahwb); -#endif // LITERT_HAS_AHWB_SUPPORT -#if LITERT_HAS_ION_SUPPORT // Create a tensor buffer from an existing ION buffer of a given size, with // optional ION buffer deallocator (it can be NULL). An non-zero // `ion_buffer_offset` can be used to specify multiple tensor buffers sharing @@ -84,18 +85,20 @@ LiteRtStatus LiteRtGetTensorBufferAhwb(LiteRtTensorBuffer tensor_buffer, // calling LiteRtDestroyTensorBuffer() to release the object. // NULL deallocator means that the ION buffer is not managed by the tensor // buffer and therefore must be released separately by the caller. +// +// @warning kLiteRtStatusErrorUnsupported is returned if ION is not supported. LiteRtStatus LiteRtCreateTensorBufferFromIonBuffer( const LiteRtRankedTensorType* tensor_type, void* ion_buffer_addr, int ion_buffer_fd, size_t ion_buffer_size, size_t ion_buffer_offset, LiteRtIonDeallocator deallocator, LiteRtTensorBuffer* buffer); // Return an error if the backing buffer is not an ION buffer. +// +// @warning kLiteRtStatusErrorUnsupported is returned if ION is not supported. LiteRtStatus LiteRtGetTensorBufferIonBuffer(LiteRtTensorBuffer buffer, void** ion_buffer_addr, int* ion_buffer_fd); -#endif // LITERT_HAS_ION_SUPPORT -#if LITERT_HAS_DMABUF_SUPPORT // Create a tensor buffer from an existing DMA-BUF buffer of a given size, with // optional DMA-BUF buffer deallocator (it can be NULL). An non-zero // `dmabuf_buffer_offset` can be used to specify multiple tensor buffers sharing @@ -107,6 +110,9 @@ LiteRtStatus LiteRtGetTensorBufferIonBuffer(LiteRtTensorBuffer buffer, // calling LiteRtDestroyTensorBuffer() to release the object. // NULL deallocator means that the DMA-BUF buffer is not managed by the tensor // buffer and therefore must be released separately by the caller. +// +// @warning kLiteRtStatusErrorUnsupported is returned if DMABUF is not +// supported. LiteRtStatus LiteRtCreateTensorBufferFromDmaBufBuffer( const LiteRtRankedTensorType* tensor_type, void* dmabuf_buffer_addr, int dmabuf_buffer_fd, size_t dmabuf_buffer_size, @@ -114,12 +120,13 @@ LiteRtStatus LiteRtCreateTensorBufferFromDmaBufBuffer( LiteRtTensorBuffer* buffer); // Return an error if the backing buffer is not an DMA-BUF buffer. +// +// @warning kLiteRtStatusErrorUnsupported is returned if DMABUF is not +// supported. LiteRtStatus LiteRtGetTensorBufferDmaBufBuffer(LiteRtTensorBuffer tensor_buffer, void** dmabuf_buffer_addr, int* dmabuf_buffer_fd); -#endif // LITERT_HAS_DMABUF_SUPPORT -#if LITERT_HAS_FASTRPC_SUPPORT // Create a tensor buffer from an existing FastRPC memory buffer of a given // size, with optional FastRPC memory buffer deallocator (it can be NULL). An // non-zero `fastrpc_buffer_offset` can be used to specify multiple tensor @@ -132,18 +139,23 @@ LiteRtStatus LiteRtGetTensorBufferDmaBufBuffer(LiteRtTensorBuffer tensor_buffer, // calling LiteRtDestroyTensorBuffer() to release the object. // NULL deallocator means that the FastRPC buffer is not managed by the tensor // buffer and therefore must be released separately by the caller. +// +// @warning kLiteRtStatusErrorUnsupported is returned if FASTRPC is not +// supported. LiteRtStatus LiteRtCreateTensorBufferFromFastRpcBuffer( const LiteRtRankedTensorType* tensor_type, void* fastrpc_buffer_addr, - int fastrpc_fd, size_t fastrpc_buffer_size, size_t fastrpc_buffer_offset, - LiteRtFastRpcDeallocator deallocator, LiteRtTensorBuffer* buffer); + int fastrpc_buffer_fd, size_t fastrpc_buffer_size, + size_t fastrpc_buffer_offset, LiteRtFastRpcDeallocator deallocator, + LiteRtTensorBuffer* tensor_buffer); // Return an error if the backing buffer is not a FastRPC memory buffer. +// +// @warning kLiteRtStatusErrorUnsupported is returned if FASTRPC is not +// supported. LiteRtStatus LiteRtGetTensorBufferFastRpcBuffer( LiteRtTensorBuffer tensor_buffer, void** fastrpc_buffer_addr, int* fastrpc_buffer_fd); -#endif // LITERT_HAS_FASTRPC_SUPPORT -#if LITERT_HAS_OPENCL_SUPPORT // Create a tensor buffer from an existing OpenCL memory of a given size, with // optional opencl memory buffer deallocator (it can be NULL). // @@ -151,6 +163,9 @@ LiteRtStatus LiteRtGetTensorBufferFastRpcBuffer( // calling LiteRtDestroyTensorBuffer() to release the object. // NULL deallocator means that the OpenCL buffer is not managed by the tensor // buffer and therefore must be released separately by the caller. +// +// @warning kLiteRtStatusErrorUnsupported is returned if OPENCL is not +// supported. LiteRtStatus LiteRtCreateTensorBufferFromOpenClMemory( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, LiteRtClMem cl_mem_addr, @@ -158,9 +173,11 @@ LiteRtStatus LiteRtCreateTensorBufferFromOpenClMemory( LiteRtTensorBuffer* buffer); // Return an error if the backing buffer is not a OpenCL memory. +// +// @warning kLiteRtStatusErrorUnsupported is returned if OPENCL is not +// supported. LiteRtStatus LiteRtGetTensorBufferOpenClMemory(LiteRtTensorBuffer tensor_buffer, LiteRtClMem* cl_mem_addr); -#endif // LITERT_HAS_OPENCL_SUPPORT // Return an error if the backing buffer is not a custom tensor buffer. // @@ -201,7 +218,6 @@ LiteRtStatus LiteRtGetTensorBufferGlTexture( LiteRtTensorBuffer tensor_buffer, LiteRtGLenum* target, LiteRtGLuint* id, LiteRtGLenum* format, size_t* size_bytes, LiteRtGLint* layer); -#if LITERT_HAS_WEBGPU_SUPPORT // Create a tensor buffer from an existing WebGPU memory of a given size, with // optional WebGPU memory buffer deallocator (it can be NULL). // @@ -209,6 +225,9 @@ LiteRtStatus LiteRtGetTensorBufferGlTexture( // releasing the object. NULL deallocator means that the Metal buffer is not // managed by the tensor buffer and therefore must be released separately by the // caller. +// +// @warning kLiteRtStatusErrorUnsupported is returned if WEBGPU is not +// supported. LiteRtStatus LiteRtCreateTensorBufferFromWebGpuBuffer( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, LiteRtWGPUBuffer wgpu_buffer, @@ -222,6 +241,9 @@ LiteRtStatus LiteRtCreateTensorBufferFromWebGpuBuffer( // releasing the object. NULL deallocator means that the WebGPU texture is not // managed by the tensor buffer and therefore must be released separately by the // caller. +// +// @warning kLiteRtStatusErrorUnsupported is returned if WEBGPU is not +// supported. LiteRtStatus LiteRtCreateTensorBufferFromWebGpuTexture( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, void* webgpu_texture, size_t webgpu_texture_size, @@ -229,11 +251,12 @@ LiteRtStatus LiteRtCreateTensorBufferFromWebGpuTexture( LiteRtTensorBuffer* tensor_buffer); // Return an error if the backing buffer is not a WebGpu buffer. +// +// @warning kLiteRtStatusErrorUnsupported is returned if WEBGPU is not +// supported. LiteRtStatus LiteRtGetTensorBufferWebGpuBuffer( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle); -#endif // LITERT_HAS_WEBGPU_SUPPORT -#if LITERT_HAS_METAL_SUPPORT // Create a tensor buffer from an existing Metal memory of a given size, with // optional metal memory buffer deallocator (it can be NULL). // @@ -241,6 +264,8 @@ LiteRtStatus LiteRtGetTensorBufferWebGpuBuffer( // releasing the object. NULL deallocator means that the Metal buffer is not // managed by the tensor buffer and therefore must be released separately by the // caller. +// +// @warning kLiteRtStatusErrorUnsupported is returned if METAL is not supported. LiteRtStatus LiteRtCreateTensorBufferFromMetalMemory( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, void* metal_buffer, @@ -248,15 +273,17 @@ LiteRtStatus LiteRtCreateTensorBufferFromMetalMemory( LiteRtTensorBuffer* tensor_buffer); // Return an error if the backing buffer is not a Metal memory. +// +// @warning kLiteRtStatusErrorUnsupported is returned if METAL is not supported. LiteRtStatus LiteRtGetTensorBufferMetalMemory(LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle); -#endif // LITERT_HAS_METAL_SUPPORT -#if LITERT_HAS_VULKAN_SUPPORT // Return an error if the backing buffer is not a Vulkan device memory. +// +// @warning kLiteRtStatusErrorUnsupported is returned if VULKAN is not +// supported. LiteRtStatus LiteRtGetTensorBufferVulkanMemory( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle); -#endif // LITERT_HAS_VULKAN_SUPPORT // Create a managed TensorBuffer for a given size and type. // diff --git a/litert/cc/internal/BUILD b/litert/cc/internal/BUILD index 42db89878f..fc85a5f248 100644 --- a/litert/cc/internal/BUILD +++ b/litert/cc/internal/BUILD @@ -643,7 +643,6 @@ cc_library( # The visibility is for testing only, otherwise it would be private. visibility = ["//litert/cc/dynamic_runtime:__pkg__"], deps = [ - "//litert/c:litert_common", "//litert/c:litert_compiled_model_header", "//litert/c:litert_environment_header", "//litert/c:litert_environment_options_header", @@ -669,7 +668,6 @@ cc_library( "//litert/kotlin/src/tests/google:__pkg__", ], deps = [ - "//litert/c:litert_common", "//litert/c:litert_compiled_model_impl", "//litert/c:litert_environment_impl", "//litert/c:litert_environment_options_impl", diff --git a/litert/cc/internal/litert_runtime_builtin.cc b/litert/cc/internal/litert_runtime_builtin.cc index 200a3f8c29..e1db7f5f84 100644 --- a/litert/cc/internal/litert_runtime_builtin.cc +++ b/litert/cc/internal/litert_runtime_builtin.cc @@ -15,7 +15,6 @@ #include "litert/cc/internal/litert_runtime_builtin.h" #include "litert/c/internal/litert_runtime_c_api.h" -#include "litert/c/litert_common.h" #include "litert/c/litert_compiled_model.h" #include "litert/c/litert_environment.h" #include "litert/c/litert_environment_options.h" @@ -158,32 +157,22 @@ static const LiteRtRuntimeCApiStruct kBuiltinStruct = { .litert_create_tensor_buffer_from_host_memory = LiteRtCreateTensorBufferFromHostMemory, .litert_get_tensor_buffer_host_memory = LiteRtGetTensorBufferHostMemory, -#if LITERT_HAS_AHWB_SUPPORT .litert_create_tensor_buffer_from_ahwb = LiteRtCreateTensorBufferFromAhwb, .litert_get_tensor_buffer_ahwb = LiteRtGetTensorBufferAhwb, -#endif // LITERT_HAS_AHWB_SUPPORT -#if LITERT_HAS_ION_SUPPORT .litert_create_tensor_buffer_from_ion_buffer = LiteRtCreateTensorBufferFromIonBuffer, .litert_get_tensor_buffer_ion_buffer = LiteRtGetTensorBufferIonBuffer, -#endif // LITERT_HAS_ION_SUPPORT -#if LITERT_HAS_DMABUF_SUPPORT .litert_create_tensor_buffer_from_dma_buf_buffer = LiteRtCreateTensorBufferFromDmaBufBuffer, .litert_get_tensor_buffer_dma_buf_buffer = LiteRtGetTensorBufferDmaBufBuffer, -#endif // LITERT_HAS_DMABUF_SUPPORT -#if LITERT_HAS_FASTRPC_SUPPORT .litert_create_tensor_buffer_from_fast_rpc_buffer = LiteRtCreateTensorBufferFromFastRpcBuffer, .litert_get_tensor_buffer_fast_rpc_buffer = LiteRtGetTensorBufferFastRpcBuffer, -#endif // LITERT_HAS_FASTRPC_SUPPORT -#if LITERT_HAS_OPENCL_SUPPORT .litert_create_tensor_buffer_from_opencl_memory = LiteRtCreateTensorBufferFromOpenClMemory, .litert_get_tensor_buffer_opencl_memory = LiteRtGetTensorBufferOpenClMemory, -#endif // LITERT_HAS_OPENCL_SUPPORT .litert_get_tensor_buffer_custom_tensor_buffer_handle = LiteRtGetTensorBufferCustomTensorBufferHandle, .litert_create_tensor_buffer_from_gl_buffer = @@ -192,22 +181,16 @@ static const LiteRtRuntimeCApiStruct kBuiltinStruct = { .litert_create_tensor_buffer_from_gl_texture = LiteRtCreateTensorBufferFromGlTexture, .litert_get_tensor_buffer_gl_texture = LiteRtGetTensorBufferGlTexture, -#if LITERT_HAS_WEBGPU_SUPPORT .litert_create_tensor_buffer_from_web_gpu_buffer = LiteRtCreateTensorBufferFromWebGpuBuffer, .litert_get_tensor_buffer_web_gpu_buffer = LiteRtGetTensorBufferWebGpuBuffer, .litert_create_tensor_buffer_from_web_gpu_texture = LiteRtCreateTensorBufferFromWebGpuTexture, -#endif // LITERT_HAS_WEBGPU_SUPPORT -#if LITERT_HAS_METAL_SUPPORT .litert_create_tensor_buffer_from_metal_memory = LiteRtCreateTensorBufferFromMetalMemory, .litert_get_tensor_buffer_metal_memory = LiteRtGetTensorBufferMetalMemory, -#endif // LITERT_HAS_METAL_SUPPORT -#if LITERT_HAS_VULKAN_SUPPORT .litert_get_tensor_buffer_vulkan_memory = LiteRtGetTensorBufferVulkanMemory, -#endif // LITERT_HAS_VULKAN_SUPPORT .litert_create_managed_tensor_buffer = LiteRtCreateManagedTensorBuffer, .litert_create_managed_tensor_buffer_from_requirements = LiteRtCreateManagedTensorBufferFromRequirements, diff --git a/litert/cc/internal/litert_runtime_proxy.h b/litert/cc/internal/litert_runtime_proxy.h index 540071bc35..95bbdafc4e 100644 --- a/litert/cc/internal/litert_runtime_proxy.h +++ b/litert/cc/internal/litert_runtime_proxy.h @@ -741,7 +741,6 @@ class RuntimeProxy { tensor_buffer, host_memory_addr); } -#if LITERT_HAS_AHWB_SUPPORT LiteRtStatus CreateTensorBufferFromAhwb( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, AHardwareBuffer* ahwb, size_t ahwb_offset, @@ -757,8 +756,6 @@ class RuntimeProxy { ahwb); } -#endif // LITERT_HAS_AHWB_SUPPORT -#if LITERT_HAS_ION_SUPPORT LiteRtStatus CreateTensorBufferFromIonBuffer( const LiteRtRankedTensorType* tensor_type, void* ion_buffer_addr, int ion_buffer_fd, size_t ion_buffer_size, size_t ion_buffer_offset, @@ -776,8 +773,6 @@ class RuntimeProxy { ion_buffer_addr, ion_buffer_fd); } -#endif // LITERT_HAS_ION_SUPPORT -#if LITERT_HAS_DMABUF_SUPPORT LiteRtStatus CreateTensorBufferFromDmaBufBuffer( const LiteRtRankedTensorType* tensor_type, void* dmabuf_buffer_addr, int dmabuf_buffer_fd, size_t dmabuf_buffer_size, @@ -797,8 +792,6 @@ class RuntimeProxy { dmabuf_buffer_fd); } -#endif // LITERT_HAS_DMABUF_SUPPORT -#if LITERT_HAS_FASTRPC_SUPPORT LiteRtStatus CreateTensorBufferFromFastRpcBuffer( const LiteRtRankedTensorType* tensor_type, void* fastrpc_buffer_addr, int fastrpc_fd, size_t fastrpc_buffer_size, size_t fastrpc_buffer_offset, @@ -817,8 +810,6 @@ class RuntimeProxy { fastrpc_buffer_fd); } -#endif // LITERT_HAS_FASTRPC_SUPPORT -#if LITERT_HAS_OPENCL_SUPPORT LiteRtStatus CreateTensorBufferFromOpenClMemory( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, LiteRtClMem cl_mem_addr, @@ -835,7 +826,6 @@ class RuntimeProxy { tensor_buffer, cl_mem_addr); } -#endif // LITERT_HAS_OPENCL_SUPPORT LiteRtStatus GetTensorBufferCustomTensorBufferHandle( LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle) { LITERT_PROXY_METHOD_STATUS( @@ -879,7 +869,6 @@ class RuntimeProxy { layer); } -#if LITERT_HAS_WEBGPU_SUPPORT LiteRtStatus CreateTensorBufferFromWebGpuBuffer( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, LiteRtWGPUBuffer wgpu_buffer, @@ -906,8 +895,6 @@ class RuntimeProxy { webgpu_texture_size, deallocator, tensor_buffer); } -#endif // LITERT_HAS_WEBGPU_SUPPORT -#if LITERT_HAS_METAL_SUPPORT LiteRtStatus CreateTensorBufferFromMetalMemory( LiteRtEnvironment env, const LiteRtRankedTensorType* tensor_type, LiteRtTensorBufferType buffer_type, void* metal_buffer, @@ -924,15 +911,12 @@ class RuntimeProxy { tensor_buffer, hw_memory_handle); } -#endif // LITERT_HAS_METAL_SUPPORT -#if LITERT_HAS_VULKAN_SUPPORT LiteRtStatus GetTensorBufferVulkanMemory(LiteRtTensorBuffer tensor_buffer, HwMemoryHandle* hw_memory_handle) { LITERT_PROXY_METHOD_STATUS(litert_get_tensor_buffer_vulkan_memory, tensor_buffer, hw_memory_handle); } -#endif // LITERT_HAS_VULKAN_SUPPORT LiteRtStatus DuplicateTensorBuffer(LiteRtTensorBuffer tensor_buffer) { LITERT_PROXY_METHOD_STATUS(litert_duplicate_tensor_buffer, tensor_buffer); }