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

Here the code for GPU but it seems, doesn't run fast #21

Open
Apisteftos opened this issue Sep 2, 2023 · 0 comments
Open

Here the code for GPU but it seems, doesn't run fast #21

Apisteftos opened this issue Sep 2, 2023 · 0 comments

Comments

@Apisteftos
Copy link

I inferenced the model with both CPU and GPU, but it seems the only difference between the is just 4 ms. With CPU reaches almost 26ms and with CUDA 21 ms. I don't unterstand why is running so bad. I suppose the export in onnx form was not so successful.

def inference(self, input_tensor):
        
        input_name = self.session.get_inputs()[0].name
        output_name = self.session.get_outputs()[0].name
        
        iobinding = self.session.io_binding()
        ortvalue = onnxruntime.OrtValue.ortvalue_from_numpy(input_tensor, 'cuda', 0)
        iobinding.bind_input(input_name, 'cuda', 0, np.float32, ortvalue.shape(), ortvalue.data_ptr())
        iobinding.bind_output(output_name, 'cuda', 0)
        
        
        start = time.perf_counter()
        #outputs = self.session.run(self.output_names, {self.input_names[0]: input_tensor})
        self.session.run_with_iobinding(iobinding)
        print(f"Inference time: {(time.perf_counter() - start)*1000:.2f} ms")
        
        
        outputs = iobinding.copy_outputs_to_cpu()

        
        return outputs

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

1 participant