Repository: taichi-dev/taichi (language: python)

Issue:
[bug] Ndarray on CPU are not handled by caching allocator
It's listed as TODO here https://github.com/taichi-dev/taichi/blob/master/taichi/rhi/cpu/cpu_device.cpp#L33. 
Without this being implemented, ndarray will always allocate new memories instead of reusing freed cached memory blocks. 
Found this in #7072 


Discussion / hints:

Fix patch:
diff --git a/taichi/rhi/cpu/cpu_device.cpp b/taichi/rhi/cpu/cpu_device.cpp
index 57a5435337227..833ea963b71e7 100644
--- a/taichi/rhi/cpu/cpu_device.cpp
+++ b/taichi/rhi/cpu/cpu_device.cpp
@@ -28,17 +28,7 @@ DeviceAllocation CpuDevice::allocate_memory(const AllocParams &params) {
 
 DeviceAllocation CpuDevice::allocate_memory_runtime(
     const LlvmRuntimeAllocParams &params) {
-  AllocInfo info;
-  info.ptr = allocate_llvm_runtime_memory_jit(params);
-  // TODO: Add caching allocator
-  info.size = params.size;
-  info.use_cached = params.use_cached;
-  DeviceAllocation alloc;
-  alloc.alloc_id = allocations_.size();
-  alloc.device = this;
-
-  allocations_.push_back(info);
-  return alloc;
+  return allocate_memory(params);
 }
 
 void CpuDevice::dealloc_memory(DeviceAllocation handle) {


Test patch:
diff --git a/tests/python/test_ndarray.py b/tests/python/test_ndarray.py
index 221666a74756f..717d69d32b04c 100644
--- a/tests/python/test_ndarray.py
+++ b/tests/python/test_ndarray.py
@@ -711,9 +711,8 @@ def test_ndarray_reset():
     ti.reset()
 
 
-# FIXME[#7119]: enable this test on CPU backend once caching allocator is used.
 @pytest.mark.run_in_serial
-@test_utils.test(arch=supported_archs_taichi_ndarray, exclude=ti.cpu)
+@test_utils.test(arch=supported_archs_taichi_ndarray)
 def test_ndarray_in_python_func():
     def test():
         z = ti.ndarray(float, (8192, 8192))