taichi-dev / voxel-challenge

226 stars 36 forks source link

Using arch=ti.vulkan on iMac (2017, Intel) casuses no screenshots can be saved #3

Closed imcom closed 2 years ago

imcom commented 2 years ago

Environment:

image

-> % python -V Python 3.9.12 taichi 1.0.0 numpy 1.22.3

Issue: Using the template to install and create the scene on my iMac (as above), the renderer works well but whenever I press p, there is no screenshots can be saved. I've got a minimum script to reproduce the issue

import taichi as ti
from renderer import Renderer
from taichi.math import vec3

VOXEL_DX = 1 / 64
SCREEN_RES = (1280, 720)
TARGET_FPS = 30
UP_DIR = (0, 1, 0)

def main():
    ti.init(arch=ti.vulkan)  # img can NOT be saved
    # ti.init(arch=ti.cpu)   # img can save
    renderer = Renderer(dx=VOXEL_DX,
                        image_res=SCREEN_RES,
                        up=UP_DIR,
                        voxel_edges=0.01,
                        exposure=1)

    renderer.background_color[None] = vec3(0.9, 0.3, 0.3)
    renderer.recompute_bbox()
    img = renderer.fetch_image()
    print(img)
    fname = "reproduce.jpg"
    ti.tools.image.imwrite(img, fname)

if __name__ == "__main__":
    main()

With this script, I noticed that if the arch is set to ti.cpu for instance, the img can be written to FS. But with ti.vulkan, there is no image written.

P.S. If I change the arch to either cpu / gpu in the scene.py. Then the script will crash. Attached the crash log as bellow.

scene.py
-        ti.init(arch=ti.vulkan)
+        ti.init(arch=ti.cpu)
[Taichi] version 1.0.0, llvm 10.0.0, commit 6a15da85, osx, python 3.9.12
[Taichi] Starting on arch=x64

====================================================
Camera:
* Drag with your left mouse button to rotate
* Press W/A/S/D/Q/E to move
====================================================

[mvk-info] MoltenVK version 1.1.8, supporting Vulkan version 1.1.204.
    The following 72 Vulkan extensions are supported:
        VK_KHR_16bit_storage v1
        VK_KHR_8bit_storage v1
        VK_KHR_bind_memory2 v1
        VK_KHR_create_renderpass2 v1
        VK_KHR_dedicated_allocation v3
        VK_KHR_depth_stencil_resolve v1
        VK_KHR_descriptor_update_template v1
        VK_KHR_device_group v4
        VK_KHR_device_group_creation v1
        VK_KHR_driver_properties v1
        VK_KHR_external_fence v1
        VK_KHR_external_fence_capabilities v1
        VK_KHR_external_memory v1
        VK_KHR_external_memory_capabilities v1
        VK_KHR_external_semaphore v1
        VK_KHR_external_semaphore_capabilities v1
        VK_KHR_get_memory_requirements2 v1
        VK_KHR_get_physical_device_properties2 v2
        VK_KHR_get_surface_capabilities2 v1
        VK_KHR_imageless_framebuffer v1
        VK_KHR_image_format_list v1
        VK_KHR_maintenance1 v2
        VK_KHR_maintenance2 v1
        VK_KHR_maintenance3 v1
        VK_KHR_multiview v1
        VK_KHR_portability_subset v1
        VK_KHR_push_descriptor v2
        VK_KHR_relaxed_block_layout v1
        VK_KHR_sampler_mirror_clamp_to_edge v3
        VK_KHR_sampler_ycbcr_conversion v14
        VK_KHR_shader_draw_parameters v1
        VK_KHR_shader_float16_int8 v1
        VK_KHR_shader_subgroup_extended_types v1
        VK_KHR_storage_buffer_storage_class v1
        VK_KHR_surface v25
        VK_KHR_swapchain v70
        VK_KHR_swapchain_mutable_format v1
        VK_KHR_timeline_semaphore v2
        VK_KHR_uniform_buffer_standard_layout v1
        VK_KHR_variable_pointers v1
        VK_EXT_debug_marker v4
        VK_EXT_debug_report v10
        VK_EXT_debug_utils v2
        VK_EXT_descriptor_indexing v2
        VK_EXT_fragment_shader_interlock v1
        VK_EXT_hdr_metadata v2
        VK_EXT_host_query_reset v1
        VK_EXT_image_robustness v1
        VK_EXT_inline_uniform_block v1
        VK_EXT_memory_budget v1
        VK_EXT_metal_surface v1
        VK_EXT_post_depth_coverage v1
        VK_EXT_private_data v1
        VK_EXT_robustness2 v1
        VK_EXT_scalar_block_layout v1
        VK_EXT_shader_stencil_export v1
        VK_EXT_shader_viewport_index_layer v1
        VK_EXT_subgroup_size_control v2
        VK_EXT_swapchain_colorspace v4
        VK_EXT_texel_buffer_alignment v1
        VK_EXT_texture_compression_astc_hdr v1
        VK_EXT_vertex_attribute_divisor v3
        VK_AMD_gpu_shader_half_float v2
        VK_AMD_negative_viewport_height v1
        VK_AMD_shader_image_load_store_lod v1
        VK_AMD_shader_trinary_minmax v1
        VK_IMG_format_pvrtc v1
        VK_INTEL_shader_integer_functions2 v1
        VK_GOOGLE_display_timing v1
        VK_MVK_macos_surface v3
        VK_MVK_moltenvk v33
        VK_NV_glsl_shader v1
