TorchWrapper

class TorchWrapper.TorchWrapperOp(in_info, out_info, lua_fw_func, lua_bw_func=None, lua_file=None, name=None)[source]
make_node(*args)[source]

Create a “apply” nodes for the inputs in that order.

infer_shape(node, input_shapes)[source]
perform(node, inputs, output_storage)[source]

Required: Calculate the function on the inputs and put the variables in the output storage. Return None.

Parameters:
node : Apply instance

Contains the symbolic inputs and outputs.

inputs : list

Sequence of inputs (immutable).

output_storage : list

List of mutable 1-element lists (do not change the length of these lists)

Raises:
MethodNotDefined

The subclass does not override this method.

Notes

The output_storage list might contain data. If an element of output_storage is not None, it has to be of the right type, for instance, for a TensorVariable, it has to be a Numpy ndarray, with the right number of dimensions, and the correct dtype. Its shape and stride pattern, can be arbitrary. It not is guaranteed that it was produced by a previous call to impl. It could be allocated by another Op impl is free to reuse it as it sees fit, or to discard it and allocate new memory.

c_header_dirs()[source]

Optional: Return a list of header search paths required by code returned by this class.

Raises:
MethodNotDefined

Subclass does not implement this method.

Examples

return [‘/usr/local/include’, ‘/opt/weirdpath/src/include’]

Provides search paths for headers, in addition to those in any relevant environment variables.

Hint: for unix compilers, these are the things that get ‘-I’ prefixed in the compiler cmdline.

c_lib_dirs()[source]

Optional: Return a list of library search paths required by code returned by this class.

Raises:
MethodNotDefined

Subclass does not implement this method.

Examples

return [‘/usr/local/lib’, ‘/opt/weirdpath/build/libs’].

Provides search paths for libraries, in addition to those in any relevant environment variables (e.g. LD_LIBRARY_PATH).

Hint: for unix compilers, these are the things that get ‘-L’ prefixed in the compiler cmdline.

c_libraries()[source]

Optional: Return a list of libraries required by code returned by this class.

Raises:
MethodNotDefined

Subclass does not implement this method.

Examples

return [‘gsl’, ‘gslcblas’, ‘m’, ‘fftw3’, ‘g2c’].

The compiler will search the directories specified by the environment variable LD_LIBRARY_PATH in addition to any returned by c_lib_dirs.

Hint: for unix compilers, these are the things that get ‘-l’ prefixed in the compiler cmdline.

c_compile_args()[source]

Optional: Return a list of compile args recommended to compile the code returned by other methods in this class.

Raises:
MethodNotDefined

Subclass does not implement this method.

c_support_code()[source]

Optional: Return utility code for use by a Variable or Op to be included at global scope prior to the rest of the code for this class.

QUESTION: How many times will this support code be emitted for a graph with many instances of the same type?

Raises:
MethodNotDefined

Subclass does not implement this method.

c_support_code_struct(node, name)[source]

Optional: return utility code for use by an Op that will be inserted at struct scope, that can be specialized for the support of a particular Apply node.

Parameters:
node : an Apply instance in the graph being compiled
name : str

A unique name to distinguish you variables from those of other nodes.

Raises:
MethodNotDefined

Subclass does not implement this method.

c_init_code_struct(node, name, sub)[source]

Optional: return a code string specific to the apply to be inserted in the struct initialization code.

Parameters:
node : an Apply instance in the graph being compiled
name : str

A unique name to distinguish variables from those of other nodes.

sub

A dictionary of values to substitute in the code. Most notably it contains a ‘fail’ entry that you should place in your code after setting a python exception to indicate an error.

Raises:
MethodNotDefined

The subclass does not override this method.

c_cleanup_code_struct(node, name)[source]

Optional: return a code string specific to the apply to be inserted in the struct cleanup code.

Parameters:
node : an Apply instance in the graph being compiled
name : str

A unique name to distinguish variables from those of other nodes.

Raises:
MethodNotDefined

The subclass does not override this method.

c_code(node, name, inputs, outputs, sub)[source]

Required: return the C implementation of an Op.

Returns C code that does the computation associated to this Op, given names for the inputs and outputs.

Parameters:
node : Apply instance

The node for which we are compiling the current c_code.

The same Op may be used in more than one node.

name : str

A name that is automatically assigned and guaranteed to be unique.

inputs : list of strings

There is a string for each input of the function, and the string is the name of a C variable pointing to that input. The type of the variable depends on the declared type of the input. There is a corresponding python variable that can be accessed by prepending “py_” to the name in the list.

outputs : list of strings

Each string is the name of a C variable where the Op should store its output. The type depends on the declared type of the output. There is a corresponding python variable that can be accessed by prepending “py_” to the name in the list. In some cases the outputs will be preallocated and the value of the variable may be pre-filled. The value for an unallocated output is type-dependent.

sub : dict of strings

Extra symbols defined in CLinker sub symbols (such as ‘fail’). WRITEME

Raises:
MethodNotDefined

The subclass does not override this method.

grad(inputs, output_grads)[source]
connection_pattern(node)[source]
class TorchWrapper.GpuTorchWrapperOp(in_info, out_info, lua_fw_func, lua_bw_func=None, lua_file=None, name=None)[source]
c_support_code()[source]

Optional: Return utility code for use by a Variable or Op to be included at global scope prior to the rest of the code for this class.

QUESTION: How many times will this support code be emitted for a graph with many instances of the same type?

Raises:
MethodNotDefined

Subclass does not implement this method.

c_libraries()[source]

Optional: Return a list of libraries required by code returned by this class.

Raises:
MethodNotDefined

Subclass does not implement this method.

Examples

return [‘gsl’, ‘gslcblas’, ‘m’, ‘fftw3’, ‘g2c’].

The compiler will search the directories specified by the environment variable LD_LIBRARY_PATH in addition to any returned by c_lib_dirs.

Hint: for unix compilers, these are the things that get ‘-l’ prefixed in the compiler cmdline.