@@ -362,61 +362,14 @@ void LevelZeroCompilerInDriver<TableExtension>::release(std::shared_ptr<const Ne
362
362
_logger.debug (" release completed" );
363
363
}
364
364
365
- /*
366
- FAILED: src/plugins/intel_npu/src/compiler/CMakeFiles/openvino_npu_driver_compiler_adapter.dir/src/zero_compiler_in_driver.cpp.obj
367
- C:\Work\mirceaau\ccache-4.8.2-windows-x86_64\ccache C:\PROGRA~2\MICROS~2\2019\BUILDT~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe /nologo /TP -DIN_OV_COMPONENT -DNPU_PLUGIN_DEVELOPER_BUILD -DOV_BUILD_POSTFIX=\"d\" -DOV_NATIVE_PARENT_PROJECT_ROOT_DIR=\"openvino\" -DOV_THREAD=OV_THREAD_TBB -DSNIPPETS_DEBUG_CAPS -DTBB_USE_DEBUG -D__TBB_NO_IMPLICIT_LINKAGE=1 -IC:\Work\mirceaau\openvino\src\plugins\intel_npu\src\compiler\include -IC:\Work\mirceaau\openvino\src\plugins\intel_npu\src\al\include -IC:\Work\mirceaau\openvino\src\plugins\intel_npu\src\utils\include -IC:\Work\mirceaau\openvino\src\inference\dev_api -IC:\Work\mirceaau\openvino\src\core\include -IC:\Work\mirceaau\openvino\src\frontends\common\include -IC:\Work\mirceaau\openvino\src\inference\include -IC:\Work\mirceaau\openvino\src\core\dev_api -IC:\Work\mirceaau\openvino\src\common\transformations\include -IC:\Work\mirceaau\openvino\src\common\low_precision_transformations\include -IC:\Work\mirceaau\openvino\src\common\itt\include -IC:\Work\mirceaau\openvino\src\common\util\include -IC:\Work\mirceaau\openvino\thirdparty\pugixml\src -IC:\Work\mirceaau\openvino\thirdparty\level_zero\level-zero\include -IC:\Work\mirceaau\openvino\src\plugins\intel_npu\thirdparty\level-zero-ext -IC:\Work\mirceaau\openvino\src\plugins\intel_npu\src\backend\include -external:IC:\Work\mirceaau\openvino\temp\tbb\include -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc /D_CRT_SECURE_NO_WARNINGS /D_SCL_SECURE_NO_WARNINGS /EHsc /Gy /W3 /bigobj /MP /wd4251 /wd4275 /Z7 /Ob0 /Od /RTC1 -std:c++17 -MDd /d1trimfile:C:\Work\mirceaau\openvino\ /d1trimfile:C:/Work/mirceaau/openvino/ -WX /showIncludes /Fosrc\plugins\intel_npu\src\compiler\CMakeFiles\openvino_npu_driver_compiler_adapter.dir\src\zero_compiler_in_driver.cpp.obj /FdC:\Work\mirceaau\openvino\bin\intel64\Debug\ /FS -c C:\Work\mirceaau\openvino\src\plugins\intel_npu\src\compiler\src\zero_compiler_in_driver.cpp
368
- C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC\14.29.30133\include\vector(701): error C2440: 'static_cast': cannot convert from 'intel_npu::driverCompilerAdapter::PreAllocatedAllocator<uint8_t>' to 'intel_npu::driverCompilerAdapter::PreAllocatedAllocator<U>'
369
- with
370
- [
371
- U=std::_Container_proxy
372
- ]
373
- */
374
- template <typename T>
375
- class PreAllocatedAllocator
376
- {
377
- public:
378
- using value_type = T;
379
-
380
- // Constructor accepts a pointer to the pre-allocated memory block
381
- PreAllocatedAllocator (T* pre_allocated, std::size_t max_size)
382
- : memory(pre_allocated), max_size(max_size), offset(0 ) {}
383
-
384
- // Allocator constructor and copy constructor
385
- PreAllocatedAllocator (const PreAllocatedAllocator<T>& other)
386
- : memory(other.memory), max_size(other.max_size), offset(other.offset) {}
387
-
388
- T* allocate (std::size_t n) {
389
- if (offset + n > max_size) {
390
- throw std::bad_alloc ();
391
- }
392
- T* ptr = memory + offset;
393
- offset += n;
394
- return ptr;
395
- }
396
-
397
- void deallocate (T*, std::size_t ) {
398
- // Deallocate does nothing since memory is externally managed
399
- }
400
-
401
- template <typename U>
402
- struct rebind {
403
- using other = PreAllocatedAllocator<U>;
404
- };
405
-
406
- private:
407
- T* memory;
408
- std::size_t max_size;
409
- std::size_t offset;
410
-
411
- };
412
-
413
365
template <typename TableExtension>
414
366
template <typename T, std::enable_if_t <UseCopyForNativeBinary(T), bool >>
415
- void LevelZeroCompilerInDriver<TableExtension>::getNativeBinary(ze_graph_dditable_ext_curr_t & graphDdiTableExt,
416
- ze_graph_handle_t graphHandle,
417
- std::vector<uint8_t >& blob) const {
418
- // Get blob size first
419
- size_t blobSize = -1 ;
367
+ std::vector<uint8_t , Mallocator<uint8_t >> LevelZeroCompilerInDriver<TableExtension>::getNativeBinary(ze_graph_dditable_ext_curr_t & graphDdiTableExt,
368
+ ze_graph_handle_t graphHandle) const {
369
+ Mallocator<uint8_t > mal;
370
+ std::vector<uint8_t , Mallocator<uint8_t >> blob (mal);
371
+ size_t blobSize;
372
+
420
373
auto result = _graphDdiTableExt.pfnGetNativeBinary (graphHandle, &blobSize, nullptr );
421
374
blob.resize (blobSize);
422
375
@@ -442,71 +395,48 @@ void LevelZeroCompilerInDriver<TableExtension>::getNativeBinary(ze_graph_dditabl
442
395
uint64_t (result),
443
396
" . " ,
444
397
getLatestBuildError ());
398
+ return std::move (blob);
445
399
}
446
400
447
- // Allocators of the same type are always equal
448
- template <typename T1, typename T2>
449
- bool operator ==(const PreAllocatedAllocator<T1>&, const PreAllocatedAllocator<T2>&) { return true ; }
450
-
451
- template <typename T1, typename T2>
452
- bool operator !=(const PreAllocatedAllocator<T1>&, const PreAllocatedAllocator<T2>&) { return false ; }
453
-
454
401
template <typename TableExtension>
455
402
template <typename T, std::enable_if_t <!UseCopyForNativeBinary(T), bool >>
456
- void LevelZeroCompilerInDriver<TableExtension>::getNativeBinary(ze_graph_dditable_ext_curr_t & graphDdiTableExt,
457
- ze_graph_handle_t graphHandle,
458
- std::vector<uint8_t >& blob) const {
459
- // Get blob ptr and size
460
- uint8_t * blobPtr = nullptr ;
461
- size_t blobSize = -1 ;
462
-
463
- auto result = _graphDdiTableExt.pfnGetNativeBinary2 (graphHandle, &blobSize, &blobPtr);
464
-
465
- OPENVINO_ASSERT (result == ZE_RESULT_SUCCESS,
466
- " Failed to compile network. L0 pfnGetNativeBinary get blob size" ,
467
- " result: " ,
468
- ze_result_to_string (result),
469
- " , code 0x" ,
470
- std::hex,
471
- uint64_t (result),
472
- " . " ,
473
- getLatestBuildError ());
474
-
475
- // std::initializer_list<uint8_t> initializerListTmp(blobPtr, blobPtr + blobSize);
403
+ std::vector<uint8_t , Mallocator<uint8_t >> LevelZeroCompilerInDriver<TableExtension>::getNativeBinary(ze_graph_dditable_ext_curr_t & graphDdiTableExt,
404
+ ze_graph_handle_t graphHandle) const {
476
405
477
- // std::vector<uint8_t> blobTmp = {initializerListTmp.begin(), initializerListTmp.end()};
406
+ uint8_t * blobPtr;
407
+ size_t blobSize;
478
408
479
- // blob.swap(blobTmp);
409
+ // Get blob ptr and size
410
+ auto result = _graphDdiTableExt.pfnGetNativeBinary2 (graphHandle, &blobSize, &blobPtr);
480
411
481
- /* placement_memory_allocator<uint8_t> pl(blobPtr);
482
- std::vector<uint8_t, placement_memory_allocator<uint8_t>> tmpBlob(pl);
483
- tmpBlob.reserve(blobSize);
484
- tmpBlob.push_back(0); */
485
- // blob.swap(tmpBlob);
486
-
487
- PreAllocatedAllocator allocator (blobPtr, blobSize);
488
-
489
- std::vector< uint8_t , PreAllocatedAllocator< uint8_t >> tmpBlob (allocator );
412
+ OPENVINO_ASSERT (result == ZE_RESULT_SUCCESS,
413
+ " Failed to compile network. L0 pfnGetNativeBinary get blob size " ,
414
+ " result: " ,
415
+ ze_result_to_string (result),
416
+ " , code 0x " ,
417
+ std::hex,
418
+ uint64_t (result),
419
+ " . " ,
420
+ getLatestBuildError () );
490
421
491
- std::cout << tmpBlob[0 ] << " " << tmpBlob[1 ] << std::endl;
422
+ Mallocator<uint8_t > mal (blobPtr, blobSize);
423
+ return std::vector<uint8_t , Mallocator<uint8_t >>(mal);
492
424
}
493
425
494
426
template <typename TableExtension>
495
- std::vector<uint8_t > LevelZeroCompilerInDriver<TableExtension>::getCompiledNetwork(
427
+ std::vector<uint8_t , Mallocator< uint8_t > > LevelZeroCompilerInDriver<TableExtension>::getCompiledNetwork(
496
428
const NetworkDescription& networkDescription) {
497
429
if (networkDescription.metadata .graphHandle != nullptr && networkDescription.compiledNetwork .size () == 0 ) {
498
430
_logger.info (" LevelZeroCompilerInDriver getCompiledNetwork get blob from graphHandle" );
499
431
ze_graph_handle_t graphHandle = static_cast <ze_graph_handle_t >(networkDescription.metadata .graphHandle );
500
432
501
- std::vector<uint8_t > blob;
502
-
503
- getNativeBinary (_graphDdiTableExt, graphHandle, blob);
504
-
505
433
_logger.info (" LevelZeroCompilerInDriver getCompiledNetwork returning blob" );
506
- return std::move (blob );
434
+ return getNativeBinary (_graphDdiTableExt, graphHandle );
507
435
}
508
436
_logger.info (" return the blob from network description" );
509
- return networkDescription.compiledNetwork ;
437
+
438
+ Mallocator<uint8_t > mal (networkDescription.compiledNetwork .data (), networkDescription.compiledNetwork .size ());
439
+ return std::vector<uint8_t , Mallocator<uint8_t >>(mal);
510
440
}
511
441
512
442
template <typename TableExtension>
0 commit comments