Closed CrytoGen closed 1 year ago
Hi, thanks for spotting this, I'll try to get it to work with CUDA when i have time and will upload a working CUDA example shortly ( I dont have an NVIDIA GPU at the moment ) , however I just uploaded a Delphi GPU example YOLO_V7 based on DirectML re "git clone" the ripo, star the library if you find it useful it helps a lot .
Having a quick look at your code snippet you don't have to cast from ANSI to UTF8 (RowByteString) this can bring some unnecessary overhead and may corrupt the parameters, no need to clone "DefaultSessionOptions" try the following and see if it works, (test by keeping only "device_id" parameter first) :
var
cpok,cpov : array of PORTChar;
cpo : POrtCUDAProviderOptionsV2;
// .. your other variables
begin
//.... your code
setLength(cpok, 6);
setLength(cpov, 6);
cpok[0]:= 'device_id';
cpok[1]:='gpu_mem_limit';
cpok[2]:='arena_extend_strategy';
cpok[3]:='cudnn_conv_algo_search';
cpok[4]:='do_copy_in_default_stream';
cpok[5]:='cudnn_conv_use_max_workspacecudnn_conv1d_pad_to_nc1d';
cpov[0]:='0';
cpov[1]:='2147483648';
cpov[2]:='kSameAsRequested';
cpov[3]:='DEFAULT';
cpov[4]:='1';
cpov[5]:='1';
ThrowOnError(getapi().CreateCUDAProviderOptions(@cpo));
ThrowOnError(getapi().UpdateCUDAProviderOptions(@cpo , @cpok[0] ,@cpov[0] , length(cpok)));
ThrowOnError(getapi().SessionOptionsAppendExecutionProvider_CUDA_V2(DefaultSessionOptions.p_ , @cpo));
// use simple inference form
Session := TORTSession.create( modelPath );
// etc..
let me know how it works.
Cheers H
Hi. Tried you variant with small corrections. cpok,cpot as array of PAnsiChar instead POrtChar (compiler don't allow to assign string constant to POrtChar). : procedure one; var cpok,cpov : array of PAnsiChar; cpo : POrtCUDAProviderOptionsV2; begin setLength(cpok, 1); setLength(cpov, 1);
cpok[0]:='device_id'; cpov[0]:='0';
WriteLn('1'); ThrowOnError(getapi().CreateCUDAProviderOptions(@cpo)); WriteLn('2'); ThrowOnError(getapi().UpdateCUDAProviderOptions(@cpo , @cpok[0] ,@cpov[0] , length(cpok))); WriteLn('3'); ThrowOnError(getapi().SessionOptionsAppendExecutionProvider_CUDAV2(DefaultSessionOptions.p , @cpo)); WriteLn('4'); // use simple inference form Session := TORTSession.create('best.onnx'); WriteLn('5'); end;
Next problem:
I will try directml little bit later. Example source look like corrupted. Unit1.fmx present without Unit1.pas. I'm sorry. I don't use git and just download source. And don't know what is "star the library"...
Sorry for splitting. I tried include DirectML from your example. And it works ) With DirectML: On CPU: Many thanks. For me it's enough. But if you want to try something with CUDA - i can keep this thread for dialogue.
Trying to create session with CUDA provider but get next error during debuggin by windbg "Exception OrtException in module Project1.exe at 000000000013F9D1. Code [1]: D:\a_work\1\s\include\onnxruntime\core/framework/provider_options_utils.h:41 onnxruntime::EnumToName [ONNXRuntimeError] : 1 : FAIL : provider_options_utils.h:33 onnxruntime::EnumToName Failed to map enum value to name: 7297107"
It work fine on CPU. I think UpdateCUDAProviderOptions work correct, because when i add keys with incorrect names (f.e. dev_id) - it show exception.
Copy of main part of source:
writeLn('Providers : ['+ Join(GetAvailableProviders())+']'); writeln(ansistring(Global.GetVersionString)); GetApi().CreateCUDAProviderOptions(@cpo); opts:=DefaultSessionOptions.Clone();
key:=[UTF8Encode('device_id'), UTF8Encode('gpu_mem_limit'), UTF8Encode('arena_extend_strategy'), UTF8Encode('cudnn_conv_algo_search'), UTF8Encode('do_copy_in_default_stream') // UTF8Encode('cudnn_conv_use_max_workspacecudnn_conv1d_pad_to_nc1d') ]; val:=[UTF8Encode('0'), UTF8Encode('2147483648'), UTF8Encode('kSameAsRequested'), UTF8Encode('DEFAULT'), UTF8Encode('1') // UTF8Encode('1') ]; WriteLn('1'); ThrowOnError(GetApi.UpdateCUDAProviderOptions(cpo,PPOrtChar(key),PPOrtChar(val),5));
WriteLn('2'); opts:=opts.AppendExecutionProvider_CUDA_V2(cpo^); WriteLn('3'); _path:='best.onnx'; session := TORTSession.Create(DefaultEnv,PORTCHAR_T(_path),opts); WriteLn('4');
I use Delphi 11.2
full source
``` program Project1; {$APPTYPE CONSOLE} {$R *.res} {$h+} uses Winapi.Windows, System.SysUtils, System.Classes, onnxruntime_pas_api, onnxruntime, System.Types, Vcl.Graphics, vcl.Imaging.pngimage, System.Diagnostics, System.Math; var session : TORTSession; opts : TORTSessionOptions; cpo : POrtCUDAProviderOptionsV2; inTensor : TORTTensorTrying in visual c++ - it's work ok.
c++
``` #include