def get_field_info(field): info = _ti_core.FieldInfo() if field is None: info.valid = False return info info.valid = True if default_cfg().arch == _ti_core.cuda: info.field_source = _ti_core.FieldSource.TaichiCuda elif default_cfg().arch == _ti_core.x64: info.field_source = _ti_core.FieldSource.TaichiX64 elif default_cfg().arch == _ti_core.vulkan: info.field_source = _ti_core.FieldSource.TaichiVulkan else: raise Exception("unsupported taichi backend") info.shape = [n for n in field.shape] info.dtype = field.dtype info.snode = field.snode.ptr if hasattr(field, 'n'): info.field_type = _ti_core.FieldType.Matrix info.matrix_rows = field.n info.matrix_cols = field.m else: info.field_type = _ti_core.FieldType.Scalar info.matrix_rows = 1 info.matrix_cols = 1 return info
def __init__(self, name, res, vsync=False, show_window=True): package_path = str(pathlib.Path(__file__).parent.parent) ti_arch = default_cfg().arch is_packed = default_cfg().packed super().__init__(name, res, vsync, show_window, package_path, ti_arch, is_packed)
def __init__(self, name, res, vsync=False, show_window=True): check_ggui_availability() package_path = str(pathlib.Path(__file__).parent.parent) ti_arch = default_cfg().arch is_packed = default_cfg().packed self.window = _ti_core.PyWindow(get_runtime().prog, name, res, vsync, show_window, package_path, ti_arch, is_packed)
def build_For(ctx, node): if node.orelse: raise TaichiSyntaxError( "'else' clause for 'for' not supported in Taichi kernels") decorator = ASTTransformer.get_decorator(ctx, node.iter) double_decorator = '' if decorator != '' and len(node.iter.args) == 1: double_decorator = ASTTransformer.get_decorator( ctx, node.iter.args[0]) if decorator == 'static': if double_decorator == 'static': raise TaichiSyntaxError("'ti.static' cannot be nested") with ctx.loop_scope_guard(is_static=True): return ASTTransformer.build_static_for( ctx, node, double_decorator == 'grouped') with ctx.loop_scope_guard(): if decorator == 'ndrange': if double_decorator != '': raise TaichiSyntaxError( "No decorator is allowed inside 'ti.ndrange") return ASTTransformer.build_ndrange_for(ctx, node) if decorator == 'grouped': if double_decorator == 'static': raise TaichiSyntaxError( "'ti.static' is not allowed inside 'ti.grouped'") elif double_decorator == 'ndrange': return ASTTransformer.build_grouped_ndrange_for(ctx, node) elif double_decorator == 'grouped': raise TaichiSyntaxError("'ti.grouped' cannot be nested") else: return ASTTransformer.build_struct_for(ctx, node, is_grouped=True) elif isinstance(node.iter, ast.Call) and isinstance( node.iter.func, ast.Name) and node.iter.func.id == 'range': return ASTTransformer.build_range_for(ctx, node) else: build_stmt(ctx, node.iter) if isinstance(node.iter.ptr, mesh.MeshElementField): if not _ti_core.is_extension_supported( impl.default_cfg().arch, _ti_core.Extension.mesh): raise Exception( 'Backend ' + str(impl.default_cfg().arch) + ' doesn\'t support MeshTaichi extension') return ASTTransformer.build_mesh_for(ctx, node) if isinstance(node.iter.ptr, mesh.MeshRelationAccessProxy): return ASTTransformer.build_nested_mesh_for(ctx, node) # Struct for return ASTTransformer.build_struct_for(ctx, node, is_grouped=False)
def init(arch=None, default_fp=None, default_ip=None, _test_mode=False, enable_fallback=True, require_version=None, **kwargs): """Initializes the Taichi runtime. This should always be the entry point of your Taichi program. Most importantly, it sets the backend used throughout the program. Args: arch: Backend to use. This is usually :const:`~taichi.lang.cpu` or :const:`~taichi.lang.gpu`. default_fp (Optional[type]): Default floating-point type. default_ip (Optional[type]): Default integral type. require_version (Optional[string]): A version string. **kwargs: Taichi provides highly customizable compilation through ``kwargs``, which allows for fine grained control of Taichi compiler behavior. Below we list some of the most frequently used ones. For a complete list, please check out https://github.com/taichi-dev/taichi/blob/master/taichi/program/compile_config.h. * ``cpu_max_num_threads`` (int): Sets the number of threads used by the CPU thread pool. * ``debug`` (bool): Enables the debug mode, under which Taichi does a few more things like boundary checks. * ``print_ir`` (bool): Prints the CHI IR of the Taichi kernels. * ``packed`` (bool): Enables the packed memory layout. See https://docs.taichi-lang.org/docs/layout. """ # Check version for users every 7 days if not disabled by users. _version_check.start_version_check_thread() # FIXME(https://github.com/taichi-dev/taichi/issues/4811): save the current working directory since it may be # changed by the Vulkan backend initialization on OS X. current_dir = os.getcwd() cfg = impl.default_cfg() # Check if installed version meets the requirements. if require_version is not None: check_require_version(require_version) # Make a deepcopy in case these args reference to items from ti.cfg, which are # actually references. If no copy is made and the args are indeed references, # ti.reset() could override the args to their default values. default_fp = _deepcopy(default_fp) default_ip = _deepcopy(default_ip) kwargs = _deepcopy(kwargs) reset() spec_cfg = _SpecialConfig() env_comp = _EnvironmentConfigurator(kwargs, cfg) env_spec = _EnvironmentConfigurator(kwargs, spec_cfg) # configure default_fp/ip: # TODO: move these stuff to _SpecialConfig too: env_default_fp = os.environ.get("TI_DEFAULT_FP") if env_default_fp: if default_fp is not None: _ti_core.warn( f'ti.init argument "default_fp" overridden by environment variable TI_DEFAULT_FP={env_default_fp}' ) if env_default_fp == '32': default_fp = f32 elif env_default_fp == '64': default_fp = f64 elif env_default_fp is not None: raise ValueError( f'Invalid TI_DEFAULT_FP={env_default_fp}, should be 32 or 64') env_default_ip = os.environ.get("TI_DEFAULT_IP") if env_default_ip: if default_ip is not None: _ti_core.warn( f'ti.init argument "default_ip" overridden by environment variable TI_DEFAULT_IP={env_default_ip}' ) if env_default_ip == '32': default_ip = i32 elif env_default_ip == '64': default_ip = i64 elif env_default_ip is not None: raise ValueError( f'Invalid TI_DEFAULT_IP={env_default_ip}, should be 32 or 64') if default_fp is not None: impl.get_runtime().set_default_fp(default_fp) if default_ip is not None: impl.get_runtime().set_default_ip(default_ip) # submodule configurations (spec_cfg): env_spec.add('log_level', str) env_spec.add('gdb_trigger') env_spec.add('short_circuit_operators') # compiler configurations (ti.cfg): for key in dir(cfg): if key in ['arch', 'default_fp', 'default_ip']: continue _cast = type(getattr(cfg, key)) if _cast is bool: _cast = None env_comp.add(key, _cast) unexpected_keys = kwargs.keys() if len(unexpected_keys): raise KeyError( f'Unrecognized keyword argument(s) for ti.init: {", ".join(unexpected_keys)}' ) # dispatch configurations that are not in ti.cfg: if not _test_mode: _ti_core.set_core_trigger_gdb_when_crash(spec_cfg.gdb_trigger) impl.get_runtime().short_circuit_operators = \ spec_cfg.short_circuit_operators _logging.set_logging_level(spec_cfg.log_level.lower()) # select arch (backend): env_arch = os.environ.get('TI_ARCH') if env_arch is not None: _logging.info(f'Following TI_ARCH setting up for arch={env_arch}') arch = _ti_core.arch_from_name(env_arch) cfg.arch = adaptive_arch_select(arch, enable_fallback, cfg.use_gles) if cfg.arch == cc: _ti_core.set_tmp_dir(locale_encode(prepare_sandbox())) print(f'[Taichi] Starting on arch={_ti_core.arch_name(cfg.arch)}') # user selected visible device visible_device = os.environ.get("TI_VISIBLE_DEVICE") if visible_device and (cfg.arch == vulkan or _ti_core.GGUI_AVAILABLE): _ti_core.set_vulkan_visible_device(visible_device) if _test_mode: return spec_cfg get_default_kernel_profiler().set_kernel_profiler_mode(cfg.kernel_profiler) # create a new program: impl.get_runtime().create_program() _logging.trace('Materializing runtime...') impl.get_runtime().prog.materialize_runtime() impl._root_fb = _snode.FieldsBuilder() if not os.environ.get("TI_DISABLE_SIGNAL_HANDLERS", False): impl.get_runtime()._register_signal_handlers() # Recover the current working directory (https://github.com/taichi-dev/taichi/issues/4811) os.chdir(current_dir) return None
j = axes(1) k = axes(2) l = axes(3) ij = axes(0, 1) ik = axes(0, 2) il = axes(0, 3) jk = axes(1, 2) jl = axes(1, 3) kl = axes(2, 3) ijk = axes(0, 1, 2) ijl = axes(0, 1, 3) ikl = axes(0, 2, 3) jkl = axes(1, 2, 3) ijkl = axes(0, 1, 2, 3) cfg = impl.default_cfg() x86_64 = _ti_core.x64 """The x64 CPU backend. """ x64 = _ti_core.x64 """The X64 CPU backend. """ arm64 = _ti_core.arm64 """The ARM CPU backend. """ cuda = _ti_core.cuda """The CUDA backend. """ metal = _ti_core.metal """The Apple Metal backend. """