pytorch / pytorch/executorch

[ET-VK] VMA assertion crash on macOS/MoltenVK: test_host_cached_available() returns bool instead of VmaAllocationCreateFlags

Open
#18,696 5 comments 0 reactions 1 assignee View on GitHub

@SS-JIA is already working on this.

Since Apr 6, 2026.

module: vulkan
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

Bug

test_host_cached_available() in backends/vulkan/runtime/vk_api/memory/Allocator.cpp is declared as returning bool but returns VmaAllocationCreateFlags values, causing implicit truncation to 1 (true).

This results in allocation_strategy_device_to_host_ being set to 1 (VMA_ALLOCATION_CREATE_DEDICATED_MEMORY_BIT) instead of the intended VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT (0x800) or VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT (0x400).

When a DEVICE_TO_HOST staging buffer is created, the invalid flag causes a VMA assertion failure:

Assertion failed: ((inoutCreateInfo.flags & (VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT | 
VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT)) != 0 && "When using VMA_ALLOCATION_CREATE_MAPPED_BIT 
and usage = VMA_MEMORY_USAGE_AUTO*, you must also specify VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT 
or VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT."), function CalcAllocationParams, file vk_mem_alloc.h, line 14926.

Reproduction

  • Platform: macOS (Apple Silicon) with MoltenVK
  • Model: Any Vulkan model exported with force_fp16=True
  • ExecuTorch version: 1.2.0

Works fine on 1.1.0 where this function didn't exist.

Root Cause

// Allocator.cpp, line 13
bool test_host_cached_available(VkPhysicalDevice physical_device) {  // <- returns bool
  // ...
  if (host_visible && host_cached) {
    return VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;       // 0x800 -> truncated to true (1)
  }
  return VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT; // 0x400 -> truncated to true (1)
}

Then at line 37-38:

allocation_strategy_device_to_host_{test_host_cached_available(physical_device_)}
// Gets value 1 instead of 0x800 or 0x400

Used at line 181:

alloc_create_info.flags |= allocation_strategy_device_to_host_;  // ORs in 1 instead of a host access flag

Fix

Change the return type from bool to VmaAllocationCreateFlags:

VmaAllocationCreateFlags test_host_cached_available(VkPhysicalDevice physical_device) {

cc @SS-JIA @manuelcandales @digantdesai @cbilgin

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.