[mvk-info] GPU device:
        model: AMD Radeon Pro 560
        type: Discrete
        vendorID: 0x1002
        deviceID: 0x67ef
        pipelineCacheUUID: 0000277C-0C03-07D2-0000-000000000000
    supports the following Metal Versions, GPU's and Feature Sets:
        Metal Shading Language 2.3
        GPU Family Mac 2
        GPU Family Mac 1
        GPU Family Common 3
        GPU Family Common 2
        GPU Family Common 1
        macOS GPU Family 2 v1
        macOS GPU Family 1 v4
        macOS GPU Family 1 v3
        macOS GPU Family 1 v2
        macOS GPU Family 1 v1
        macOS Read-Write Texture Tier 2
[mvk-info] Created VkInstance for Vulkan version 1.0.0, as requested by app, with the following 0 Vulkan extensions enabled:
[mvk-info] MoltenVK version 1.1.8, supporting Vulkan version 1.1.204.
    The following 72 Vulkan extensions are supported:
        VK_KHR_16bit_storage v1
        VK_KHR_8bit_storage v1
        VK_KHR_bind_memory2 v1
        VK_KHR_create_renderpass2 v1
        VK_KHR_dedicated_allocation v3
        VK_KHR_depth_stencil_resolve v1
        VK_KHR_descriptor_update_template v1
        VK_KHR_device_group v4
        VK_KHR_device_group_creation v1
        VK_KHR_driver_properties v1
        VK_KHR_external_fence v1
        VK_KHR_external_fence_capabilities v1
        VK_KHR_external_memory v1
        VK_KHR_external_memory_capabilities v1
        VK_KHR_external_semaphore v1
        VK_KHR_external_semaphore_capabilities v1
        VK_KHR_get_memory_requirements2 v1
        VK_KHR_get_physical_device_properties2 v2
        VK_KHR_get_surface_capabilities2 v1
        VK_KHR_imageless_framebuffer v1
        VK_KHR_image_format_list v1
        VK_KHR_maintenance1 v2
        VK_KHR_maintenance2 v1
        VK_KHR_maintenance3 v1
        VK_KHR_multiview v1
        VK_KHR_portability_subset v1
        VK_KHR_push_descriptor v2
        VK_KHR_relaxed_block_layout v1
        VK_KHR_sampler_mirror_clamp_to_edge v3
        VK_KHR_sampler_ycbcr_conversion v14
        VK_KHR_shader_draw_parameters v1
        VK_KHR_shader_float16_int8 v1
        VK_KHR_shader_subgroup_extended_types v1
        VK_KHR_storage_buffer_storage_class v1
        VK_KHR_surface v25
        VK_KHR_swapchain v70
        VK_KHR_swapchain_mutable_format v1
        VK_KHR_timeline_semaphore v2
        VK_KHR_uniform_buffer_standard_layout v1
        VK_KHR_variable_pointers v1
        VK_EXT_debug_marker v4
        VK_EXT_debug_report v10
        VK_EXT_debug_utils v2
        VK_EXT_descriptor_indexing v2
        VK_EXT_fragment_shader_interlock v1
        VK_EXT_hdr_metadata v2
        VK_EXT_host_query_reset v1
        VK_EXT_image_robustness v1
        VK_EXT_inline_uniform_block v1
        VK_EXT_memory_budget v1
        VK_EXT_metal_surface v1
        VK_EXT_post_depth_coverage v1
        VK_EXT_private_data v1
        VK_EXT_robustness2 v1
        VK_EXT_scalar_block_layout v1
        VK_EXT_shader_stencil_export v1
        VK_EXT_shader_viewport_index_layer v1
        VK_EXT_subgroup_size_control v2
        VK_EXT_swapchain_colorspace v4
        VK_EXT_texel_buffer_alignment v1
        VK_EXT_texture_compression_astc_hdr v1
        VK_EXT_vertex_attribute_divisor v3
        VK_AMD_gpu_shader_half_float v2
        VK_AMD_negative_viewport_height v1
        VK_AMD_shader_image_load_store_lod v1
        VK_AMD_shader_trinary_minmax v1
        VK_IMG_format_pvrtc v1
        VK_INTEL_shader_integer_functions2 v1
        VK_GOOGLE_display_timing v1
        VK_MVK_macos_surface v3
        VK_MVK_moltenvk v33
        VK_NV_glsl_shader v1
