/* * Copyright (c) Advanced Micro Devices, Inc., or its affiliates. * * SPDX-License-Identifier: MIT */ /** * @addtogroup hipMemMapArrayAsync hipMemMapArrayAsync * @{ * @ingroup VirtualMemoryManagementTest * `hipError_t hipMemMapArrayAsync(hipArrayMapInfo *mapInfoList, * unsigned int count, * hipStream_t stream)` - * Maps or unmaps subregions of sparse HIP arrays and sparse HIP mipmapped arrays. */ #include #include #include #include "hip_vmm_common.hh" /** * Test Description * ------------------------ * - Basic sanity test. * ------------------------ * - unit/virtualMemoryManagement/hipMemMapArrayAsync.cc * Test requirements * ------------------------ * - HIP_VERSION >= 6.1 */ HIP_TEST_CASE(Unit_hipMemMapArrayAsync_Positive_Basic) { HIP_CHECK(hipFree(0)); hipDevice_t device; HIP_CHECK(hipDeviceGet(&device, 0)); checkVMMSupported(device); CHECK_IMAGE_SUPPORT; hipmipmappedArray array; HIP_ARRAY3D_DESCRIPTOR desc = {}; using vec_info = vector_info; desc.Format = vec_info::format; desc.NumChannels = vec_info::size; desc.Width = 1; desc.Height = 1; desc.Flags = CUDA_ARRAY3D_SPARSE; unsigned int levels = 2; HIP_CHECK(hipMipmappedArrayCreate(&array, &desc, levels)); hipMemAllocationProp prop = {}; prop.type = hipMemAllocationTypePinned; prop.location.type = hipMemLocationTypeDevice; prop.location.id = device; prop.allocFlags.usage = CU_MEM_CREATE_USAGE_TILE_POOL; size_t granularity; HIP_CHECK( hipMemGetAllocationGranularity(&granularity, &prop, hipMemAllocationGranularityRecommended)); hipMemGenericAllocationHandle_t handle; HIP_CHECK(hipMemCreate(&handle, granularity, &prop, 0)); hipArrayMapInfo map_info_list = {}; map_info_list.resourceType = HIP_RESOURCE_TYPE_MIPMAPPED_ARRAY; map_info_list.resource.mipmap = array; map_info_list.subresourceType = hipArraySparseSubresourceTypeSparseLevel; map_info_list.subresource.sparseLevel.extentWidth = 1; map_info_list.subresource.sparseLevel.extentHeight = 1; map_info_list.subresource.sparseLevel.extentDepth = 1; map_info_list.memOperationType = hipMemOperationTypeMap; map_info_list.memHandleType = hipMemHandleTypeGeneric; map_info_list.memHandle.memHandle = handle; map_info_list.deviceBitMask = 0x1; StreamGuard stream(Streams::created); HIP_CHECK(hipMemMapArrayAsync(&map_info_list, 1, stream.stream())); HIP_CHECK(hipStreamSynchronize(stream.stream())); map_info_list.memOperationType = hipMemOperationTypeUnmap; map_info_list.memHandle.memHandle = NULL; HIP_CHECK(hipMemMapArrayAsync(&map_info_list, 1, stream.stream())); HIP_CHECK(hipStreamSynchronize(stream.stream())); HIP_CHECK(hipMemRelease(handle)); HIP_CHECK(hipMipmappedArrayDestroy(array)); } /** * End doxygen group VirtualMemoryManagementTest. * @} */