CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
123 lines
4.0 KiB
C++
123 lines
4.0 KiB
C++
/* ************************************************************************
|
|
* Copyright (C) 2020-2024 Advanced Micro Devices, Inc. All rights reserved.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop-
|
|
* ies of the Software, and to permit persons to whom the Software is furnished
|
|
* to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM-
|
|
* PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE-
|
|
* CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* ************************************************************************ */
|
|
|
|
#include "client_utility.hpp"
|
|
#include "rocblas_device_malloc.hpp"
|
|
|
|
int main()
|
|
{
|
|
rocblas_handle handle;
|
|
CHECK_ROCBLAS_ERROR(rocblas_create_handle(&handle));
|
|
|
|
// Free all memory in the handle
|
|
CHECK_ROCBLAS_ERROR(rocblas_set_device_memory_size(handle, 0));
|
|
|
|
size_t sizes[] = {512, 1025, 10 * 1024 * 1024};
|
|
|
|
if(rocblas_is_device_memory_size_query(handle))
|
|
{
|
|
rocblas_cerr << "rocblas_is_device_memory_size_query() incorrectly returned true"
|
|
<< std::endl;
|
|
return 1;
|
|
}
|
|
|
|
CHECK_ROCBLAS_ERROR(rocblas_start_device_memory_size_query(handle));
|
|
|
|
if(!rocblas_is_device_memory_size_query(handle))
|
|
{
|
|
rocblas_cerr << "rocblas_is_device_memory_size_query() incorrectly returned false"
|
|
<< std::endl;
|
|
return 1;
|
|
}
|
|
|
|
CHECK_ALLOC_QUERY(rocblas_set_optimal_device_memory_size(handle, sizes[0], sizes[1], sizes[2]));
|
|
|
|
size_t max;
|
|
CHECK_ROCBLAS_ERROR(rocblas_stop_device_memory_size_query(handle, &max));
|
|
|
|
CHECK_ROCBLAS_ERROR(rocblas_set_device_memory_size(handle, max));
|
|
|
|
for(size_t size : sizes)
|
|
{
|
|
try
|
|
{
|
|
rocblas_device_malloc mem(handle, size);
|
|
|
|
if(!mem)
|
|
{
|
|
rocblas_cerr << "rocblas_device_malloc failed" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
void* ptr = static_cast<void*>(mem);
|
|
|
|
hipMemset(ptr, 0, size);
|
|
|
|
rocblas_device_malloc_base& ref = mem;
|
|
}
|
|
catch(...)
|
|
{
|
|
rocblas_cerr << "exception thrown for malloc size " << size << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
rocblas_device_malloc mem2 = rocblas_device_malloc(handle, size);
|
|
rocblas_device_malloc_base& ref2 = mem2;
|
|
rocblas_device_malloc mem3 = std::move(mem2);
|
|
}
|
|
|
|
try
|
|
{
|
|
rocblas_device_malloc mem(handle, sizes[0], sizes[1], sizes[2]);
|
|
|
|
if(!mem)
|
|
{
|
|
rocblas_cerr << "rocblas_device_malloc failed" << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
for(size_t i = 0; i < 3; ++i)
|
|
{
|
|
void* ptr = mem[i];
|
|
if(!ptr)
|
|
{
|
|
rocblas_cerr << "nullptr returned from rocblas_device_malloc[" << i << "]"
|
|
<< std::endl;
|
|
return 1;
|
|
}
|
|
hipMemset(ptr, 0, sizes[i]);
|
|
}
|
|
|
|
rocblas_device_malloc_base& ref = mem;
|
|
}
|
|
catch(...)
|
|
{
|
|
rocblas_cerr << "exception thrown for malloc size " << sizes[0] << "," << sizes[1] << ","
|
|
<< sizes[2] << std::endl;
|
|
return 1;
|
|
}
|
|
|
|
CHECK_ROCBLAS_ERROR(rocblas_destroy_handle(handle));
|
|
|
|
rocblas_cout << "All tests passed" << std::endl;
|
|
}
|