[mvk-info] GPU device:
        model: AMD Radeon Pro 560
        type: Discrete
        vendorID: 0x1002
        deviceID: 0x67ef
        pipelineCacheUUID: 0000277C-0C03-07D2-0000-000000000000
    supports the following Metal Versions, GPU's and Feature Sets:
        Metal Shading Language 2.3
        GPU Family Mac 2
        GPU Family Mac 1
        GPU Family Common 3
        GPU Family Common 2
        GPU Family Common 1
        macOS GPU Family 2 v1
        macOS GPU Family 1 v4
        macOS GPU Family 1 v3
        macOS GPU Family 1 v2
        macOS GPU Family 1 v1
        macOS Read-Write Texture Tier 2
[mvk-info] Created VkInstance for Vulkan version 1.1.204, as requested by app, with the following 5 Vulkan extensions enabled:
        VK_KHR_external_memory_capabilities v1
        VK_KHR_external_semaphore_capabilities v1
        VK_KHR_get_physical_device_properties2 v2
        VK_KHR_surface v25
        VK_EXT_debug_utils v2
[E 04/16/22 23:57:35.900 3762443] Received signal 11 (Segmentation fault: 11)

                            * Taichi Core - Stack Traceback *
==========================================================================================
|                       Module |  Offset | Function                                      |
|----------------------------------------------------------------------------------------|
*               taichi_core.so |     126 | taichi::Logger::error(std::__1::basic_string< |
                                         | char, std::__1::char_traits<char>, std::__1:: |
                                         | allocator<char> > const&, bool)               |
*               taichi_core.so |     228 | taichi::(anonymous namespace)::signal_handler |
                                         | (int)                                         |
