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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions backends/aoti/common_shims.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,24 @@ AOTI_SHIM_EXPORT AOTITorchError
aoti_torch_get_storage_size(Tensor* tensor, int64_t* ret_size) {
(void)tensor;
(void)ret_size;
throw std::runtime_error("Not implemented");
throw std::runtime_error("Not implemented: aoti_torch_get_storage_size");
return Error::Internal;
}

AOTI_SHIM_EXPORT AOTITorchError
aoti_torch_clone_preserve_strides(Tensor* self, Tensor** ret_new_tensor) {
(void)self;
(void)ret_new_tensor;
throw std::runtime_error("Not implemented");
throw std::runtime_error(
"Not implemented: aoti_torch_clone_preserve_strides");
return Error::Internal;
}

AOTI_SHIM_EXPORT AOTITorchError
aoti_torch_clone(Tensor* self, Tensor** ret_new_tensor) {
(void)self;
(void)ret_new_tensor;
throw std::runtime_error("Not implemented");
throw std::runtime_error("Not implemented: aoti_torch_clone");
return Error::Internal;
}

Expand All @@ -257,7 +258,8 @@ AOTI_SHIM_EXPORT AOTITorchError aoti_torch_create_tensor_from_blob(
(void)device_type;
(void)device_index;
(void)ret_new_tensor;
throw std::runtime_error("Not implemented");
throw std::runtime_error(
"Not implemented: aoti_torch_create_tensor_from_blob");
return Error::Internal;
}

Expand Down
2 changes: 1 addition & 1 deletion backends/apple/metal/metal_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_device_name(cls) -> str:
@classmethod
def get_supported_fallback_kernels(cls) -> Dict[str, Any]:
return {
"aoti_torch_mps_addmm_out": None,
"aoti_torch_mps_bmm_out": None,
"aoti_torch_mps_convolution": None,
"aoti_torch_mps_mm_out": None,
"at::_ops::_scaled_dot_product_attention_math_for_mps::call": None,
Expand Down
1 change: 1 addition & 0 deletions backends/apple/metal/runtime/shims/et_metal.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ int metal_copy_memory(
bool src_is_device,
bool dst_is_device);
void metal_cleanup_resources();
void metal_buffer_nocopy(void* ptr, size_t nbytes, bool map_ptr_to_buffer);

// Helper functions to access Metal objects
MTLDevice_t get_metal_device();
Expand Down
12 changes: 12 additions & 0 deletions backends/apple/metal/runtime/shims/et_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ void metal_cleanup_resources() {
}
}

void metal_buffer_nocopy(void* ptr, size_t nbytes, bool map_ptr_to_buffer) {
id<MTLDevice> device = get_metal_device();
id<MTLBuffer> subBuffer = [device newBufferWithBytesNoCopy:ptr
length:nbytes
options:MTLResourceCPUCacheModeWriteCombined | MTLResourceStorageModeShared
deallocator:nil];

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for subBuffer for nullity/false-y

if (map_ptr_to_buffer) {
ptr_to_mtl_buffer[ptr] = subBuffer; // Map contents to buffer
}
}

bool metal_is_device_pointer(void* ptr) {
return ptr_to_mtl_buffer.find(ptr) != ptr_to_mtl_buffer.end();
}
Expand Down
10 changes: 10 additions & 0 deletions backends/apple/metal/runtime/shims/et_metal_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ AOTITorchError aoti_torch_mps_mm_out(
AOTITensorHandle self,
AOTITensorHandle mat2);

/**
* ExecutorTorch implementation of aoti_torch_mps_bmm_out.
* Performs batched matrix multiplication: out = self @ mat2
* All tensors must be 3-D with matching batch dimensions.
*/
AOTITorchError aoti_torch_mps_bmm_out(
AOTITensorHandle out,
AOTITensorHandle self,
AOTITensorHandle mat2);

/**
* ExecutorTorch implementation of aoti_torch_mps_convolution.
* Performs 2D convolution operation - matches PyTorch AOTI signature
Expand Down
Loading
Loading