Executable¶
- class nvtripy.Executable(executable, arg_names, output_devices)[source]¶
Bases:
object
Represents a compiled executable generated by the compiler.
See also
- load() Executable [source]¶
Loads a executable from the provided path.
- Parameters:
path (str) – The path from which to load the exectuable.
- Returns:
The executable object loaded from the file.
- Return type:
Example: Save and load executable
1import os 2 3 4def add(a, b): 5 return a + b 6 7 8compiled_add = tp.compile( 9 add, 10 args=[ 11 tp.InputInfo(shape=((1, 2, 3),), dtype=tp.float32), 12 tp.InputInfo(shape=((1, 2, 3),), dtype=tp.float32), 13 ], 14) 15 16 17# Assuming `out_dir` is the directory containing the executable: 18executable_file = os.path.join(out_dir, "executable.json") 19loaded_executable = tp.Executable.load(executable_file)
>>> loaded_executable Executable(a: nvtripy.Tensor, b: nvtripy.Tensor) -> nvtripy.Tensor
[I] /tmp/tmpsymvtzt7 does not exist, creating now.
- __call__(*args: Tensor, **kwargs: Tensor) Tensor | Sequence[Tensor] [source]¶
Invokes the executable with the specified tensor arguments.
- Parameters:
- Returns:
The output
Tensor
s of the compiled function.- Return type:
Example
1def add(a, b): 2 return a + b 3 4 5compiled_add = tp.compile( 6 add, 7 args=[ 8 tp.InputInfo((1,), dtype=tp.float32), 9 tp.InputInfo((1,), dtype=tp.float32), 10 ], 11) 12 13a = tp.ones((1,), dtype=tp.float32) 14b = tp.ones((1,), dtype=tp.float32) 15 16out = compiled_add(a, b)
>>> a tensor([1.0000], dtype=float32, loc=gpu:0, shape=(1,)) >>> b tensor([1.0000], dtype=float32, loc=gpu:0, shape=(1,)) >>> out tensor([2.0000], dtype=float32, loc=gpu:0, shape=(1,))
- save(path: str) None [source]¶
Saves this executable to the provided path.
- Parameters:
path (str) – The path at which to save the executable.
- Return type:
None
Example: Save executable
1import os 2 3 4def add(a, b): 5 return a + b 6 7 8compiled_add = tp.compile( 9 add, 10 args=[ 11 tp.InputInfo(shape=((1, 2, 3),), dtype=tp.float32), 12 tp.InputInfo(shape=((1, 2, 3),), dtype=tp.float32), 13 ], 14) 15 16# Assuming `out_dir` is the desired output directory: 17executable_file = os.path.join(out_dir, "executable.json") 18compiled_add.save(executable_file)
[I] /tmp/tmpi26binzu does not exist, creating now.