*     libsystem_platform.dylib |      29 | (null)                                        |
*                          ??? | 6298881 | (null)                                        |
*            libMoltenVK.dylib |     228 | (null)                                        |
*               taichi_core.so |      37 | taichi::lang::vulkan::VulkanDevice::~VulkanDe |
                                         | vice()                                        |
*               taichi_core.so |      14 | taichi::lang::vulkan::VulkanDevice::~VulkanDe |
                                         | vice()                                        |
*               taichi_core.so |     769 | taichi::lang::vulkan::VulkanDeviceCreator::Vu |
                                         | lkanDeviceCreator(taichi::lang::vulkan::Vulka |
                                         | nDeviceCreator::Params const&)                |
*               taichi_core.so |    1434 | taichi::ui::vulkan::AppContext::init(taichi:: |
                                         | lang::Program*, GLFWwindow*, taichi::ui::AppC |
                                         | onfig const&)                                 |
*               taichi_core.so |      22 | taichi::ui::vulkan::Renderer::init(taichi::la |
                                         | ng::Program*, GLFWwindow*, taichi::ui::AppCon |
                                         | fig const&)                                   |
*               taichi_core.so |     204 | taichi::ui::vulkan::Window::init(taichi::lang |
                                         | ::Program*, taichi::ui::AppConfig const&)     |
*               taichi_core.so |     185 | taichi::ui::vulkan::Window::Window(taichi::la |
                                         | ng::Program*, taichi::ui::AppConfig const&)   |
*               taichi_core.so |     305 | taichi::ui::PyWindow::PyWindow(taichi::lang:: |
                                         | Program*, std::__1::basic_string<char, std::_ |
                                         | _1::char_traits<char>, std::__1::allocator<ch |
                                         | ar> >, pybind11::tuple, bool, bool, std::__1: |
                                         | :basic_string<char, std::__1::char_traits<cha |
                                         | r>, std::__1::allocator<char> >, taichi::Arch |
                                         | , bool)                                       |
*               taichi_core.so |     183 | taichi::ui::PyWindow* pybind11::detail::initi |
                                         | mpl::construct_or_initialize<taichi::ui::PyWi |
                                         | ndow, taichi::lang::Program*, std::__1::basic |
                                         | _string<char, std::__1::char_traits<char>, st |
                                         | d::__1::allocator<char> >, pybind11::tuple, b |
                                         | ool, bool, std::__1::basic_string<char, std:: |
                                         | __1::char_traits<char>, std::__1::allocator<c |
                                         | har> >, taichi::Arch, bool, 0>(taichi::lang:: |
                                         | Program*&&, std::__1::basic_string<char, std: |
                                         | :__1::char_traits<char>, std::__1::allocator< |
                                         | char> >&&, pybind11::tuple&&, bool&&, bool&&, |
                                         |  std::__1::basic_string<char, std::__1::char_ |
                                         | traits<char>, std::__1::allocator<char> >&&,  |
                                         | taichi::Arch&&, bool&&)                       |
