taichi icon indicating copy to clipboard operation
taichi copied to clipboard

Controllable precision when printing

Open yuanming-hu opened this issue 1 year ago • 1 comments

Concisely describe the proposed feature

import taichi as ti

ti.init()

@ti.kernel
def foo():
    a = 1.23456
    print(f"{a:.2f}")

foo()

The user would expect 1.23.

Describe the solution you'd like (if any) IIRC Taichi stores the numbers in a buffer and format them on the host. Perhaps we should allow a richer syntax?

Also note that we need support for vector/matrix and even structs.

Additional comments Not sure if this feature request was already raised somewhere...

yuanming-hu avatar Sep 01 '22 16:09 yuanming-hu

FYI this feature can be added without too much hassel since it's supported on both llvm and spirv based backends. reference:

  • https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/master/docs/debug_printf.md
  • https://docs.nvidia.com/cuda/ptx-writers-guide-to-interoperability/index.html This issue can be a pretty good get started issue for a new contributor who are interested in taichi codegen part. cc @gingerkidney

Adding this to v1.2.0 milestone so that we can get back to it in the future if no one picks it up before that.

ailzhang avatar Sep 17 '22 04:09 ailzhang

cc: @dream189free

ailzhang avatar Feb 10 '23 02:02 ailzhang