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

Force copy to device #635

Open
dionhaefner opened this issue Nov 6, 2019 · 1 comment
Open

Force copy to device #635

dionhaefner opened this issue Nov 6, 2019 · 1 comment

Comments

@dionhaefner
Copy link
Collaborator

Is there a way to force Bohrium to copy an array to GPU?

I want to benchmark Bohrium against some other libraries, so I do something like this:

def prepare_inputs(np_inputs):
    bh_inputs = [bh.array(k) for k in np_inputs]
    bh.flush()
    return bh_inputs


inputs = prepare_inputs(np_inputs)
with Timer():
    run_benchmark(inputs)
    bh.flush()

But on GPU, the data is not copied during prepare_inputs, only when the data is accessed during run_benchmark. The timings I get for Bohrium are thus higher than for other libraries, which copy the data right away.

I found that the following works:

def prepare_inputs(np_inputs):
    bh_inputs = [bh.array(k) for k in np_inputs]
    for k in bh_inputs:
         tmp = k * 1
         bh.flush()
    return bh_inputs

But it feels a bit stupid.

@madsbk
Copy link
Contributor

madsbk commented Nov 7, 2019

I guess you can call bohrium._bh.get_data_pointer(bh_ary, copy2host=False, allocate=True), which will return a point (as a Python integter) to the GPU memory. If the data is on main memory, it will be copied to the GPU before returning.

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