*               taichi_core.so |     179 | pybind11::class_<taichi::ui::PyWindow> pybind |
                                         | 11::detail::argument_loader<pybind11::detail: |
                                         | :value_and_holder&, taichi::lang::Program*, s |
                                         | td::__1::basic_string<char, std::__1::char_tr |
                                         | aits<char>, std::__1::allocator<char> >, pybi |
                                         | nd11::tuple, bool, bool, std::__1::basic_stri |
                                         | ng<char, std::__1::char_traits<char>, std::__ |
                                         | 1::allocator<char> >, taichi::Arch, bool>::ca |
                                         | ll_impl<void, void pybind11::detail::initimpl |
                                         | ::constructor<taichi::lang::Program*, std::__ |
                                         | 1::basic_string<char, std::__1::char_traits<c |
                                         | har>, std::__1::allocator<char> >, pybind11:: |
                                         | tuple, bool, bool, std::__1::basic_string<cha |
                                         | r, std::__1::char_traits<char>, std::__1::all |
                                         | ocator<char> >, taichi::Arch, bool>::execute< |
                                         | pybind11::class_<taichi::ui::PyWindow>, 0>(py |
                                         | bind11::class_<taichi::ui::PyWindow>&)::'lamb |
                                         | da'(pybind11::detail::value_and_holder&, taic |
                                         | hi::lang::Program*, std::__1::basic_string<ch |
                                         | ar, std::__1::char_traits<char>, std::__1::al |
                                         | locator<char> >, pybind11::tuple, bool, bool, |
                                         |  std::__1::basic_string<char, std::__1::char_ |
                                         | traits<char>, std::__1::allocator<char> >, ta |
                                         | ichi::Arch, bool)&, 0ul, 1ul, 2ul, 3ul, 4ul,  |
                                         | 5ul, 6ul, 7ul, 8ul, pybind11::detail::void_ty |
                                         | pe>(void pybind11::detail::initimpl::construc |
                                         | tor<taichi::lang::Program*, std::__1::basic_s |
                                         | tring<char, std::__1::char_traits<char>, std: |
                                         | :__1::allocator<char> >, pybind11::tuple, boo |
                                         | l, bool, std::__1::basic_string<char, std::__ |
                                         | 1::char_traits<char>, std::__1::allocator<cha |
                                         | r> >, taichi::Arch, bool>::execute<pybind11:: |
                                         | class_<taichi::ui::PyWindow>, 0>(pybind11::cl |
                                         | ass_<taichi::ui::PyWindow>&)::'lambda'(pybind |
                                         | 11::detail::value_and_holder&, taichi::lang:: |
                                         | Program*, std::__1::basic_string<char, std::_ |
                                         | _1::char_traits<char>, std::__1::allocator<ch |
                                         | ar> >, pybind11::tuple, bool, bool, std::__1: |
                                         | :basic_string<char, std::__1::char_traits<cha |
                                         | r>, std::__1::allocator<char> >, taichi::Arch |
                                         | , bool)&, std::__1::integer_sequence<unsigned |
                                         |  long, 0ul, 1ul, 2ul, 3ul, 4ul, 5ul, 6ul, 7ul |
                                         | , 8ul>, pybind11::detail::void_type&&) &&     |
*               taichi_core.so |      76 | void pybind11::cpp_function::initialize<void  |
                                         | pybind11::detail::initimpl::constructor<taich |
                                         | i::lang::Program*, std::__1::basic_string<cha |
                                         | r, std::__1::char_traits<char>, std::__1::all |
                                         | ocator<char> >, pybind11::tuple, bool, bool,  |
                                         | std::__1::basic_string<char, std::__1::char_t |
                                         | raits<char>, std::__1::allocator<char> >, tai |
                                         | chi::Arch, bool>::execute<pybind11::class_<ta |
                                         | ichi::ui::PyWindow>, 0>(pybind11::class_<taic |
                                         | hi::ui::PyWindow>&)::'lambda'(pybind11::detai |
                                         | l::value_and_holder&, taichi::lang::Program*, |
                                         |  std::__1::basic_string<char, std::__1::char_ |
                                         | traits<char>, std::__1::allocator<char> >, py |
                                         | bind11::tuple, bool, bool, std::__1::basic_st |
                                         | ring<char, std::__1::char_traits<char>, std:: |
                                         | __1::allocator<char> >, taichi::Arch, bool),  |
                                         | void, pybind11::detail::value_and_holder&, ta |
                                         | ichi::lang::Program*, std::__1::basic_string< |
                                         | char, std::__1::char_traits<char>, std::__1:: |
                                         | allocator<char> >, pybind11::tuple, bool, boo |
                                         | l, std::__1::basic_string<char, std::__1::cha |
                                         | r_traits<char>, std::__1::allocator<char> >,  |
                                         | taichi::Arch, bool, pybind11::name, pybind11: |
                                         | :is_method, pybind11::sibling, pybind11::deta |
                                         | il::is_new_style_constructor>(pybind11::class |
                                         | _<taichi::ui::PyWindow>&&, void (*)(pybind11: |
                                         | :detail::value_and_holder&, taichi::lang::Pro |
                                         | gram*, std::__1::basic_string<char, std::__1: |
                                         | :char_traits<char>, std::__1::allocator<char> |
                                         |  >, pybind11::tuple, bool, bool, std::__1::ba |
                                         | sic_string<char, std::__1::char_traits<char>, |
                                         |  std::__1::allocator<char> >, taichi::Arch, b |
                                         | ool), pybind11::name const&, pybind11::is_met |
                                         | hod const&, pybind11::sibling const&, pybind1 |
                                         | 1::detail::is_new_style_constructor const&):: |
                                         | 'lambda'(pybind11::detail::function_call&)::o |
                                         | perator()(pybind11::detail::function_call&) c |
                                         | onst                                          |
