You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_vulkan_allocator.py 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. # Copyright 2021 Tencent
  2. # SPDX-License-Identifier: BSD-3-Clause
  3. import pytest
  4. import ncnn
  5. def test_vk_blob_allocator():
  6. if not hasattr(ncnn, "get_gpu_count"):
  7. return
  8. vkdev = ncnn.get_gpu_device(0)
  9. assert vkdev is not None
  10. allocator = ncnn.VkBlobAllocator(vkdev)
  11. assert allocator.buffer_memory_type_index >= 0
  12. assert allocator.image_memory_type_index >= 0
  13. mappable = allocator.mappable
  14. allocator.mappable = not mappable
  15. assert allocator.mappable == (not mappable)
  16. coherent = allocator.coherent
  17. allocator.coherent = not coherent
  18. assert allocator.coherent == (not coherent)
  19. bufmem = allocator.fastMalloc(10 * 1024)
  20. assert bufmem is not None
  21. allocator.fastFree(bufmem)
  22. imgmem = allocator.fastMalloc(4, 4, 3, 4, 1)
  23. assert imgmem is not None
  24. allocator.fastFree(imgmem)
  25. def test_vk_weight_allocator():
  26. if not hasattr(ncnn, "get_gpu_count"):
  27. return
  28. vkdev = ncnn.get_gpu_device(0)
  29. assert vkdev is not None
  30. allocator = ncnn.VkWeightAllocator(vkdev)
  31. assert allocator.buffer_memory_type_index >= 0
  32. assert allocator.image_memory_type_index >= 0
  33. mappable = allocator.mappable
  34. allocator.mappable = not mappable
  35. assert allocator.mappable == (not mappable)
  36. coherent = allocator.coherent
  37. allocator.coherent = not coherent
  38. assert allocator.coherent == (not coherent)
  39. bufmem = allocator.fastMalloc(10 * 1024)
  40. assert bufmem is not None
  41. allocator.fastFree(bufmem)
  42. imgmem = allocator.fastMalloc(4, 4, 3, 4, 1)
  43. assert imgmem is not None
  44. allocator.fastFree(imgmem)
  45. def test_vk_staging_allocator():
  46. if not hasattr(ncnn, "get_gpu_count"):
  47. return
  48. vkdev = ncnn.get_gpu_device(0)
  49. assert vkdev is not None
  50. allocator = ncnn.VkStagingAllocator(vkdev)
  51. assert allocator.buffer_memory_type_index >= 0
  52. assert allocator.image_memory_type_index >= 0
  53. mappable = allocator.mappable
  54. allocator.mappable = not mappable
  55. assert allocator.mappable == (not mappable)
  56. coherent = allocator.coherent
  57. allocator.coherent = not coherent
  58. assert allocator.coherent == (not coherent)
  59. bufmem = allocator.fastMalloc(10 * 1024)
  60. assert bufmem is not None
  61. allocator.fastFree(bufmem)
  62. imgmem = allocator.fastMalloc(4, 4, 3, 4, 1)
  63. assert imgmem is not None
  64. allocator.fastFree(imgmem)
  65. def test_vk_weight_staging_allocator():
  66. if not hasattr(ncnn, "get_gpu_count"):
  67. return
  68. vkdev = ncnn.get_gpu_device(0)
  69. assert vkdev is not None
  70. allocator = ncnn.VkWeightStagingAllocator(vkdev)
  71. assert allocator.buffer_memory_type_index >= 0
  72. assert allocator.image_memory_type_index >= 0
  73. mappable = allocator.mappable
  74. allocator.mappable = not mappable
  75. assert allocator.mappable == (not mappable)
  76. coherent = allocator.coherent
  77. allocator.coherent = not coherent
  78. assert allocator.coherent == (not coherent)
  79. bufmem = allocator.fastMalloc(10 * 1024)
  80. assert bufmem is not None
  81. allocator.fastFree(bufmem)
  82. imgmem = allocator.fastMalloc(4, 4, 3, 4, 1)
  83. assert imgmem is None