diff --git a/projects/hip-tests/catch/include/hip_test_defgroups.hh b/projects/hip-tests/catch/include/hip_test_defgroups.hh index f4ceedbc1b..83d2c4610b 100644 --- a/projects/hip-tests/catch/include/hip_test_defgroups.hh +++ b/projects/hip-tests/catch/include/hip_test_defgroups.hh @@ -102,7 +102,14 @@ THE SOFTWARE. */ /** - * @defgroup KernelTest Kernel Functions Management + * @defgroup MemoryTest memory Management APIs + * @{ + * This section describes the memory management types & functions of HIP runtime API. + * @} + */ + +/** +* @defgroup KernelTest Kernel Functions Management * @{ * This section describes the various kernel functions invocation. * @} diff --git a/projects/hip-tests/catch/unit/CMakeLists.txt b/projects/hip-tests/catch/unit/CMakeLists.txt index 4426b79b64..ae5c866e32 100644 --- a/projects/hip-tests/catch/unit/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/CMakeLists.txt @@ -36,7 +36,9 @@ add_subdirectory(compiler) add_subdirectory(errorHandling) add_subdirectory(cooperativeGrps) add_subdirectory(context) +add_subdirectory(g++) add_subdirectory(module) + if(HIP_PLATFORM STREQUAL "amd") add_subdirectory(callback) #add_subdirectory(clock) diff --git a/projects/hip-tests/catch/unit/g++/CMakeLists.txt b/projects/hip-tests/catch/unit/g++/CMakeLists.txt new file mode 100644 index 0000000000..5adf876616 --- /dev/null +++ b/projects/hip-tests/catch/unit/g++/CMakeLists.txt @@ -0,0 +1,19 @@ +# AMD specific test +if(HIP_PLATFORM MATCHES "amd") +if(UNIX) +set(TEST_SRC + hipMalloc.cc +) +# Creating Custom object file +add_custom_target(malloc_custom COMMAND g++ -c ${CMAKE_CURRENT_SOURCE_DIR}/hipMalloc.cpp -I${HIP_PATH}/include -D__HIP_PLATFORM_AMD__ -o malloc.o BYPRODUCTS malloc.o) +add_library(malloc_gpp OBJECT IMPORTED) +set_property(TARGET malloc_gpp PROPERTY IMPORTED_OBJECTS "${CMAKE_CURRENT_BINARY_DIR}/malloc.o") + +hip_add_exe_to_target(NAME gppTests + TEST_SRC ${TEST_SRC} + TEST_TARGET_NAME build_tests + LINKER_LIBS malloc_gpp) + +add_dependencies(gppTests malloc_custom) +endif() +endif() diff --git a/projects/hip-tests/catch/unit/g++/hipMalloc.cc b/projects/hip-tests/catch/unit/g++/hipMalloc.cc new file mode 100644 index 0000000000..22e3141c0e --- /dev/null +++ b/projects/hip-tests/catch/unit/g++/hipMalloc.cc @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 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 + * copies 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 WARRANNTY OF ANY KIND, EXPRESS OR + * IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * */ + +#include +#include +#include "hipMalloc.h" +/** + * @addtogroup hipMalloc hipMalloc + * @{ + * @ingroup MemoryTest + * `hipError_t hipMalloc(void** ptr, size_t size)` - + * Allocate memory on the default accelerator. + * @} + */ + +/** + * Test Description + * ------------------------ + * - Allocate memory by using hipMalloc API and verify hipSuccess is returned. + + * Test source + * ------------------------ + * - catch/unit/g++/hipMalloc.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.6 + */ + +TEST_CASE("Unit_hipMalloc_gpptest") { + printf("calling cpp function from here\n"); + int result = MallocFunc(); + REQUIRE(result == 1); +} diff --git a/projects/hip-tests/catch/unit/g++/hipMalloc.cpp b/projects/hip-tests/catch/unit/g++/hipMalloc.cpp new file mode 100644 index 0000000000..d954dc5e33 --- /dev/null +++ b/projects/hip-tests/catch/unit/g++/hipMalloc.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 - 2021 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 + * copies 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 WARRANNTY OF ANY KIND, EXPRESS OR + * IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * */ + +#include +#include +#include "hipMalloc.h" + +int MallocFunc() { + int* Ad; + hipError_t err; + err = hipMalloc(reinterpret_cast(&Ad), 1024); + if (err == hipSuccess) { + std::cout <<"PASSED!" < + +extern int MallocFunc(); \ No newline at end of file