*               taichi_core.so |    4691 | pybind11::cpp_function::dispatcher(_object*,  |
                                         | _object*, _object*)                           |
*                       Python |      52 | (null)                                        |
*                       Python |     127 | (null)                                        |
*                       Python |     728 | (null)                                        |
neozhaoliang commented 2 years ago

I dont' have a iMac at hand to reproduce this bug, have you tweaked with renders.py to see if some settings may have an effect on this behavier? For example change float to ti.f32 in this line? Though it's a very rare chance that this is the cause of the bug ...

imcom commented 2 years ago

I dont' have a iMac at hand to reproduce this bug, have you tweaked with renders.py to see if some settings may have an effect on this behavier? For example change float to ti.f32 in this line? Though it's a very rare chance that this is the cause of the bug ...

Nope, I am not sure what params can/shall be tweaked :P, I will try the float -> ti.f32 tonight to see if the crash still happens

bobcao3 commented 2 years ago

Hello! The imwrite issue is a bit weird. Can you try using an absolute path instead of relative for the file? As for the CPU backend / GGUI compatibility issue, it seems to be a bug for a while, we are still trying to figure out why, sorry for that!

yuanming-hu commented 2 years ago

On my M1 Mac:

[E 04/18/22 14:54:47.466 7900605] [image_io.cpp:imwrite@30] Cannot write image file [screenshot-2022-04-18-145447.jpg]

                            * Taichi Core - Stack Traceback *
==========================================================================================
|                       Module |  Offset | Function                                      |
|----------------------------------------------------------------------------------------|
*               taichi_core.so |     120 | taichi::Logger::error(std::__1::basic_string< |
                                         | char, std::__1::char_traits<char>, std::__1:: |
                                         | allocator<char> > const&, bool)               |
*               taichi_core.so |    1408 | taichi::imwrite(std::__1::basic_string<char,  |
                                         | std::__1::char_traits<char>, std::__1::alloca |
                                         | tor<char> > const&, unsigned long, int, int,  |
                                         | int)                                          |
*               taichi_core.so |      72 | void pybind11::cpp_function::initialize<void  |
                                         | (*&)(std::__1::basic_string<char, std::__1::c |
                                         | har_traits<char>, std::__1::allocator<char> > |
                                         |  const&, unsigned long, int, int, int), void, |
                                         |  std::__1::basic_string<char, std::__1::char_ |
                                         | traits<char>, std::__1::allocator<char> > con |
                                         | st&, unsigned long, int, int, int, pybind11:: |
                                         | name, pybind11::scope, pybind11::sibling>(voi |
                                         | d (*&)(std::__1::basic_string<char, std::__1: |
                                         | :char_traits<char>, std::__1::allocator<char> |
                                         |  > const&, unsigned long, int, int, int), voi |
                                         | d (*)(std::__1::basic_string<char, std::__1:: |
                                         | char_traits<char>, std::__1::allocator<char>  |
                                         | > const&, unsigned long, int, int, int), pybi |
                                         | nd11::name const&, pybind11::scope const&, py |
                                         | bind11::sibling const&)::'lambda'(pybind11::d |
                                         | etail::function_call&)::operator()(pybind11:: |
                                         | detail::function_call&) const                 |
