Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support scalar array Input/Output #323

Open
iitaku opened this issue Aug 30, 2024 · 3 comments
Open

Support scalar array Input/Output #323

iitaku opened this issue Aug 30, 2024 · 3 comments

Comments

@iitaku
Copy link
Collaborator

iitaku commented Aug 30, 2024

No description provided.

@xinyuli1204
Copy link
Contributor

xinyuli1204 commented Oct 24, 2024

C++ USAGE

std::array

option1

........
        std::array<int, 4> offsets = {1, 2, 3, 4};
        auto n = b.add("test_scalar_array")(in, &offsets).set_params(Param("input_offsets.size", 4));
        n["output"].bind(outs);
        b.run();

option2

........
        Port offsets_p{"input_offsets", Halide::type_of<int32_t>(), 0};
        std::array<int, 4> offsets = {1, 2, 3, 4};
        auto n = b.add("test_scalar_array")(in, offsets_p).set_params(Param("input_offsets.size", 4));
        offsets_p.bind(&offsets)
        n["output"].bind(outs);
        b.run();

@xinyuli1204
Copy link
Contributor

xinyuli1204 commented Oct 24, 2024

Python USAGE

test case

def test_all():
    # Test new Buffer API

    input_port = Port(name='input', type=Type.from_dtype(np.dtype(np.int32)), dim=2)

    offsets_port = Port(name='input_offsets', type=Type.from_dtype(np.dtype(np.int32)), dim=0)
    builder = Builder()
    builder.set_target(target='host')
    builder.with_bb_module(path='ion-bb-test')

    node = (builder.add('test_scalar_array').set_iports([input_port,offsets_port])
            .set_params(params=[ Param(key='input_offsets.size', val='4') ]))

    idata = np.full((4, 4), fill_value=42, dtype=np.int32)
    ibuf = Buffer(array=idata)
    offsets_ = [1, 2, 3, 4]


    odata = []
    obufs = []
    for i in range(4):
        odata.append(np.full((4, 4), fill_value=0, dtype=np.int32))
        obufs.append(Buffer(array=odata[i]))

    input_port.bind(ibuf)
    offsets_port.bind(offsets_)
    output_port = node.get_port(name='output')
    output_port.bind(obufs)

    # First run
    builder.run()

    for i in range(4):
        print (odata[i][0][0])

    print("passed")

test_all()


offsets_port = Port(name='input_offsets', type=Type(code_=TypeCode.Int, bits_=32, lanes_=1), dim=0)
...................
offsets_ = [1, 2, 3, 4]
offsets_port.bind(offsets_)

@xinyuli1204
Copy link
Contributor

xinyuli1204 commented Oct 24, 2024

pr here #335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants