Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

SPIKE: Have ts2mod use suffwdpass and sufrevpass rather than sufrev#768

Open
awf wants to merge 1 commit into
awf/relu3-mapfrom
awf/sufrev
Open

SPIKE: Have ts2mod use suffwdpass and sufrevpass rather than sufrev#768
awf wants to merge 1 commit into
awf/relu3-mapfrom
awf/sufrev

Conversation

@awf

@awf awf commented May 11, 2021

Copy link
Copy Markdown
Contributor

Currently, given knossos function

(def foo ...)

We implement (in ts2ks.*_template) the forward pass by calling foo, and the reverse by calling [sufrev foo]. We should change to [suffwdpass foo] and [sufrevpass foo].

A current blocking issue, which @dcrc2 may have an idea on: pybind11

TypeError: Unable to convert function return value to a Python type! The signature was
        (arg0: dynamic_ksc_cpp.Tensor_1_Float) -> Tuple[dynamic_ksc_cpp.Tensor_1_Float, Tuple[Tuple[], Tuple[], ks::tensor<1ul, ks::tuple<double, ks::tuple<double, ks::tuple<double, ks::tuple<bool, double, ks::tuple<double, ks::tuple<bool, ks::tuple<double, ks::tuple<double, double> > > > > > > > >]]

@dcrc2

dcrc2 commented May 12, 2021

Copy link
Copy Markdown
Contributor

The issue here is the tensor-of-tuples in the return type. We currently only support a small number of tensor types, listed in src/ksc/python/utils.py:

    declare_tensor_1<double>(m, "Tensor_1_Float");
    declare_tensor_2<double>(m, "Tensor_2_Float");
    declare_tensor_2<int>(m, "Tensor_2_Integer");

Clearly we can't just keep adding to this list, especially when we have complex implementation-defined structures like the one here. But there's also a further problem in that our implementation of declare_tensor_N only works for scalar element types anyway.

It's not actually clear to me what we would want this binding to look like. Do we want to copy the result into python objects, or create a python wrapper for a C++ object, or have some combination of the two depending on the element types? Maybe this needs some discussion/investigation.

Once we've decided what should happen I suspect it's possible to get pybind11 to do what we want, perhaps by implementing a type_caster specialization for ks::tensor. Or maybe ts2mod could code-generate the bindings. Either way it sounds like a significant chunk of work so I'd want to pin down the desired interface first.

@awf awf changed the title Have ts2mod use suf{fwd|rev}pass Have ts2mod use suffwdpass and sufrevpass rather than sufrev Jun 7, 2021
@awf awf changed the title Have ts2mod use suffwdpass and sufrevpass rather than sufrev Have ts2mod use suffwdpass and sufrevpass rather than sufrev Jun 7, 2021
@awf awf changed the title Have ts2mod use suffwdpass and sufrevpass rather than sufrev SPIKE: Have ts2mod use suffwdpass and sufrevpass rather than sufrev Jun 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants