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.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. # Tencent is pleased to support the open source community by making ncnn available.
  2. #
  3. # Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.
  4. #
  5. # Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  6. # in compliance with the License. You may obtain a copy of the License at
  7. #
  8. # https://opensource.org/licenses/BSD-3-Clause
  9. #
  10. # Unless required by applicable law or agreed to in writing, software distributed
  11. # under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  12. # CONDITIONS OF ANY KIND, either express or implied. See the License for the
  13. # specific language governing permissions and limitations under the License.
  14. import pytest
  15. import ncnn
  16. def test_vk_blob_allocator():
  17. if not hasattr(ncnn, "get_gpu_count"):
  18. return
  19. vkdev = ncnn.get_gpu_device(0)
  20. assert vkdev is not None
  21. allocator = ncnn.VkBlobAllocator(vkdev)
  22. assert allocator.buffer_memory_type_index >= 0
  23. assert allocator.image_memory_type_index >= 0
  24. mappable = allocator.mappable
  25. allocator.mappable = not mappable
  26. assert allocator.mappable == (not mappable)
  27. coherent = allocator.coherent
  28. allocator.coherent = not coherent
  29. assert allocator.coherent == (not coherent)
  30. bufmem = allocator.fastMalloc(10 * 1024)
  31. assert bufmem is not None
  32. allocator.fastFree(bufmem)
  33. imgmem = allocator.fastMalloc(4, 4, 3, 4, 1)
  34. assert imgmem is not None
  35. allocator.fastFree(imgmem)
  36. def test_vk_weight_allocator():
  37. if not hasattr(ncnn, "get_gpu_count"):
  38. return
  39. vkdev = ncnn.get_gpu_device(0)
  40. assert vkdev is not None
  41. allocator = ncnn.VkWeightAllocator(vkdev)
  42. assert allocator.buffer_memory_type_index >= 0
  43. assert allocator.image_memory_type_index >= 0
  44. mappable = allocator.mappable
  45. allocator.mappable = not mappable
  46. assert allocator.mappable == (not mappable)
  47. coherent = allocator.coherent
  48. allocator.coherent = not coherent
  49. assert allocator.coherent == (not coherent)
  50. bufmem = allocator.fastMalloc(10 * 1024)
  51. assert bufmem is not None
  52. allocator.fastFree(bufmem)
  53. imgmem = allocator.fastMalloc(4, 4, 3, 4, 1)
  54. assert imgmem is not None
  55. allocator.fastFree(imgmem)
  56. def test_vk_staging_allocator():
  57. if not hasattr(ncnn, "get_gpu_count"):
  58. return
  59. vkdev = ncnn.get_gpu_device(0)
  60. assert vkdev is not None
  61. allocator = ncnn.VkStagingAllocator(vkdev)
  62. assert allocator.buffer_memory_type_index >= 0
  63. assert allocator.image_memory_type_index >= 0
  64. mappable = allocator.mappable
  65. allocator.mappable = not mappable
  66. assert allocator.mappable == (not mappable)
  67. coherent = allocator.coherent
  68. allocator.coherent = not coherent
  69. assert allocator.coherent == (not coherent)
  70. bufmem = allocator.fastMalloc(10 * 1024)
  71. assert bufmem is not None
  72. allocator.fastFree(bufmem)
  73. imgmem = allocator.fastMalloc(4, 4, 3, 4, 1)
  74. assert imgmem is not None
  75. allocator.fastFree(imgmem)
  76. def test_vk_weight_staging_allocator():
  77. if not hasattr(ncnn, "get_gpu_count"):
  78. return
  79. vkdev = ncnn.get_gpu_device(0)
  80. assert vkdev is not None
  81. allocator = ncnn.VkWeightStagingAllocator(vkdev)
  82. assert allocator.buffer_memory_type_index >= 0
  83. assert allocator.image_memory_type_index >= 0
  84. mappable = allocator.mappable
  85. allocator.mappable = not mappable
  86. assert allocator.mappable == (not mappable)
  87. coherent = allocator.coherent
  88. allocator.coherent = not coherent
  89. assert allocator.coherent == (not coherent)
  90. bufmem = allocator.fastMalloc(10 * 1024)
  91. assert bufmem is not None
  92. allocator.fastFree(bufmem)
  93. imgmem = allocator.fastMalloc(4, 4, 3, 4, 1)
  94. assert imgmem is None