*               taichi_core.so |    3316 | pybind11::cpp_function::dispatcher(_object*,  |
                                         | _object*, _object*)                           |
*                      Python3 |     140 | (null)                                        |
*                      Python3 |     372 | (null)                                        |
*                      Python3 |     448 | (null)                                        |
*                      Python3 |   23928 | (null)                                        |
*                      Python3 |     120 | (null)                                        |
*                      Python3 |     288 | (null)                                        |
*                      Python3 |   23928 | (null)                                        |
*                      Python3 |     120 | (null)                                        |
*                      Python3 |     288 | (null)                                        |
*                      Python3 |   23900 | (null)                                        |
*                      Python3 |    3212 | (null)                                        |
*                      Python3 |      60 | (null)                                        |
*                      Python3 |     280 | (null)                                        |
*                      Python3 |     248 | (null)                                        |
*                      Python3 |    1624 | (null)                                        |
*                      Python3 |     340 | (null)                                        |
*                      Python3 |      40 | (null)                                        |
*                libdyld.dylib |       4 | (null)                                        |
==========================================================================================

Internal error occurred. Check out this page for possible solutions:
https://docs.taichi.graphics/lang/articles/install
Traceback (most recent call last):
  File "main.py", line 18, in <module>
    scene.finish()
  File "/Users/yuanming/repos/voxels/scene.py", line 175, in finish
    ti.tools.image.imwrite(img, fname)
  File "/Users/yuanming/Library/Python/3.8/lib/python/site-packages/taichi/tools/image.py", line 73, in imwrite
    _ti_core.imwrite(filename, ptr, resx, resy, comp)
RuntimeError: [image_io.cpp:imwrite@30] Cannot write image file [screenshot-2022-04-18-145447.jpg]
yuanming-hu commented 2 years ago

Hello! The imwrite issue is a bit weird. Can you try using an absolute path instead of relative for the file? As for the CPU backend / GGUI compatibility issue, it seems to be a bug for a while, we are still trying to figure out why, sorry for that!

Using an absolute path works on my end! @neozhaoliang Can you simply use the absolute path for now (using os.path.join etc.)?

import taichi as ti
import numpy as np

ti.init(arch=ti.vulkan) # If not initializing with vulkan the program works

img = np.zeros((16, 16, 3))
ti.tools.image.imwrite(img, 'a.jpg') 
# ti.tools.image.imwrite(img, '/tmp/a.jpg')
# If using an absolute path, the program works
neozhaoliang commented 2 years ago

@imcom Updated the code by using the absolute path for imwrite. Could you please try the new code and see if the bug is fixed?

yuanming-hu commented 2 years ago

The problem still exists because ti.vulkan initialization changes cwd on Mac for some reason: https://github.com/taichi-dev/taichi/issues/4811 We need to fix that in Taichi to systematically address this issue.

imcom commented 2 years ago

@imcom Updated the code by using the absolute path for imwrite. Could you please try the new code and see if the bug is fixed?

Sry for the late reply

Turned out that it did generate images ... as yuanming said ... the cwd is not set properly ...

cuz once you print out the cwd ... I found this... lol

image

For a workaround, dirpath = os.path.dirname(os.path.abspath(__file__)) might be appropriate

neozhaoliang commented 2 years ago

This PR fixes the cwd problem. Please build from source again and see if it's fixed?

imcom commented 2 years ago

This PR fixes the cwd problem. Please build from source again and see if it's fixed?

I will try our nightly build :D Thx!

imcom commented 2 years ago

This PR fixes the cwd problem. Please build from source again and see if it's fixed?

taichi-nightly 1.0.1.post20220420 this nightly build fixes the dir issue @neozhaoliang cheers