diff --git a/.github/workflows/build-ais.yml b/.github/workflows/build-ais.yml index 62b7fff1..508d5f40 100644 --- a/.github/workflows/build-ais.yml +++ b/.github/workflows/build-ais.yml @@ -55,7 +55,7 @@ jobs: cp -R /mnt/ais /ais mkdir /ais/build ' - - name: Generate build files for hipFile and rocFile targeting the AMD platform (amdclang++) + - name: Generate build files for hipFile targeting the AMD platform (amdclang++) run: | docker exec \ -t \ @@ -70,7 +70,7 @@ jobs: -DBUILD_CODE_COVERAGE=ON \ .. ' - - name: Build hipFile and rocFile for the AMD platform (amdclang++) + - name: Build hipFile for the AMD platform (amdclang++) run: | docker exec \ -t \ @@ -79,7 +79,7 @@ jobs: /bin/bash -c ' cmake --build . --parallel ' - - name: Test hipFile and rocFile for the AMD platform (amdclang++) + - name: Test hipFile for the AMD platform (amdclang++) run: | docker exec \ -t \ @@ -157,7 +157,7 @@ jobs: cp -R /mnt/ais /ais mkdir /ais/build ' - - name: Generate build files for hipFile and rocFile targeting the AMD platform (${{ matrix.alternate_compilers }}) + - name: Generate build files for hipFile targeting the AMD platform (${{ matrix.alternate_compilers }}) run: | docker exec \ -t \ @@ -171,7 +171,7 @@ jobs: -DBUILD_AIS_DOCS=ON \ .. ' - - name: Build hipFile and rocFile for the AMD platform (${{ matrix.alternate_compilers }}) + - name: Build hipFile for the AMD platform (${{ matrix.alternate_compilers }}) run: | docker exec \ -t \ @@ -226,7 +226,7 @@ jobs: cp -R /mnt/ais /ais mkdir /ais/build ' - - name: Generate build files for hipFile and rocFile targeting the AMD platform (amdclang++) + - name: Generate build files for hipFile targeting the AMD platform (amdclang++) run: | docker exec \ -t \ @@ -240,7 +240,7 @@ jobs: -DBUILD_AIS_DOCS=ON \ .. ' - - name: Build hipFile and rocFile for the AMD platform (amdclang++) + - name: Build hipFile for the AMD platform (amdclang++) run: | docker exec \ -t \ @@ -249,7 +249,7 @@ jobs: /bin/bash -c ' cmake --build . --parallel ' - - name: Run hipFile and rocFile system tests for the AMD platform (amdclang++) + - name: Run hipFile system tests for the AMD platform (amdclang++) run: | docker exec \ -t \ @@ -258,7 +258,7 @@ jobs: /bin/bash -c ' ctest -V -L "system" --parallel ' - - name: Stress tests for hipFile and rocFile targeting the AMD platform (amdclang++) + - name: Stress tests for hipFile targeting the AMD platform (amdclang++) run: | docker exec \ -t \ diff --git a/CHANGELOG.md b/CHANGELOG.md index d21d283f..da761b5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# Changelog for hipFile/rocFile +# Changelog for hipFile ## UNRELEASED - hipFile 0.2.0 ### Added @@ -6,10 +6,11 @@ ### Changed ### Removed +* The rocFile library has been completely removed and the code is now a part of hipFile. * The hipify patch was removed. You can get hipify with hipFile support at https://github.com/derobins/HIPIFY/tree/hipFile. ### Limitations -* The batch API calls are not supported w/ a rocFile backend -* The async API calls are not supported w/ a rocFile backend +* The batch API calls are not supported w/ an AMD backend +* The async API calls are not supported w/ an AMD backend ### Known issues diff --git a/CMakeLists.txt b/CMakeLists.txt index a04b0607..070cefdf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,8 +16,6 @@ endif() # Set the library version in a variable so we can use # it in *.in files and avoid version mismatch. -# -# The versions number of rocFile and hipFile are identical set(AIS_LIBRARY_MAJOR 0) set(AIS_LIBRARY_MINOR 2) set(AIS_LIBRARY_PATCH 0) @@ -81,6 +79,15 @@ if(NOT CMAKE_HIP_PLATFORM STREQUAL "amd" AND NOT CMAKE_HIP_PLATFORM STREQUAL "nv message(FATAL_ERROR "Invalid CMAKE_HIP_PLATFORM: '${CMAKE_HIP_PLATFORM}'. Allowed values are 'amd' or 'nvidia'.") endif() +# Set the platform variable +if(CMAKE_HIP_PLATFORM STREQUAL "nvidia") + set(BUILD_AMD_DETAIL OFF) + set(BUILD_NVIDIA_DETAIL ON) +else() + set(BUILD_AMD_DETAIL ON) + set(BUILD_NVIDIA_DETAIL OFF) +endif() + #----------------------------------------------------------------------------- # Include our custom CMake code in the module path #----------------------------------------------------------------------------- @@ -119,7 +126,7 @@ include(AISAddLibraries) #----------------------------------------------------------------------------- # Code coverage (via llvm-cov) # -# To use with the hipFile/rocFile libraries: +# To use with the hipFile library: # - Build with BUILD_CODE_COVERAGE set to ON # - Run `ctest .` # @@ -156,15 +163,6 @@ include(AISIWYU) #------------------- include(AISSanitizers) -#------------------- -# Platform defaults -#------------------- -if(CMAKE_HIP_PLATFORM STREQUAL "nvidia") - set(BUILD_ROCFILE OFF) -else() - set(BUILD_ROCFILE ON) -endif() - #----------------------- # aiscp example program #----------------------- @@ -173,7 +171,7 @@ option(BUILD_AISCP "Build aiscp example program" ON) #------ # docs #------ -option(BUILD_AIS_DOCS "Build the rocFile/hipFile docs (requires Doxygen)" OFF) +option(BUILD_AIS_DOCS "Build the hipFile docs (requires Doxygen)" OFF) #----------------------------------------------------------------------------- # Find important packages for building the software @@ -194,10 +192,10 @@ else() endif() # Find the cuFile library and headers on NVIDIA -if(CMAKE_HIP_PLATFORM STREQUAL "nvidia") +if(BUILD_NVIDIA_DETAIL) find_package(CUDAToolkit REQUIRED) - if(CMAKE_HIP_PLATFORM STREQUAL "nvidia" AND CMAKE_VERSION VERSION_LESS "3.28") + if(CMAKE_VERSION VERSION_LESS "3.28") enable_language(CUDA) # Set a default architecture if not provided. if(NOT CMAKE_CUDA_ARCHITECTURES) @@ -219,9 +217,6 @@ endif() #----------------------------------------------------------------------------- # Subdirectories to configure/build #----------------------------------------------------------------------------- -if(BUILD_ROCFILE) - add_subdirectory(rocfile) -endif() add_subdirectory(hipfile) if(BUILD_AIS_DOCS) add_subdirectory(docs) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9675b19a..ccfcfbed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,4 +1,4 @@ -# Contributing to hipFile/rocFile +# Contributing to hipFile Thank you for contributing! This guide outlines the development workflow, contribution standards, and best practices when working on hipFile. diff --git a/INSTALL.md b/INSTALL.md index f78dfd63..278e0810 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -1,6 +1,6 @@ -# Install guide for hipFile / rocFile +# Install guide for hipFile -## Building hipFile and rocFile +## Building hipFile > [!NOTE] > hipFile is alpha software that has undergone testing on limited hardware. It may not work on your system at this time. @@ -57,18 +57,18 @@ Sanitizer options `ctest .` will run all tests. -You can filter on test labels using the `-L` option. We currently have `hipfile` and `rocfile` labels for each library and `unit`, `system`, and `stress` labels for the different test types. Multiple `-L` options form an *and*. A `|` can be used for an *or*. +You can filter on test labels using the `-L` option. We currently have `hipfile` and `internal` labels for the public API and its internals, respectively, and `unit`, `system`, and `stress` labels for the different test types. Multiple `-L` options form an *and*. A `|` can be used for an *or*. -`ctest . -L rocfile -L unit` runs all unit tests in the rocFile library. +`ctest . -L internal -L unit` runs all the internal library unit tests. `ctest . -L 'system|unit'` runs all system or unit tests. You can filter on test names using the `-R` option. This option supports wildcards. -`ctest . -R RocFileBuffer.get_buffer_makes_temporary_buffer` runs the specified test. -`ctest . -R 'RocFileBuffer*'` runs all tests that start with RocFileBuffer. +`ctest . -R HipFileBuffer.get_buffer_makes_temporary_buffer` runs the specified test. +`ctest . -R 'HipFileBuffer*'` runs all tests that start with HipFileBuffer. ### Install and package -The hipFile and rocFile libraries can be installed with CMake. The default +The hipFile library can be installed with CMake. The default install prefix is still the CMake default of `/usr/local`. `cmake --install .` diff --git a/README.md b/README.md index acabae08..2e155d61 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# hipFile / rocFile +# hipFile > [!CAUTION] > This release is an *early-access* software technology preview. Running production workloads is *not* recommended. @@ -9,7 +9,7 @@ AMD Infinity Storage library that supports IO directly to the GPU -## Building hipFile and rocFile +## Building hipFile See the INSTALL.md file in the project root for a list of supported hardware and compilers as well as build and install instructions. diff --git a/SECURITY.md b/SECURITY.md index 04351502..01ca213b 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -1,8 +1,8 @@ # Security Policy ## Reporting a vulnerability -If you have discovered a security vulnerability in the hipFile or rocFile -libraries, please do NOT report it publicly using a GitHub issue. Instead, +If you have discovered a security vulnerability in the hipFile library, +please do NOT report it publicly using a GitHub issue. Instead, you should report the issue via the AMD Product Security website: https://www.amd.com/en/resources/product-security.html diff --git a/STYLEGUIDE.md b/STYLEGUIDE.md index 6cd2212d..62766944 100644 --- a/STYLEGUIDE.md +++ b/STYLEGUIDE.md @@ -1,4 +1,4 @@ -# hipFile/rocFile Style Guide +# hipFile Style Guide ## File and Directory Structure ### Organization diff --git a/cmake/AISAddExecutable.cmake b/cmake/AISAddExecutable.cmake index d0e794ba..38b0af79 100644 --- a/cmake/AISAddExecutable.cmake +++ b/cmake/AISAddExecutable.cmake @@ -15,9 +15,9 @@ include(AISCompilerOptions) # NOTE: Assumes AIS target libraries are named _(static|shared) # # NOTE: This isn't the most robust function. It's mainly intended -# to reduce code duplication in rocFile/hipFile. For example, -# DEPS is for passing the rocFile dependency to hipFile and -# won't work for passing general library dependencies. +# to reduce code duplication. For example, DEPS is for passing +# the hipFile shared/static dependency and won't work for passing +# general library dependencies. function(ais_add_executable) # Parse arguments diff --git a/cmake/AISAddLibraries.cmake b/cmake/AISAddLibraries.cmake index 4d7add76..9913bb34 100644 --- a/cmake/AISAddLibraries.cmake +++ b/cmake/AISAddLibraries.cmake @@ -13,21 +13,13 @@ include(CheckLinkerFlag) # LIBINCL Path to installed include files (e.g., hipfile.h) # SYSINCLS [path1 [path2 ...]] Paths to other include dirs # SRCS [src1 [src2 ...]] The source files -# DEPS [dependency1 [dependency2 ...]] List of AIS target library dependencies # LIBS [lib1, [lib2 ...]] List of external library dependencies -# -# NOTE: Assumes internal library dependencies are named _(static|shared) -# -# NOTE: This isn't the most robust function. It's mainly intended to reduce -# code duplication in rocFile/hipFile. For example, DEPS is for passing -# the rocFile internal library dependency to hipFile and won't work for -# passing general library dependencies. function(ais_add_libraries) # Parse arguments set(options) # None at this time set(oneValueArgs NAME DETAIL LIBINCL) - set(multiValueArgs SRCS DEPS SYSINCLS LIBS) + set(multiValueArgs SRCS SYSINCLS LIBS) cmake_parse_arguments(arg "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) # Convenience names @@ -48,18 +40,6 @@ function(ais_add_libraries) set_target_properties(${shared_name} PROPERTIES VERSION ${AIS_LIBRARY_VERSION}) set_target_properties(${shared_name} PROPERTIES SOVERSION ${AIS_LIBRARY_SOVERSION}) - # Add dependencies on internal targets - foreach(dep IN LISTS arg_DEPS) - add_dependencies(${static_name} "${dep}_static") - add_dependencies(${shared_name} "${dep}_shared") - - target_link_libraries(${static_name} PRIVATE "${dep}_static") - target_link_libraries(${shared_name} PRIVATE "${dep}_shared") - - # The object library needs to see the headers for any dependencies - target_link_libraries(${object_name} PUBLIC "${dep}_shared") - endforeach() - # Add dependencies on external libraries foreach(lib IN LISTS arg_LIBS) find_library(LIBRARY_PATH NAMES ${lib}) diff --git a/cmake/AISCompilerOptions.cmake b/cmake/AISCompilerOptions.cmake index fc49b389..354a9887 100644 --- a/cmake/AISCompilerOptions.cmake +++ b/cmake/AISCompilerOptions.cmake @@ -12,7 +12,7 @@ function(ais_set_compiler_flags target) foreach(source IN LISTS sources) get_source_file_property(language ${source} LANGUAGE) # CMake HIP language prior to 3.28 only supports AMD, so change LANGUAGE to CUDA for HIP files - if(CMAKE_HIP_PLATFORM STREQUAL "nvidia" AND CMAKE_VERSION VERSION_LESS "3.28" AND language STREQUAL HIP) + if(BUILD_NVIDIA_DETAIL AND CMAKE_VERSION VERSION_LESS "3.28" AND language STREQUAL HIP) set_source_files_properties(${source} PROPERTIES LANGUAGE "CUDA") set(language CUDA) message(STATUS "Setting ${source} LANGUAGE to CUDA because CMake < 3.28") diff --git a/cmake/AISInstall.cmake b/cmake/AISInstall.cmake index 78466306..97779ae3 100644 --- a/cmake/AISInstall.cmake +++ b/cmake/AISInstall.cmake @@ -2,46 +2,26 @@ # # SPDX-License-Identifier: MIT -# Install hipFile and rocFile +# Install hipFile # From the rocm-cmake repo include(ROCMInstallTargets) include(ROCMCreatePackage) - # Install the package -if(BUILD_ROCFILE) - rocm_install(TARGETS rocfile_static) - rocm_install(TARGETS rocfile_shared) -endif() rocm_install(TARGETS hipfile_static) rocm_install(TARGETS hipfile_shared) # Install the headers -if(BUILD_ROCFILE) - rocm_install( - DIRECTORY ${CMAKE_SOURCE_DIR}/rocfile/include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} - ) -endif() rocm_install( DIRECTORY ${CMAKE_SOURCE_DIR}/hipfile/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) -# Always install the hipfile-types.h file -rocm_install( - FILES ${CMAKE_SOURCE_DIR}/shared/hipfile-types.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} -) - # rocm_package_add_dependencies() line should go here # when we have dependencies # Export the targets -if(BUILD_ROCFILE) - set(target_list ${target_list} roc::rocfile_shared roc::rocfile_static) -endif() set(target_list ${target_list} roc::hipfile_shared roc::hipfile_static) rocm_export_targets( diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 4f959805..d8c2d3ac 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -52,6 +52,3 @@ function(ais_add_docs_target AIS_DOC_PRETTY_NAME) endfunction() ais_add_docs_target("hipFile") -if(BUILD_ROCFILE) - ais_add_docs_target("rocFile") -endif() diff --git a/hipfile/CMakeLists.txt b/hipfile/CMakeLists.txt index b6fd4e96..0124c7fe 100644 --- a/hipfile/CMakeLists.txt +++ b/hipfile/CMakeLists.txt @@ -6,23 +6,27 @@ cmake_minimum_required(VERSION 3.21) project("hipfile" DESCRIPTION "hipFile library" LANGUAGES CXX HIP) -# Set the path to the include directory for later use +# Set the path to the include directories for later use set(HIPFILE_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include") set(HIPFILE_AMD_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/amd_detail") set(HIPFILE_NVIDIA_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src/nvidia_detail") -set(HIPFILE_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test") +set(HIPFILE_TEST_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test/common") +set(HIPFILE_AMD_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test/amd_detail") # Add the src directory depending on the HIP platform -if(CMAKE_HIP_PLATFORM STREQUAL "nvidia") +if(BUILD_NVIDIA_DETAIL) add_subdirectory(src/nvidia_detail) else() add_subdirectory(src/amd_detail) endif() -# Add the testing directory +# Add the testing directories if(BUILD_TESTING) add_subdirectory(test) endif() +if(BUILD_TESTING AND BUILD_AMD_DETAIL) + add_subdirectory(test/amd_detail) +endif() # Add the aiscp example directory if(BUILD_AISCP) diff --git a/hipfile/docs/errors.rst b/hipfile/docs/errors.rst index 44e3392f..67e6f6e5 100644 --- a/hipfile/docs/errors.rst +++ b/hipfile/docs/errors.rst @@ -12,7 +12,7 @@ values indicate an error. :: - typedef struct __ROCFILE_NODISCARD hipFileError { + typedef struct __HIPFILE_NODISCARD hipFileError { hipFileOpError_t err; //!< Errors related to hipFile or the GPU IO driver hipError_t hip_drv_err; //!< Errors related to the GPU driver } hipFileError_t; @@ -31,8 +31,8 @@ be set to ``hipSuccess``. Several helper macros are included in ``hipfile.h`` that help with error checking: -* ``IS_ROCFILE_ERR()`` -* ``ROCFILE_ERRSTR()`` +* ``IS_HIPFILE_ERR()`` +* ``HIPFILE_ERRSTR()`` * ``IS_HIP_DRV_ERR()`` * ``HIP_DRV_ERR()`` diff --git a/hipfile/include/hipfile.h b/hipfile/include/hipfile.h index c2e58218..065c3380 100644 --- a/hipfile/include/hipfile.h +++ b/hipfile/include/hipfile.h @@ -5,7 +5,6 @@ #pragma once -#include #include #include #include @@ -83,6 +82,20 @@ extern "C" { */ #define HIPFILE_VERSION_PATCH 0 +// *********************************************************************** +// PLATFORM-INDEPENDENT TYPES +// *********************************************************************** + +/*! + * @brief Platform-independent offset type + * @ingroup core + */ +#ifndef _WIN32 +typedef off_t hoff_t; +#else +typedef __int64 hoff_t; +#endif + // *********************************************************************** // ERROR HANDLING // *********************************************************************** diff --git a/hipfile/src/amd_detail/CMakeLists.txt b/hipfile/src/amd_detail/CMakeLists.txt index 650d5c89..03c67855 100644 --- a/hipfile/src/amd_detail/CMakeLists.txt +++ b/hipfile/src/amd_detail/CMakeLists.txt @@ -5,16 +5,30 @@ # ROCm-backed hipFile set(HIPFILE_SOURCES - hipfile.cpp - hipfile-rocfile.cpp ../common/hipfile-common.cpp + async.cpp + backend/asyncop-fallback.cpp + backend/fallback.cpp + backend/fastpath.cpp + batch/batch.cpp + buffer.cpp + context.cpp + file.cpp + hip.cpp + hipfile.cpp + hipfile-private.cpp + mountinfo.cpp + state.cpp + stream.cpp + sys.cpp ) # Will create hipfile_(static|shared) ais_add_libraries( - NAME hipfile - DETAIL amd - SRCS ${HIPFILE_SOURCES} - DEPS rocfile - LIBINCL ${HIPFILE_INCLUDE_PATH} + NAME hipfile + DETAIL amd + LIBS mount + SRCS ${HIPFILE_SOURCES} + LIBINCL ${HIPFILE_INCLUDE_PATH} + SYSINCLS ${HIPFILE_AMD_SOURCE_PATH} ) diff --git a/rocfile/src/async.cpp b/hipfile/src/amd_detail/async.cpp similarity index 96% rename from rocfile/src/async.cpp rename to hipfile/src/amd_detail/async.cpp index adab7a70..40eb9808 100644 --- a/rocfile/src/async.cpp +++ b/hipfile/src/amd_detail/async.cpp @@ -5,6 +5,7 @@ #include "async.h" #include "context.h" +#include "hipfile.h" #include "stream.h" #include "sys.h" @@ -13,17 +14,17 @@ #include #include -namespace rocFile { +namespace hipFile { class IBuffer; } -namespace rocFile { +namespace hipFile { class IFile; } -namespace rocFile { +namespace hipFile { enum class IoType; } -namespace rocFile { +namespace hipFile { AsyncMonitor::AsyncMonitor() : is_finished{false} { diff --git a/rocfile/src/async.h b/hipfile/src/amd_detail/async.h similarity index 93% rename from rocfile/src/async.h rename to hipfile/src/amd_detail/async.h index fe5e8ea2..aeb9f951 100644 --- a/rocfile/src/async.h +++ b/hipfile/src/amd_detail/async.h @@ -4,7 +4,7 @@ */ #pragma once -#include "hipfile-types.h" +#include "hipfile.h" #include #include @@ -15,20 +15,20 @@ #include #include -namespace rocFile { +namespace hipFile { class IBuffer; } -namespace rocFile { +namespace hipFile { class IFile; } -namespace rocFile { +namespace hipFile { class IStream; } -namespace rocFile { +namespace hipFile { enum class IoType; } -namespace rocFile { +namespace hipFile { class AsyncOp { public: diff --git a/rocfile/src/backend.h b/hipfile/src/amd_detail/backend.h similarity index 99% rename from rocfile/src/backend.h rename to hipfile/src/amd_detail/backend.h index d681800d..c2e040df 100644 --- a/rocfile/src/backend.h +++ b/hipfile/src/amd_detail/backend.h @@ -16,7 +16,7 @@ #include #include -namespace rocFile { +namespace hipFile { // The maximum number of bytes that can be transferred in a single read() or // write() system call. Mirrors kernel's MAX_RW_COUNT diff --git a/rocfile/src/backend/asyncop-fallback.cpp b/hipfile/src/amd_detail/backend/asyncop-fallback.cpp similarity index 96% rename from rocfile/src/backend/asyncop-fallback.cpp rename to hipfile/src/amd_detail/backend/asyncop-fallback.cpp index cd951d3c..7c1976d2 100644 --- a/rocfile/src/backend/asyncop-fallback.cpp +++ b/hipfile/src/amd_detail/backend/asyncop-fallback.cpp @@ -14,17 +14,17 @@ #include #include -namespace rocFile { +namespace hipFile { class IFile; } -namespace rocFile { +namespace hipFile { class IStream; } -namespace rocFile { +namespace hipFile { enum class IoType; } -using namespace rocFile; +using namespace hipFile; static void hipHostDeleter(void *buffer) diff --git a/rocfile/src/backend/asyncop-fallback.h b/hipfile/src/amd_detail/backend/asyncop-fallback.h similarity index 87% rename from rocfile/src/backend/asyncop-fallback.h rename to hipfile/src/amd_detail/backend/asyncop-fallback.h index cb44766e..64953fe9 100644 --- a/rocfile/src/backend/asyncop-fallback.h +++ b/hipfile/src/amd_detail/backend/asyncop-fallback.h @@ -5,25 +5,25 @@ #pragma once #include "async.h" -#include "hipfile-types.h" +#include "hipfile.h" #include #include -namespace rocFile { +namespace hipFile { class IBuffer; } -namespace rocFile { +namespace hipFile { class IFile; } -namespace rocFile { +namespace hipFile { class IStream; } -namespace rocFile { +namespace hipFile { enum class IoType; } -namespace rocFile { +namespace hipFile { struct AsyncOpFallback : AsyncOp { ssize_t bytes_transferred_internal; diff --git a/rocfile/src/backend/fallback.cpp b/hipfile/src/amd_detail/backend/fallback.cpp similarity index 98% rename from rocfile/src/backend/fallback.cpp rename to hipfile/src/amd_detail/backend/fallback.cpp index 0ca245d1..7b0feae3 100644 --- a/rocfile/src/backend/fallback.cpp +++ b/hipfile/src/amd_detail/backend/fallback.cpp @@ -20,7 +20,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using std::min; using std::shared_ptr; @@ -52,7 +52,7 @@ Fallback::io(IoType io_type, shared_ptr file, shared_ptr buffer, { size_t buflen{buffer->getLength()}; - size = min(size, rocFile::MAX_RW_COUNT); + size = min(size, hipFile::MAX_RW_COUNT); if (file_offset < 0) { throw std::invalid_argument("Negative file offset"); diff --git a/rocfile/src/backend/fallback.h b/hipfile/src/amd_detail/backend/fallback.h similarity index 90% rename from rocfile/src/backend/fallback.h rename to hipfile/src/amd_detail/backend/fallback.h index 94bd75b9..b8554f0b 100644 --- a/rocfile/src/backend/fallback.h +++ b/hipfile/src/amd_detail/backend/fallback.h @@ -6,22 +6,22 @@ #pragma once #include "backend.h" -#include "hipfile-types.h" +#include "hipfile.h" #include #include -namespace rocFile { +namespace hipFile { class IBuffer; } -namespace rocFile { +namespace hipFile { class IFile; } -namespace rocFile { +namespace hipFile { enum class IoType; } -namespace rocFile { +namespace hipFile { struct Fallback : public Backend { virtual ~Fallback() override = default; diff --git a/rocfile/src/backend/fastpath.cpp b/hipfile/src/amd_detail/backend/fastpath.cpp similarity index 97% rename from rocfile/src/backend/fastpath.cpp rename to hipfile/src/amd_detail/backend/fastpath.cpp index 63e30b7d..250fa657 100644 --- a/rocfile/src/backend/fastpath.cpp +++ b/hipfile/src/amd_detail/backend/fastpath.cpp @@ -8,6 +8,7 @@ #include "fastpath.h" #include "file.h" #include "hip.h" +#include "hipfile.h" #include "io.h" #include @@ -16,7 +17,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using namespace std; /* The fastpath backend is used when: @@ -33,14 +34,14 @@ using namespace std; * - The buffer type is hipMemoryTypeDevice * * When using the fastpath the IO flows through the following - * - rocFile HIP wrapper (userspace) + * - hipFile HIP wrapper (userspace) * - repository: hipFile - * - file: rocfile/hip.cpp + * - file: hipfile/src/amd_detail/hip.cpp * - methods: Hip::hipAmdFileRead(...), Hip::hipAmdFileWrite(...) * - throws * - std::system_error if status is non-zero (set by kfd) * - Hip::runtime_error if hip runtime does not return hipSuccess or - * if rocFile was unable to find hipAmdFileRead/hipAmdFileWrite + * if hipFile was unable to find hipAmdFileRead/hipAmdFileWrite * - HIP Runtime (userspace) * - repository: rocm-systems * - file: projects/clr/hipamd/src/hip_storage.cpp diff --git a/rocfile/src/backend/fastpath.h b/hipfile/src/amd_detail/backend/fastpath.h similarity index 86% rename from rocfile/src/backend/fastpath.h rename to hipfile/src/amd_detail/backend/fastpath.h index 91b9863f..61f0915e 100644 --- a/rocfile/src/backend/fastpath.h +++ b/hipfile/src/amd_detail/backend/fastpath.h @@ -6,22 +6,22 @@ #pragma once #include "backend.h" -#include "hipfile-types.h" +#include "hipfile.h" #include #include -namespace rocFile { +namespace hipFile { class IBuffer; } -namespace rocFile { +namespace hipFile { class IFile; } -namespace rocFile { +namespace hipFile { enum class IoType; } -namespace rocFile { +namespace hipFile { struct Fastpath : public Backend { virtual ~Fastpath() override = default; diff --git a/rocfile/src/batch/batch.cpp b/hipfile/src/amd_detail/batch/batch.cpp similarity index 90% rename from rocfile/src/batch/batch.cpp rename to hipfile/src/amd_detail/batch/batch.cpp index 024ca359..7ff7c14f 100644 --- a/rocfile/src/batch/batch.cpp +++ b/hipfile/src/amd_detail/batch/batch.cpp @@ -7,7 +7,7 @@ #include "buffer.h" #include "context.h" #include "file.h" -#include "rocfile.h" +#include "hipfile.h" #include "state.h" #include @@ -20,9 +20,9 @@ #include #include -namespace rocFile { +namespace hipFile { -BatchOperation::BatchOperation(std::unique_ptr params, +BatchOperation::BatchOperation(std::unique_ptr params, std::shared_ptr _buffer, std::shared_ptr _file) : io_params{std::move(params)}, buffer{_buffer}, file{_file} { @@ -67,7 +67,7 @@ BatchOperation::BatchOperation(std::unique_ptr params, } // Check OpCode - if (io_params->opcode != rocFileBatchRead && io_params->opcode != rocFileBatchWrite) { + if (io_params->opcode != hipFileBatchRead && io_params->opcode != hipFileBatchWrite) { std::stringstream msg; msg << "Bad opcode specified. Value: " << io_params->opcode; msg << ". Cookie: " << io_params->cookie; @@ -75,7 +75,7 @@ BatchOperation::BatchOperation(std::unique_ptr params, } // Check Batch Mode - if (io_params->mode != rocFileBatch) { + if (io_params->mode != hipFileBatch) { std::stringstream msg; msg << "Invalid Batch mode specified. Value: " << io_params->mode; msg << ". Cookie: " << io_params->cookie; @@ -100,7 +100,7 @@ BatchContext::get_capacity() const noexcept } void -BatchContext::submit_operations(const rocFileIOParams_t *params, unsigned num_params) +BatchContext::submit_operations(const hipFileIOParams_t *params, unsigned num_params) { std::unique_lock _ulock{context_mutex}; @@ -119,8 +119,8 @@ BatchContext::submit_operations(const rocFileIOParams_t *params, unsigned num_pa // rather than waiting to lock the DriverState lock for each lookup. for (unsigned i = 0; i < num_params; i++) { // Make a copy of the params so another thread cannot modify the operation. - auto param_copy = std::make_unique(params[i]); - // flags currently unused. Ambiguous if flags in rocFileBatchIOSubmit is for buffer or + auto param_copy = std::make_unique(params[i]); + // flags currently unused. Ambiguous if flags in hipFileBatchIOSubmit is for buffer or // file flags. auto [_file, _buffer] = Context::get()->getFileAndBuffer( param_copy->fh, param_copy->u.batch.devPtr_base, param_copy->u.batch.size, 0); @@ -140,11 +140,11 @@ BatchContextMap::clear() active_contexts.clear(); } -rocFileBatchHandle_t +hipFileBatchHandle_t BatchContextMap::createContext(unsigned capacity) { auto context = std::shared_ptr{new BatchContext{capacity}}; - rocFileBatchHandle_t handle = context.get(); + hipFileBatchHandle_t handle = context.get(); // Should not need to worry about duplicate keys unless the application // somehow deallocates this handle... @@ -155,7 +155,7 @@ BatchContextMap::createContext(unsigned capacity) } void -BatchContextMap::destroyContext(rocFileBatchHandle_t handle) +BatchContextMap::destroyContext(hipFileBatchHandle_t handle) { std::unique_lock ulock{batch_mutex}; @@ -171,7 +171,7 @@ BatchContextMap::destroyContext(rocFileBatchHandle_t handle) } std::shared_ptr -BatchContextMap::get(rocFileBatchHandle_t handle) +BatchContextMap::get(hipFileBatchHandle_t handle) { // NOTE: This mutex only protects the map, so we'll // also need to protect the data diff --git a/rocfile/src/batch/batch.h b/hipfile/src/amd_detail/batch/batch.h similarity index 86% rename from rocfile/src/batch/batch.h rename to hipfile/src/amd_detail/batch/batch.h index 54923941..f8372a17 100644 --- a/rocfile/src/batch/batch.h +++ b/hipfile/src/amd_detail/batch/batch.h @@ -5,7 +5,7 @@ #pragma once -#include "rocfile.h" +#include "hipfile.h" #include #include @@ -13,14 +13,14 @@ #include #include -namespace rocFile { +namespace hipFile { class IBuffer; } -namespace rocFile { +namespace hipFile { class IFile; } -namespace rocFile { +namespace hipFile { struct InvalidBatchHandle : public std::invalid_argument { InvalidBatchHandle() : std::invalid_argument{"Invalid batch handle"} @@ -35,13 +35,13 @@ class BatchOperation { /// @param [in] params IO parameters /// @param [in] buffer Buffer corresponding to params->u.batch.devPtr_base /// @param [in] file File corresponding params->fh - BatchOperation(std::unique_ptr params, std::shared_ptr buffer, + BatchOperation(std::unique_ptr params, std::shared_ptr buffer, std::shared_ptr file); private: /// @brief A copy of the params provided by the application. /// @internal Keep this listed at the top of BatchOperation. - const std::unique_ptr io_params; + const std::unique_ptr io_params; /// @brief A reference to the specified Buffer. const std::shared_ptr buffer; @@ -56,7 +56,7 @@ class IBatchContext { virtual ~IBatchContext() = default; virtual unsigned get_capacity() const noexcept = 0; - virtual void submit_operations(const rocFileIOParams_t *params, unsigned num_params) = 0; + virtual void submit_operations(const hipFileIOParams_t *params, unsigned num_params) = 0; }; class BatchContext : public IBatchContext { @@ -76,7 +76,7 @@ class BatchContext : public IBatchContext { /// @note This is an All or None operation. If one submitted operation is not valid, no operations /// will be submitted. /// - void submit_operations(const rocFileIOParams_t *params, const unsigned num_params) override; + void submit_operations(const hipFileIOParams_t *params, const unsigned num_params) override; private: const unsigned capacity; @@ -103,20 +103,20 @@ class BatchContextMap { * @param capacity Maximum number of outstanding operations that this context can manage * @return An opaque handle used to reference this new batch context */ - rocFileBatchHandle_t createContext(unsigned capacity); + hipFileBatchHandle_t createContext(unsigned capacity); /*! * @brief Destroy a batch context and release all associated resources * @param handle The handle for the batch context to destroy */ - void destroyContext(rocFileBatchHandle_t handle); + void destroyContext(hipFileBatchHandle_t handle); /*! * @brief Get a batch context * @param handle The opaque handle associated with a batch context * @return A batch context */ - std::shared_ptr get(rocFileBatchHandle_t handle); + std::shared_ptr get(hipFileBatchHandle_t handle); /*! * @brief Clear the contents @@ -125,7 +125,7 @@ class BatchContextMap { private: /// batch context lookup table - std::unordered_map> active_contexts; + std::unordered_map> active_contexts; /// Mutex to protect the active context map mutable std::shared_mutex batch_mutex; diff --git a/rocfile/src/buffer.cpp b/hipfile/src/amd_detail/buffer.cpp similarity index 99% rename from rocfile/src/buffer.cpp rename to hipfile/src/amd_detail/buffer.cpp index 41738454..697b5651 100644 --- a/rocfile/src/buffer.cpp +++ b/hipfile/src/amd_detail/buffer.cpp @@ -20,7 +20,7 @@ using std::shared_ptr; using std::transform; using std::vector; -namespace rocFile { +namespace hipFile { static bool isValidBufferRegion(void *ptr, size_t length) diff --git a/rocfile/src/buffer.h b/hipfile/src/amd_detail/buffer.h similarity index 91% rename from rocfile/src/buffer.h rename to hipfile/src/amd_detail/buffer.h index 3500f5fd..5a05f751 100644 --- a/rocfile/src/buffer.h +++ b/hipfile/src/amd_detail/buffer.h @@ -11,7 +11,7 @@ #include #include -namespace rocFile { +namespace hipFile { /// @brief Buffer is currently registered struct BufferAlreadyRegistered : public std::runtime_error { @@ -108,26 +108,26 @@ class BufferMap { virtual ~BufferMap(); /// @brief Creates and registers a buffer - /// @attention A unique_lock on RocFileMutex must be held + /// @attention A unique_lock on HipFileMutex must be held /// @param buf Buffer pointer /// @param length Buffer length /// @param flags Buffer flags (unused) virtual void registerBuffer(const void *buf, size_t length, int flags); /// @brief Deregisters and destroys a buffer - /// @attention A unique_lock on RocFileMutex must be held + /// @attention A unique_lock on HipFileMutex must be held /// @param buf Buffer pointer virtual void deregisterBuffer(const void *buf); /// @brief Look up a registered buffer using the buffer pointer - /// @attention A shared_lock on RocFileMutex must be held + /// @attention A shared_lock on HipFileMutex must be held /// @param buf Buffer pointer /// @return A registered buffer virtual std::shared_ptr getBuffer(const void *buf); /// @brief Look up a registered buffer. Returns a temporary unregistered /// buffer (of size length, using flags) if no matching buffer is found. - /// @attention A shared_lock on RocFileMutex must be held + /// @attention A shared_lock on HipFileMutex must be held /// @param buf Buffer pointer /// @param length Buffer length /// @return A registered or temporary unregistered buffer @@ -136,7 +136,7 @@ class BufferMap { virtual void clear(); private: - /// Buffer lookup table. Protected by rocfile.cpp's StateMutex + /// Buffer lookup table. Protected by hipfile.cpp's StateMutex std::unordered_map> from_ptr; }; diff --git a/rocfile/src/context.cpp b/hipfile/src/amd_detail/context.cpp similarity index 79% rename from rocfile/src/context.cpp rename to hipfile/src/amd_detail/context.cpp index bd829970..4e909938 100644 --- a/rocfile/src/context.cpp +++ b/hipfile/src/amd_detail/context.cpp @@ -9,9 +9,9 @@ #include "state.h" #include "sys.h" -namespace rocFile { +namespace hipFile { -RocFileInit::RocFileInit() +HipFileInit::HipFileInit() { Context::get(); Context::get(); @@ -20,7 +20,7 @@ RocFileInit::RocFileInit() HIPFILE_WARN_NO_GLOBAL_CTOR_OFF HIPFILE_WARN_NO_EXIT_DTOR_OFF -static RocFileInit *rocfile_init = Context::get(); +static HipFileInit *hipfile_init = Context::get(); HIPFILE_WARN_NO_EXIT_DTOR_ON HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/rocfile/src/context.h b/hipfile/src/amd_detail/context.h similarity index 96% rename from rocfile/src/context.h rename to hipfile/src/amd_detail/context.h index c3e12ee0..b568c9f6 100644 --- a/rocfile/src/context.h +++ b/hipfile/src/amd_detail/context.h @@ -11,7 +11,7 @@ #include #endif -namespace rocFile { +namespace hipFile { template struct ContextOverride; @@ -92,9 +92,9 @@ template struct ContextOverride { }; #endif -class RocFileInit { - RocFileInit(); - friend struct Context; +class HipFileInit { + HipFileInit(); + friend struct Context; }; } diff --git a/rocfile/src/file.cpp b/hipfile/src/amd_detail/file.cpp similarity index 93% rename from rocfile/src/file.cpp rename to hipfile/src/amd_detail/file.cpp index dbcbb382..e63d940d 100644 --- a/rocfile/src/file.cpp +++ b/hipfile/src/amd_detail/file.cpp @@ -21,7 +21,7 @@ using std::shared_ptr; using std::transform; using std::vector; -namespace rocFile { +namespace hipFile { UnregisteredFile::UnregisteredFile(int fd) : m_fd(fd), m_stx{Context::get()->statx(fd, "", AT_EMPTY_PATH, @@ -61,10 +61,10 @@ UnregisteredFile::getMountInfo() const noexcept return m_mountinfo; } -rocFileHandle_t +hipFileHandle_t IFile::getHandle() const { - return reinterpret_cast(const_cast(this)); + return reinterpret_cast(const_cast(this)); } File::File(const UnregisteredFile &uf) @@ -97,7 +97,7 @@ File::getMountInfo() const } shared_ptr -FileMap::getFile(rocFileHandle_t fh) +FileMap::getFile(hipFileHandle_t fh) { auto itr = from_fh.find(fh); if (from_fh.end() == itr) { @@ -107,7 +107,7 @@ FileMap::getFile(rocFileHandle_t fh) return itr->second; } -rocFileHandle_t +hipFileHandle_t FileMap::registerFile(const UnregisteredFile &uf) { if (from_fd.end() != from_fd.find(uf.getFd())) { @@ -122,7 +122,7 @@ FileMap::registerFile(const UnregisteredFile &uf) } void -FileMap::deregisterFile(rocFileHandle_t fh) +FileMap::deregisterFile(hipFileHandle_t fh) { auto itr = from_fh.find(fh); @@ -149,7 +149,7 @@ FileMap::~FileMap() { try { // Create a list of registered files without causing the use_count to increase - vector file_handles; + vector file_handles; file_handles.reserve(from_fh.size()); transform(from_fh.begin(), from_fh.end(), std::back_inserter(file_handles), [](const auto &pair) { return pair.first; }); diff --git a/rocfile/src/file.h b/hipfile/src/amd_detail/file.h similarity index 86% rename from rocfile/src/file.h rename to hipfile/src/amd_detail/file.h index f1ff06b6..1302e2c5 100644 --- a/rocfile/src/file.h +++ b/hipfile/src/amd_detail/file.h @@ -5,7 +5,7 @@ #pragma once -#include "rocfile.h" +#include "hipfile.h" #include "mountinfo.h" #include @@ -14,7 +14,7 @@ #include #include -namespace rocFile { +namespace hipFile { /// @brief File is not registered struct FileNotRegistered : public std::runtime_error { @@ -79,7 +79,7 @@ class IFile { /// @brief Get the handle for this file /// @return The handle for this file - virtual rocFileHandle_t getHandle() const; + virtual hipFileHandle_t getHandle() const; virtual int getFd() const = 0; virtual const struct statx &getStatx() const noexcept = 0; @@ -131,28 +131,28 @@ class FileMap { public: virtual ~FileMap(); - /// @brief Registers a file. Files must be registered before they can be used with rocFile IO APIs - /// @attention A unique_lock on RocFileMutex must be held + /// @brief Registers a file. Files must be registered before they can be used with hipFile IO APIs + /// @attention A unique_lock on HipFileMutex must be held /// @param uf An unregistered file - virtual rocFileHandle_t registerFile(const UnregisteredFile &uf); + virtual hipFileHandle_t registerFile(const UnregisteredFile &uf); /// @brief Deregisters the file associated with the provided file handle - /// @attention A unique_lock on RocFileMutex must be held + /// @attention A unique_lock on HipFileMutex must be held /// @param fh The handle of the file to deregister - virtual void deregisterFile(rocFileHandle_t fh); + virtual void deregisterFile(hipFileHandle_t fh); - /// @brief Look up a file given a rocFileHandle_t - /// @attention A shared_lock on RocFileMutex must be held + /// @brief Look up a file given a hipFileHandle_t + /// @attention A shared_lock on HipFileMutex must be held /// @param fh The file handle to lookup the file with /// @return If file handle is valid, return a shared pointer to the file, otherwise throw NotRegistered. - virtual std::shared_ptr getFile(rocFileHandle_t fh); + virtual std::shared_ptr getFile(hipFileHandle_t fh); virtual void clear(); private: /// File lookup tables. std::unordered_map> from_fd; - std::unordered_map> from_fh; + std::unordered_map> from_fh; }; } diff --git a/rocfile/src/hip.cpp b/hipfile/src/amd_detail/hip.cpp similarity index 99% rename from rocfile/src/hip.cpp rename to hipfile/src/amd_detail/hip.cpp index b575842a..e891b44a 100644 --- a/rocfile/src/hip.cpp +++ b/hipfile/src/amd_detail/hip.cpp @@ -9,7 +9,7 @@ #include #include -namespace rocFile { +namespace hipFile { static void * hipGetProcAddressHelper(const char *symbol) diff --git a/rocfile/src/hip.h b/hipfile/src/amd_detail/hip.h similarity index 96% rename from rocfile/src/hip.h rename to hipfile/src/amd_detail/hip.h index 754801f2..11dc0638 100644 --- a/rocfile/src/hip.h +++ b/hipfile/src/amd_detail/hip.h @@ -14,7 +14,7 @@ /* hipxx (hip++) * - * hipxx wraps HIP APIs used by hipFile/rocFile libraries. This enables unit + * hipxx wraps HIP APIs used by the hipFile library. This enables unit * tests to mock HIP APIs. * * The wrapper methods should @@ -23,7 +23,7 @@ * - Use return values instead of out arguments when possible */ -namespace rocFile { +namespace hipFile { struct HipMemAddressRange { hipDeviceptr_t base; diff --git a/rocfile/src/rocfile-private.cpp b/hipfile/src/amd_detail/hipfile-private.cpp similarity index 56% rename from rocfile/src/rocfile-private.cpp rename to hipfile/src/amd_detail/hipfile-private.cpp index 0ea5be16..89b2ad93 100644 --- a/rocfile/src/rocfile-private.cpp +++ b/hipfile/src/amd_detail/hipfile-private.cpp @@ -4,11 +4,11 @@ */ #include "context.h" -#include "rocfile-private.h" +#include "hipfile-private.h" #include "state.h" void -rocFileEnsureDriverInitPrivate() +hipFileEnsureDriverInitPrivate() { - rocFile::Context::get()->ensureInitialized(); + hipFile::Context::get()->ensureInitialized(); } diff --git a/rocfile/src/rocfile-private.h b/hipfile/src/amd_detail/hipfile-private.h similarity index 73% rename from rocfile/src/rocfile-private.h rename to hipfile/src/amd_detail/hipfile-private.h index 6e6e90fb..b7db4e7a 100644 --- a/rocfile/src/rocfile-private.h +++ b/hipfile/src/amd_detail/hipfile-private.h @@ -5,14 +5,13 @@ #pragma once -#include "hipfile-types.h" -#include "rocfile.h" +#include "hipfile.h" #include #include #include -namespace rocFile { +namespace hipFile { enum class IoType; struct Backend; } @@ -23,9 +22,9 @@ struct Backend; // Ensures that the driver is initialized without incrementing the reference // count if the driver is already initialized. Used by hipFile to ensure its // behaviour is consistent on AMD and NVIDIA -ROCFILE_API -void rocFileEnsureDriverInitPrivate(); +HIPFILE_API +void hipFileEnsureDriverInitPrivate(); -ssize_t rocFileIo(rocFile::IoType type, rocFileHandle_t fh, const void *buffer_base, size_t size, +ssize_t hipFileIo(hipFile::IoType type, hipFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset, hoff_t buffer_offset, - const std::vector> &backends); + const std::vector> &backends); diff --git a/hipfile/src/amd_detail/hipfile-rocfile.cpp b/hipfile/src/amd_detail/hipfile-rocfile.cpp deleted file mode 100644 index 4e2e450e..00000000 --- a/hipfile/src/amd_detail/hipfile-rocfile.cpp +++ /dev/null @@ -1,319 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ - -#include "hipfile-rocfile.h" - -#include - -hipFileOpError_t -toHipFileOpError(rocFileOpError_t status) -{ - switch (status) { - case rocFileSuccess: - return hipFileSuccess; - case rocFileDriverNotInitialized: - return hipFileDriverNotInitialized; - case rocFileDriverInvalidProps: - return hipFileDriverInvalidProps; - case rocFileDriverUnsupportedLimit: - return hipFileDriverUnsupportedLimit; - case rocFileDriverVersionMismatch: - return hipFileDriverVersionMismatch; - case rocFileDriverVersionReadError: - return hipFileDriverVersionReadError; - case rocFileDriverClosing: - return hipFileDriverClosing; - case rocFilePlatformNotSupported: - return hipFilePlatformNotSupported; - case rocFileIONotSupported: - return hipFileIONotSupported; - case rocFileDeviceNotSupported: - return hipFileDeviceNotSupported; - case rocFileDriverError: - return hipFileDriverError; - case rocFileHipDriverError: - return hipFileHipDriverError; - case rocFileHipPointerInvalid: - return hipFileHipPointerInvalid; - case rocFileHipMemoryTypeInvalid: - return hipFileHipMemoryTypeInvalid; - case rocFileHipPointerRangeError: - return hipFileHipPointerRangeError; - case rocFileHipContextMismatch: - return hipFileHipContextMismatch; - case rocFileInvalidMappingSize: - return hipFileInvalidMappingSize; - case rocFileInvalidMappingRange: - return hipFileInvalidMappingRange; - case rocFileInvalidFileType: - return hipFileInvalidFileType; - case rocFileInvalidFileOpenFlag: - return hipFileInvalidFileOpenFlag; - case rocFileDIONotSet: - return hipFileDIONotSet; - case rocFileInvalidValue: - return hipFileInvalidValue; - case rocFileMemoryAlreadyRegistered: - return hipFileMemoryAlreadyRegistered; - case rocFileMemoryNotRegistered: - return hipFileMemoryNotRegistered; - case rocFilePermissionDenied: - return hipFilePermissionDenied; - case rocFileDriverAlreadyOpen: - return hipFileDriverAlreadyOpen; - case rocFileHandleNotRegistered: - return hipFileHandleNotRegistered; - case rocFileHandleAlreadyRegistered: - return hipFileHandleAlreadyRegistered; - case rocFileDeviceNotFound: - return hipFileDeviceNotFound; - case rocFileInternalError: - return hipFileInternalError; - case rocFileGetNewFDFailed: - return hipFileGetNewFDFailed; - case rocFileDriverSetupError: - return hipFileDriverSetupError; - case rocFileIODisabled: - return hipFileIODisabled; - case rocFileBatchSubmitFailed: - return hipFileBatchSubmitFailed; - case rocFileGPUMemoryPinningFailed: - return hipFileGPUMemoryPinningFailed; - case rocFileBatchFull: - return hipFileBatchFull; - case rocFileAsyncNotSupported: - return hipFileAsyncNotSupported; - case rocFileIOMaxError: - return hipFileIOMaxError; - default: - throw std::invalid_argument("Invalid rocFileOpError_t value"); - } -} - -hipFileError_t -toHipFileError(const rocFileError_t &status) -{ - return {toHipFileOpError(status.err), status.hip_drv_err}; -} - -rocFileFileHandleType_t -toRocFileFileHandleType(hipFileFileHandleType_t hf_type) -{ - switch (hf_type) { - case hipFileHandleTypeOpaqueFD: - return rocFileHandleTypeOpaqueFD; - case hipFileHandleTypeOpaqueWin32: - return rocFileHandleTypeOpaqueWin32; - case hipFileHandleTypeUserspaceFS: - return rocFileHandleTypeUserspaceFS; - default: - throw std::invalid_argument("Invalid hipFileFileHandleType_t value"); - } -} - -hipFileDriverProps_t -toHipFileDriverProps(const rocFileDriverProps_t &rf_props) -{ - hipFileDriverProps_t hf_props; - - hf_props.nvfs.major_version = rf_props.nvfs.major_version; - hf_props.nvfs.minor_version = rf_props.nvfs.minor_version; - hf_props.nvfs.poll_thresh_size = rf_props.nvfs.poll_thresh_size; - hf_props.nvfs.max_direct_io_size = rf_props.nvfs.max_direct_io_size; - hf_props.nvfs.driver_status_flags = rf_props.nvfs.driver_status_flags; - hf_props.nvfs.driver_control_flags = rf_props.nvfs.driver_control_flags; - hf_props.feature_flags = rf_props.feature_flags; - hf_props.max_device_cache_size = rf_props.max_device_cache_size; - hf_props.per_buffer_cache_size = rf_props.per_buffer_cache_size; - hf_props.max_device_pinned_mem_size = rf_props.max_device_pinned_mem_size; - hf_props.max_batch_io_count = rf_props.max_batch_io_count; - hf_props.max_batch_io_timeout_msecs = rf_props.max_batch_io_timeout_msecs; - - return hf_props; -} - -rocFileDescr_t -toRocFileDescr(const hipFileDescr_t &fd) -{ - rocFileDescr_t rfd; - - rfd.fs_ops = reinterpret_cast(fd.fs_ops); - - switch (fd.type) { - case hipFileHandleTypeOpaqueFD: - rfd.type = rocFileHandleTypeOpaqueFD; - rfd.handle.fd = fd.handle.fd; - break; - case hipFileHandleTypeOpaqueWin32: - rfd.type = rocFileHandleTypeOpaqueWin32; - rfd.handle.hFile = fd.handle.hFile; - break; - case hipFileHandleTypeUserspaceFS: - rfd.type = rocFileHandleTypeUserspaceFS; - rfd.handle.fd = fd.handle.fd; - break; - default: - throw std::invalid_argument("Invalid hipFileFileHandleType_t value"); - } - - return rfd; -} - -rocFileBatchMode -toRocFileBatchMode(hipFileBatchMode_t hf_batch_mode) -{ - switch (hf_batch_mode) { - case hipFileBatch: - return rocFileBatch; - default: - throw std::invalid_argument("Invalid hipFileBatchMode_t value"); - } -} - -rocFileOpcode_t -toRocFileOpcode(hipFileOpcode_t hf_opcode) -{ - switch (hf_opcode) { - case hipFileBatchRead: - return rocFileBatchRead; - case hipFileBatchWrite: - return rocFileBatchWrite; - default: - throw std::invalid_argument("Invalid hipFileOpcode_t value"); - } -} - -rocFileIOParams_t -toRocFileIOParams(const hipFileIOParams_t &hf_io_params) -{ - rocFileIOParams_t rf_io_params; - - rf_io_params.mode = toRocFileBatchMode(hf_io_params.mode); - rf_io_params.u.batch.devPtr_base = hf_io_params.u.batch.devPtr_base; - rf_io_params.u.batch.file_offset = hf_io_params.u.batch.file_offset; - rf_io_params.u.batch.devPtr_offset = hf_io_params.u.batch.devPtr_offset; - rf_io_params.u.batch.size = hf_io_params.u.batch.size; - rf_io_params.fh = hf_io_params.fh; - rf_io_params.opcode = toRocFileOpcode(hf_io_params.opcode); - rf_io_params.cookie = hf_io_params.cookie; - - return rf_io_params; -} - -hipFileStatus_t -toHipFileStatus(rocFileStatus_t rf_status) -{ - switch (rf_status) { - case rocFileWaiting: - return hipFileWaiting; - case rocFilePending: - return hipFilePending; - case rocFileInvalid: - return hipFileInvalid; - case rocFileCanceled: - return hipFileCanceled; - case rocFileComplete: - return hipFileComplete; - case rocFileTimeout: - return hipFileTimeout; - case rocFileFailed: - return hipFileFailed; - default: - throw std::invalid_argument("Invalid rocFileStatus_t value"); - } -} - -hipFileIOEvents_t -toHipFileIOEvents(const rocFileIOEvents_t &rf_io_event) -{ - hipFileIOEvents_t hf_io_event; - - hf_io_event.cookie = rf_io_event.cookie; - hf_io_event.status = toHipFileStatus(rf_io_event.status); - hf_io_event.ret = rf_io_event.ret; - - return hf_io_event; -} - -rocFileSizeTConfigParameter_t -toRocFileSizeTConfigParameter(hipFileSizeTConfigParameter_t param) -{ - switch (param) { - case hipFileParamProfileStats: - return rocFileParamProfileStats; - case hipFileParamExecutionMaxIOQueueDepth: - return rocFileParamExecutionMaxIOQueueDepth; - case hipFileParamExecutionMaxIOThreads: - return rocFileParamExecutionMaxIOThreads; - case hipFileParamExecutionMinIOThresholdSizeKB: - return rocFileParamExecutionMinIOThresholdSizeKB; - case hipFileParamExecutionMaxRequestParallelism: - return rocFileParamExecutionMaxRequestParallelism; - case hipFileParamPropertiesMaxDirectIOSizeKB: - return rocFileParamPropertiesMaxDirectIOSizeKB; - case hipFileParamPropertiesMaxDeviceCacheSizeKB: - return rocFileParamPropertiesMaxDeviceCacheSizeKB; - case hipFileParamPropertiesPerBufferCacheSizeKB: - return rocFileParamPropertiesPerBufferCacheSizeKB; - case hipFileParamPropertiesMaxDevicePinnedMemSizeKB: - return rocFileParamPropertiesMaxDevicePinnedMemSizeKB; - case hipFileParamPropertiesIOBatchsize: - return rocFileParamPropertiesIOBatchsize; - case hipFileParamPollthresholdSizeKB: - return rocFileParamPollthresholdSizeKB; - case hipFileParamPropertiesBatchIOTimeoutMs: - return rocFileParamPropertiesBatchIOTimeoutMs; - default: - throw std::invalid_argument("Invalid hipFileSizeTConfigParameter_t value"); - } -} - -rocFileBoolConfigParameter_t -toRocFileBoolConfigParameter(hipFileBoolConfigParameter_t param) -{ - switch (param) { - case hipFileParamPropertiesUsePollMode: - return rocFileParamPropertiesUsePollMode; - case hipFileParamPropertiesAllowCompatMode: - return rocFileParamPropertiesAllowCompatMode; - case hipFileParamForceCompatMode: - return rocFileParamForceCompatMode; - case hipFileParamFsMiscApiCheckAggressive: - return rocFileParamFsMiscApiCheckAggressive; - case hipFileParamExecutionParallelIO: - return rocFileParamExecutionParallelIO; - case hipFileParamProfileNvtx: - return rocFileParamProfileNvtx; - case hipFileParamPropertiesAllowSystemMemory: - return rocFileParamPropertiesAllowSystemMemory; - case hipFileParamUsePcip2pdma: - return rocFileParamUsePcip2pdma; - case hipFileParamPreferIOUring: - return rocFileParamPreferIOUring; - case hipFileParamForceOdirectMode: - return rocFileParamForceOdirectMode; - case hipFileParamSkipTopologyDetection: - return rocFileParamSkipTopologyDetection; - case hipFileParamStreamMemopsBypass: - return rocFileParamStreamMemopsBypass; - default: - throw std::invalid_argument("Invalid hipFileBoolConfigParameter_t value"); - } -} - -rocFileStringConfigParameter_t -toRocFileStringConfigParameter(hipFileStringConfigParameter_t param) -{ - switch (param) { - case hipFileParamLoggingLevel: - return rocFileParamLoggingLevel; - case hipFileParamEnvLogfilePath: - return rocFileParamEnvLogfilePath; - case hipFileParamLogDir: - return rocFileParamLogDir; - default: - throw std::invalid_argument("Invalid hipFileStringConfigParameter_t value"); - } -} diff --git a/hipfile/src/amd_detail/hipfile-rocfile.h b/hipfile/src/amd_detail/hipfile-rocfile.h deleted file mode 100644 index ff776a1d..00000000 --- a/hipfile/src/amd_detail/hipfile-rocfile.h +++ /dev/null @@ -1,42 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ - -// Conversions between hipFile and rocFile types - -#pragma once - -#include "hipfile.h" - -#include "rocfile.h" - -// rocFile to hipFile //////////////////////////////////////////////////////// - -hipFileOpError_t toHipFileOpError(rocFileOpError_t status); - -hipFileError_t toHipFileError(const rocFileError_t &status); - -hipFileDriverProps_t toHipFileDriverProps(const rocFileDriverProps_t &rf_props); - -hipFileStatus_t toHipFileStatus(rocFileStatus_t rf_status); - -hipFileIOEvents_t toHipFileIOEvents(const rocFileIOEvents_t &rf_io_event); - -// hipFile to rocFile //////////////////////////////////////////////////////// - -rocFileDescr_t toRocFileDescr(const hipFileDescr_t &fd); - -rocFileFileHandleType_t toRocFileFileHandleType(hipFileFileHandleType_t hf_type); - -rocFileIOParams_t toRocFileIOParams(const hipFileIOParams_t &hf_io_params); - -rocFileOpcode_t toRocFileOpcode(hipFileOpcode_t hf_opcode); - -rocFileBatchMode toRocFileBatchMode(hipFileBatchMode_t hf_batch_mode); - -rocFileSizeTConfigParameter_t toRocFileSizeTConfigParameter(hipFileSizeTConfigParameter_t param); - -rocFileBoolConfigParameter_t toRocFileBoolConfigParameter(hipFileBoolConfigParameter_t param); - -rocFileStringConfigParameter_t toRocFileStringConfigParameter(hipFileStringConfigParameter_t param); diff --git a/hipfile/src/amd_detail/hipfile.cpp b/hipfile/src/amd_detail/hipfile.cpp index f7970a62..8af5ab6b 100644 --- a/hipfile/src/amd_detail/hipfile.cpp +++ b/hipfile/src/amd_detail/hipfile.cpp @@ -3,77 +3,212 @@ * SPDX-License-Identifier: MIT */ -#include "hipfile-rocfile.h" -#include "hipfile-types.h" +#include "backend.h" +#include "batch/batch.h" +#include "buffer.h" +#include "context.h" +#include "file.h" +#include "hip.h" #include "hipfile.h" -#include "rocfile.h" +#include "hipfile-private.h" +#include "hipfile-warnings.h" +#include "io.h" +#include "state.h" +#include "sys.h" #include -#include #include -#include #include -#include +#include +#include #include +#include +#include +using namespace hipFile; using namespace std; -void rocFileEnsureDriverInitPrivate(); +/// Catch C++ exceptions from the hipFile code and convert +/// them into error values that can be returned from public +/// C API calls. +static inline hipFileError_t +handle_exception() noexcept +try { + throw; +} +catch (hipFileError_t e) { + return e; +} +catch (const Hip::RuntimeError &e) { + return {hipFileHipDriverError, e.error}; +} +catch (...) { + return {hipFileInternalError, hipSuccess}; +} hipFileError_t hipFileHandleRegister(hipFileHandle_t *fh, hipFileDescr_t *descr) try { - rocFileHandle_t *rocfile_fh = fh; - rocFileError_t status; - - if (descr) { - auto rocfile_descr = toRocFileDescr(*descr); - status = rocFileHandleRegister(rocfile_fh, &rocfile_descr); - descr->fs_ops = reinterpret_cast(rocfile_descr.fs_ops); - } - else { - status = rocFileHandleRegister(rocfile_fh, nullptr); + if (fh == nullptr || descr == nullptr) { + return {hipFileInvalidValue, hipSuccess}; } - return toHipFileError(status); + switch (descr->type) { + case hipFileHandleTypeOpaqueFD: { + UnregisteredFile uf{descr->handle.fd}; + *fh = Context::get()->registerFile(uf); + return {hipFileSuccess, hipSuccess}; + } + case hipFileHandleTypeOpaqueWin32: + case hipFileHandleTypeUserspaceFS: + default: + return {hipFileIONotSupported, hipSuccess}; + } +} +catch (const FileAlreadyRegistered &) { + return {hipFileHandleAlreadyRegistered, hipSuccess}; } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } void hipFileHandleDeregister(hipFileHandle_t fh) -{ - (void)rocFileHandleDeregister(fh); +try { + if (fh == nullptr) { + return; + } + + Context::get()->deregisterFile(fh); + return; +} +catch (...) { + return; } hipFileError_t hipFileBufRegister(const void *buffer_base, size_t length, int flags) try { - return toHipFileError(rocFileBufRegister(buffer_base, length, flags)); + Context::get()->registerBuffer(buffer_base, length, flags); + return {hipFileSuccess, hipSuccess}; +} +catch (const BufferAlreadyRegistered &) { + return {hipFileMemoryAlreadyRegistered, hipSuccess}; +} +catch (const InvalidMemoryType &) { + return {hipFileHipMemoryTypeInvalid, hipSuccess}; +} +catch (const InvalidPointerRange &) { + return {hipFileHipPointerRangeError, hipSuccess}; +} +catch (const Hip::RuntimeError &e) { + if (e.error == hipErrorInvalidValue) { + return {hipFileInvalidValue, hipSuccess}; + } + return handle_exception(); +} +catch (const std::invalid_argument &) { + return {hipFileInvalidValue, hipSuccess}; } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileBufDeregister(const void *buffer_base) try { - auto error = toHipFileError(rocFileBufDeregister(buffer_base)); - if (error.err == hipFileDriverNotInitialized) { - error.err = hipFileDriverClosing; + Context::get()->deregisterBuffer(buffer_base); + return {hipFileSuccess, hipSuccess}; +} +catch (const DriverNotInitialized &) { + // Mimic cuFile and return hipFileDriverClosing instead + // of hipFileDrivernotInitialized + return {hipFileDriverClosing, hipSuccess}; +} +catch (const BufferNotRegistered &) { + return {hipFileMemoryNotRegistered, hipSuccess}; +} +catch (const BufferOperationsOutstanding &) { + return {hipFileInternalError, hipSuccess}; +} +catch (...) { + return handle_exception(); +} + +/// @brief Get the cached list of backends obtained from DriverState +static const vector> & +getCachedBackends() +{ + HIPFILE_WARN_NO_EXIT_DTOR_OFF + static const auto backends{Context::get()->getBackends()}; + HIPFILE_WARN_NO_EXIT_DTOR_ON + return backends; +} + +ssize_t +hipFileIo(IoType type, hipFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset, + hoff_t buffer_offset, const vector> &backends) +try { + auto [file, buffer] = Context::get()->getFileAndBuffer(fh, buffer_base, size, 0); + int score{-1}; + std::shared_ptr backend{}; + + for (const auto &_backend : backends) { + auto _score = _backend->score(file, buffer, size, file_offset, buffer_offset); + if (score < _score) { + score = _score; + backend = _backend; + } } - return error; + + if (!backend) { + if (backends.size() == 0) { + throw std::runtime_error("No available backends for IO request"); + } + else { + throw std::runtime_error("All backends refused IO request"); + } + } + + return backend->io(type, file, buffer, size, file_offset, buffer_offset); +} +catch (const DriverNotInitialized &) { + return -hipFileDriverNotInitialized; +} +catch (hipFileError_t e) { + return -e.err; +} +catch (const InvalidMemoryType &) { + return -hipFileHipMemoryTypeInvalid; +} +catch (const std::invalid_argument &) { + return -hipFileInvalidValue; +} +catch (const FileNotRegistered &) { + return -hipFileHandleNotRegistered; +} +catch (const Hip::RuntimeError &e) { + return -e.error; +} +catch (const Sys::RuntimeError &e) { + errno = e.error; + return -1; +} +catch (const std::system_error &e) { + errno = e.code().value(); + return -1; } catch (...) { - return {hipFileInternalError, hipSuccess}; + return -hipFileInternalError; } ssize_t hipFileRead(hipFileHandle_t fh, void *buffer_base, size_t size, hoff_t file_offset, hoff_t buffer_offset) { - auto result = rocFileRead(fh, buffer_base, size, file_offset, buffer_offset); - if (result == -rocFileDriverNotInitialized) { + auto result = + hipFileIo(IoType::Read, fh, buffer_base, size, file_offset, buffer_offset, getCachedBackends()); + + if (result == -hipFileDriverNotInitialized) { // Match cuFile behaviour errno = EINVAL; result = -1; @@ -85,8 +220,10 @@ ssize_t hipFileWrite(hipFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset, hoff_t buffer_offset) { - auto result = rocFileWrite(fh, buffer_base, size, file_offset, buffer_offset); - if (result == -rocFileDriverNotInitialized) { + auto result = + hipFileIo(IoType::Write, fh, buffer_base, size, file_offset, buffer_offset, getCachedBackends()); + + if (result == -hipFileDriverNotInitialized) { // Match cuFile behaviour errno = EINVAL; result = -1; @@ -97,264 +234,314 @@ hipFileWrite(hipFileHandle_t fh, const void *buffer_base, size_t size, hoff_t fi hipFileError_t hipFileDriverOpen() try { - return toHipFileError(rocFileDriverOpen()); + Context::get()->incrRefCount(); + + return {hipFileSuccess, hipSuccess}; } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileDriverClose() try { - return toHipFileError(rocFileDriverClose()); + if (Context::get()->getRefCount() > 0) { + Context::get()->decrRefCount(); + return {hipFileSuccess, hipSuccess}; + } + else { + return {hipFileDriverNotInitialized, hipSuccess}; + } } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } int64_t hipFileUseCount() -{ - return rocFileUseCount(); +try { + return Context::get()->getRefCount(); +} +catch (...) { + return -1; } hipFileError_t hipFileDriverGetProperties(hipFileDriverProps_t *props) try { - rocFileError_t status; + (void)props; - if (props) { - rocFileDriverProps_t roc_props; - status = rocFileDriverGetProperties(&roc_props); - if (status.err == rocFileSuccess) { - *props = toHipFileDriverProps(roc_props); - } - } - else { - status = rocFileDriverGetProperties(nullptr); - } - - return toHipFileError(status); + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileDriverSetPollMode(bool poll, size_t poll_threshold_size) try { - return toHipFileError(rocFileDriverSetPollMode(poll, poll_threshold_size)); + (void)poll; + (void)poll_threshold_size; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) try { - return toHipFileError(rocFileDriverSetMaxDirectIOSize(max_direct_io_size)); + (void)max_direct_io_size; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileDriverSetMaxCacheSize(size_t max_cache_size) try { - return toHipFileError(rocFileDriverSetMaxCacheSize(max_cache_size)); + (void)max_cache_size; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) try { - return toHipFileError(rocFileDriverSetMaxPinnedMemSize(max_pinned_size)); + (void)max_pinned_size; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileBatchIOSetUp(hipFileBatchHandle_t *batch_idp, unsigned max_nr) try { - return toHipFileError(rocFileBatchIOSetUp(batch_idp, max_nr)); + if (batch_idp == nullptr) { + return {hipFileInvalidValue, hipSuccess}; + } + + *batch_idp = Context::get()->createBatchContext(max_nr); + + return {hipFileSuccess, hipSuccess}; +} +catch (const std::invalid_argument &) { + return {hipFileInvalidValue, hipSuccess}; } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileBatchIOSubmit(hipFileBatchHandle_t batch_idp, unsigned nr, hipFileIOParams_t *iocbp, unsigned flags) try { - auto rf_batch_idp = batch_idp; - rocFileError_t status; + (void)flags; // Unused at this time. - if (iocbp) { - vector io_params(nr); - - for (unsigned i = 0; i < nr; i++) { - io_params[i] = toRocFileIOParams(iocbp[i]); - } - - status = rocFileBatchIOSubmit(rf_batch_idp, nr, io_params.data(), flags); - } - else { - status = rocFileBatchIOSubmit(rf_batch_idp, nr, nullptr, flags); - } + std::shared_ptr batch_context = Context::get()->getBatchContext(batch_idp); + batch_context->submit_operations(iocbp, nr); - return toHipFileError(status); + return {hipFileSuccess, hipSuccess}; +} +catch (const std::invalid_argument &) { + return {hipFileInvalidValue, hipSuccess}; } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileBatchIOGetStatus(hipFileBatchHandle_t batch_idp, unsigned min_nr, unsigned *nr, hipFileIOEvents_t *iocbp, struct timespec *timeout) try { - auto rf_batch_idp = batch_idp; - rocFileError_t status; - - if (iocbp) { - vector io_events(*nr); - - status = rocFileBatchIOGetStatus(rf_batch_idp, min_nr, nr, io_events.data(), timeout); - - if (status.err == rocFileSuccess) { - for (unsigned i = 0; i < *nr; i++) { - iocbp[i] = toHipFileIOEvents(io_events[i]); - } - } - } - else { - status = rocFileBatchIOGetStatus(rf_batch_idp, min_nr, nr, nullptr, timeout); - } + (void)batch_idp; + (void)min_nr; + (void)nr; + (void)iocbp; + (void)timeout; - return toHipFileError(status); + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileBatchIOCancel(hipFileBatchHandle_t batch_idp) try { - return toHipFileError(rocFileBatchIOCancel(batch_idp)); + (void)batch_idp; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } void hipFileBatchIODestroy(hipFileBatchHandle_t batch_idp) -{ - (void)rocFileBatchIODestroy(batch_idp); +try { + (void)batch_idp; + + throw std::runtime_error("Not Implemented"); +} +catch (...) { + return; } hipFileError_t hipFileReadAsync(hipFileHandle_t fh, void *buffer_base, size_t *size_p, hoff_t *file_offset_p, hoff_t *buffer_offset_p, ssize_t *bytes_read_p, hipStream_t stream) try { - auto result = toHipFileError( - rocFileReadAsync(fh, buffer_base, size_p, file_offset_p, buffer_offset_p, bytes_read_p, stream)); - if (result.err == hipFileDriverNotInitialized) { + if (Context::get()->getRefCount() == 0) { // Match cuFile behaviour - rocFileEnsureDriverInitPrivate(); - result.err = hipFileInvalidValue; + hipFileEnsureDriverInitPrivate(); + return {hipFileInvalidValue, hipSuccess}; } - return result; + + (void)fh; + (void)buffer_base; + (void)size_p; + (void)file_offset_p; + (void)buffer_offset_p; + (void)bytes_read_p; + (void)stream; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileWriteAsync(hipFileHandle_t fh, void *buffer_base, size_t *size_p, hoff_t *file_offset_p, hoff_t *buffer_offset_p, ssize_t *bytes_written_p, hipStream_t stream) try { - auto result = toHipFileError( - rocFileWriteAsync(fh, buffer_base, size_p, file_offset_p, buffer_offset_p, bytes_written_p, stream)); - if (result.err == hipFileDriverNotInitialized) { + if (Context::get()->getRefCount() == 0) { // Match cuFile behaviour - rocFileEnsureDriverInitPrivate(); - result.err = hipFileInvalidValue; + hipFileEnsureDriverInitPrivate(); + return {hipFileInvalidValue, hipSuccess}; } - return result; + + (void)fh; + (void)buffer_base; + (void)size_p; + (void)file_offset_p; + (void)buffer_offset_p; + (void)bytes_written_p; + (void)stream; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileStreamRegister(hipStream_t stream, unsigned flags) try { - return toHipFileError(rocFileStreamRegister(stream, flags)); + Context::get()->registerStream(stream, flags); + return {hipFileSuccess, hipSuccess}; +} +catch (std::invalid_argument &) { + return {hipFileInvalidValue, hipSuccess}; } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileStreamDeregister(hipStream_t stream) try { - return toHipFileError(rocFileStreamDeregister(stream)); + Context::get()->deregisterStream(stream); + return {hipFileSuccess, hipSuccess}; +} +catch (std::invalid_argument &) { + return {hipFileInvalidValue, hipSuccess}; } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } +// *********************************************************************** +// PROPERTIES API +// *********************************************************************** + hipFileError_t hipFileGetParameterSizeT(hipFileSizeTConfigParameter_t param, size_t *value) try { - return toHipFileError(rocFileGetParameterSizeT(toRocFileSizeTConfigParameter(param), value)); + (void)param; + (void)value; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileGetParameterBool(hipFileBoolConfigParameter_t param, bool *value) try { - return toHipFileError(rocFileGetParameterBool(toRocFileBoolConfigParameter(param), value)); + (void)param; + (void)value; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileGetParameterString(hipFileStringConfigParameter_t param, char *desc_str, int len) try { - return toHipFileError(rocFileGetParameterString(toRocFileStringConfigParameter(param), desc_str, len)); + (void)param; + (void)desc_str; + (void)len; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileSetParameterSizeT(hipFileSizeTConfigParameter_t param, size_t value) try { - return toHipFileError(rocFileSetParameterSizeT(toRocFileSizeTConfigParameter(param), value)); + (void)param; + (void)value; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileSetParameterBool(hipFileBoolConfigParameter_t param, bool value) try { - return toHipFileError(rocFileSetParameterBool(toRocFileBoolConfigParameter(param), value)); + (void)param; + (void)value; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } hipFileError_t hipFileSetParameterString(hipFileStringConfigParameter_t param, const char *desc_str) try { - return toHipFileError(rocFileSetParameterString(toRocFileStringConfigParameter(param), desc_str)); + (void)param; + (void)desc_str; + + throw std::runtime_error("Not Implemented"); } catch (...) { - return {hipFileInternalError, hipSuccess}; + return handle_exception(); } diff --git a/rocfile/src/io.h b/hipfile/src/amd_detail/io.h similarity index 89% rename from rocfile/src/io.h rename to hipfile/src/amd_detail/io.h index 0babd96f..4ed0cc51 100644 --- a/rocfile/src/io.h +++ b/hipfile/src/amd_detail/io.h @@ -4,7 +4,7 @@ */ #pragma once -namespace rocFile { +namespace hipFile { enum class IoType { Read, diff --git a/rocfile/src/mountinfo.cpp b/hipfile/src/amd_detail/mountinfo.cpp similarity index 99% rename from rocfile/src/mountinfo.cpp rename to hipfile/src/amd_detail/mountinfo.cpp index 1fb3a143..54af714e 100644 --- a/rocfile/src/mountinfo.cpp +++ b/hipfile/src/amd_detail/mountinfo.cpp @@ -14,7 +14,7 @@ struct libmnt_context; struct libmnt_fs; struct libmnt_table; -namespace rocFile { +namespace hipFile { LibMount::~LibMount() { diff --git a/rocfile/src/mountinfo.h b/hipfile/src/amd_detail/mountinfo.h similarity index 98% rename from rocfile/src/mountinfo.h rename to hipfile/src/amd_detail/mountinfo.h index ccd48c6e..d2d24f5d 100644 --- a/rocfile/src/mountinfo.h +++ b/hipfile/src/amd_detail/mountinfo.h @@ -12,7 +12,7 @@ struct libmnt_context; struct libmnt_fs; struct libmnt_table; -namespace rocFile { +namespace hipFile { /// @brief The filesystem type enum class FilesystemType { diff --git a/rocfile/src/state.cpp b/hipfile/src/amd_detail/state.cpp similarity index 92% rename from rocfile/src/state.cpp rename to hipfile/src/amd_detail/state.cpp index 93e99cca..f4452624 100644 --- a/rocfile/src/state.cpp +++ b/hipfile/src/amd_detail/state.cpp @@ -22,11 +22,11 @@ using std::shared_mutex; using std::shared_ptr; using std::unique_lock; -namespace rocFile { +namespace hipFile { struct Backend; } -namespace rocFile { +namespace hipFile { DriverState::DriverState() : ref_count{0} { @@ -44,20 +44,20 @@ DriverState::~DriverState() // Batch interface // -rocFileBatchHandle_t +hipFileBatchHandle_t DriverState::createBatchContext(unsigned capacity) { return batch_map->createContext(capacity); } void -DriverState::destroyBatchContext(rocFileBatchHandle_t handle) +DriverState::destroyBatchContext(hipFileBatchHandle_t handle) { batch_map->destroyContext(handle); } std::shared_ptr -DriverState::getBatchContext(rocFileBatchHandle_t handle) +DriverState::getBatchContext(hipFileBatchHandle_t handle) { return batch_map->get(handle); } @@ -118,7 +118,7 @@ DriverState::getBuffer(const void *buf, size_t length, int flags) // File interface // -rocFileHandle_t +hipFileHandle_t DriverState::registerFile(const UnregisteredFile &uf) { unique_lock ulock{state_mutex}; @@ -133,7 +133,7 @@ DriverState::registerFile(const UnregisteredFile &uf) } void -DriverState::deregisterFile(rocFileHandle_t fh) +DriverState::deregisterFile(hipFileHandle_t fh) { unique_lock ulock{state_mutex}; @@ -145,7 +145,7 @@ DriverState::deregisterFile(rocFileHandle_t fh) } shared_ptr -DriverState::getFile(rocFileHandle_t fh) +DriverState::getFile(hipFileHandle_t fh) { // NOTE: This mutex only protects the map, so we'll // also need to protect the data @@ -187,11 +187,11 @@ DriverState::getStream(hipStream_t hip_stream) // Buffer and file calls // // These are for reducing the number of lock calls and are implemented -// as needed for the rocFile code +// as needed for the hipFile code // file_buffer_pair -DriverState::getFileAndBuffer(rocFileHandle_t fh, const void *buf, size_t length, int flags) +DriverState::getFileAndBuffer(hipFileHandle_t fh, const void *buf, size_t length, int flags) { // NOTE: This mutex only protects the map, so we'll // also need to protect the data @@ -209,7 +209,7 @@ DriverState::getFileAndBuffer(rocFileHandle_t fh, const void *buf, size_t length // file_buffer_stream_tuple -DriverState::getFileBufferAndStream(rocFileHandle_t fh, const void *buf, size_t length, int flags, +DriverState::getFileBufferAndStream(hipFileHandle_t fh, const void *buf, size_t length, int flags, hipStream_t hipStream) { shared_lock slock{state_mutex}; diff --git a/rocfile/src/state.h b/hipfile/src/amd_detail/state.h similarity index 90% rename from rocfile/src/state.h rename to hipfile/src/amd_detail/state.h index 665df1bd..803ae695 100644 --- a/rocfile/src/state.h +++ b/hipfile/src/amd_detail/state.h @@ -9,7 +9,7 @@ #include "batch/batch.h" #include "buffer.h" #include "file.h" -#include "rocfile.h" +#include "hipfile.h" #include "stream.h" #include @@ -20,11 +20,11 @@ #include #include -namespace rocFile { +namespace hipFile { template struct Context; } -namespace rocFile { +namespace hipFile { /// @brief The driver is not initialized struct DriverNotInitialized : public std::runtime_error { @@ -44,7 +44,7 @@ struct file_buffer_stream_tuple { std::shared_ptr stream; }; -// rocFile "state" +// hipFile "state" // // Important for: // @@ -71,16 +71,16 @@ class DriverState { /// @brief Create a new batch context /// @param [in] capacity Maximum number of outstanding operations that this context can manage /// @return An opaque handle used to reference this new batch context - virtual rocFileBatchHandle_t createBatchContext(unsigned capacity); + virtual hipFileBatchHandle_t createBatchContext(unsigned capacity); /// @brief Destroy a batch context and release all associated resources /// @param [in] handle The handle for the batch context to destroy - virtual void destroyBatchContext(rocFileBatchHandle_t handle); + virtual void destroyBatchContext(hipFileBatchHandle_t handle); /// @brief Get a batch context /// @param [in] handle The opaque handle associated with a batch context /// @return A batch context - virtual std::shared_ptr getBatchContext(rocFileBatchHandle_t handle); + virtual std::shared_ptr getBatchContext(hipFileBatchHandle_t handle); // // Buffer interface @@ -113,20 +113,20 @@ class DriverState { // File interface // - /// @brief Registers a file. Files must be registered before they can be used with rocFile IO APIs + /// @brief Registers a file. Files must be registered before they can be used with hipFile IO APIs /// @param [in] uf An unregistered file - /// @return A handle to be used when calling rocFile IO APIs - virtual rocFileHandle_t registerFile(const UnregisteredFile &uf); + /// @return A handle to be used when calling hipFile IO APIs + virtual hipFileHandle_t registerFile(const UnregisteredFile &uf); /// @brief Deregisters the file associated with the provided file handle /// @param [in] fh The handle of the file to deregister - virtual void deregisterFile(rocFileHandle_t fh); + virtual void deregisterFile(hipFileHandle_t fh); - /// @brief Look up a file given a rocFileHandle_t + /// @brief Look up a file given a hipFileHandle_t /// @param [in] fh The file handle to lookup the file with /// @return If file handle is valid, return a shared pointer to the file, otherwise throw /// FileNotRegistered. - virtual std::shared_ptr getFile(rocFileHandle_t fh); + virtual std::shared_ptr getFile(hipFileHandle_t fh); // // Stream interface @@ -150,7 +150,7 @@ class DriverState { // Buffer and file calls // // These are for reducing the number of lock calls and are implemented - // as needed for the rocFile code + // as needed for the hipFile code // /// @brief Look up a file and registered buffer @@ -164,12 +164,12 @@ class DriverState { /// @param [in] buf Buffer pointer /// @param [in] length Buffer length /// @param [in] flags Buffer flags (unused) - virtual file_buffer_pair getFileAndBuffer(rocFileHandle_t fh, const void *buf, size_t length, int flags); + virtual file_buffer_pair getFileAndBuffer(hipFileHandle_t fh, const void *buf, size_t length, int flags); // // Buffer, file, and stream calls // - virtual file_buffer_stream_tuple getFileBufferAndStream(rocFileHandle_t fh, const void *buf, + virtual file_buffer_stream_tuple getFileBufferAndStream(hipFileHandle_t fh, const void *buf, size_t length, int flags, hipStream_t hipStream); // diff --git a/rocfile/src/stream.cpp b/hipfile/src/amd_detail/stream.cpp similarity index 85% rename from rocfile/src/stream.cpp rename to hipfile/src/amd_detail/stream.cpp index e0e07841..24dfcb47 100644 --- a/rocfile/src/stream.cpp +++ b/hipfile/src/amd_detail/stream.cpp @@ -3,7 +3,7 @@ * SPDX-License-Identifier: MIT */ #include "context.h" -#include "rocfile.h" +#include "hipfile.h" #include "stream.h" #include "sys.h" @@ -13,16 +13,16 @@ #include #include -namespace rocFile { +namespace hipFile { Stream::Stream(const hipStream_t _hip_stream, uint32_t flags) - : hip_stream{_hip_stream}, fixed_buf_offset{(flags & ROCFILE_STREAM_FIXED_BUF_OFFSET) != 0}, - fixed_file_offset{(flags & ROCFILE_STREAM_FIXED_FILE_OFFSET) != 0}, - fixed_io_size{(flags & ROCFILE_STREAM_FIXED_FILE_SIZE) != 0}, - page_aligned{(flags & ROCFILE_STREAM_PAGE_ALIGNED_INPUTS) != 0} + : hip_stream{_hip_stream}, fixed_buf_offset{(flags & HIPFILE_STREAM_FIXED_BUF_OFFSET) != 0}, + fixed_file_offset{(flags & HIPFILE_STREAM_FIXED_FILE_OFFSET) != 0}, + fixed_io_size{(flags & HIPFILE_STREAM_FIXED_FILE_SIZE) != 0}, + page_aligned{(flags & HIPFILE_STREAM_PAGE_ALIGNED_INPUTS) != 0} { - if ((flags & ROCFILE_STREAM_FLAGS_MASK) != flags) { + if ((flags & HIPFILE_STREAM_FLAGS_MASK) != flags) { throw std::invalid_argument("Invalid flags for stream"); } } diff --git a/rocfile/src/stream.h b/hipfile/src/amd_detail/stream.h similarity index 99% rename from rocfile/src/stream.h rename to hipfile/src/amd_detail/stream.h index 073f940a..9c67a446 100644 --- a/rocfile/src/stream.h +++ b/hipfile/src/amd_detail/stream.h @@ -9,7 +9,7 @@ #include #include -namespace rocFile { +namespace hipFile { class IStream { public: diff --git a/rocfile/src/sys.cpp b/hipfile/src/amd_detail/sys.cpp similarity index 98% rename from rocfile/src/sys.cpp rename to hipfile/src/amd_detail/sys.cpp index d7f9768a..898c3b17 100644 --- a/rocfile/src/sys.cpp +++ b/hipfile/src/amd_detail/sys.cpp @@ -11,7 +11,7 @@ #include #include -namespace rocFile { +namespace hipFile { template static inline R diff --git a/rocfile/src/sys.h b/hipfile/src/amd_detail/sys.h similarity index 95% rename from rocfile/src/sys.h rename to hipfile/src/amd_detail/sys.h index 40caf886..240cefd2 100644 --- a/rocfile/src/sys.h +++ b/hipfile/src/amd_detail/sys.h @@ -13,14 +13,14 @@ #include #include -/* sys wraps system APIs used by rocFile which enables unit tests to mock system calls. +/* sys wraps system APIs used by hipFile which enables unit tests to mock system calls. * * The wrapper methods should * - Throw a Sys::RuntimeError if the wrapped function fails * - Use return values instead of out arguments when possible */ -namespace rocFile { +namespace hipFile { struct Sys { virtual ~Sys() = default; diff --git a/hipfile/src/nvidia_detail/hipfile.cpp b/hipfile/src/nvidia_detail/hipfile.cpp index 7e23022c..c3de95fe 100644 --- a/hipfile/src/nvidia_detail/hipfile.cpp +++ b/hipfile/src/nvidia_detail/hipfile.cpp @@ -5,7 +5,6 @@ #include "hipfile.h" #include "hipfile-cufile.h" -#include "hipfile-types.h" #include #include diff --git a/hipfile/test/CMakeLists.txt b/hipfile/test/CMakeLists.txt index dc2a7ea5..d8bfc736 100644 --- a/hipfile/test/CMakeLists.txt +++ b/hipfile/test/CMakeLists.txt @@ -7,17 +7,12 @@ include(AISUseGTest) find_package(Boost COMPONENTS program_options REQUIRED) set(SHARED_SOURCE_FILES - "${CMAKE_SOURCE_DIR}/shared/test/magic-word.cpp" -) - -set(SHARED_TEST_INCLUDE_PATH - "${CMAKE_SOURCE_DIR}/shared/test/" + common/magic-word.cpp ) # These tests do not require a HIP capable GPU. # They should pass on a CPU-only system. set(UNIT_TEST_SOURCE_FILES - main.cpp ) # These tests call into the GPU Driver. @@ -33,15 +28,13 @@ set(SYSTEM_TEST_SOURCE_FILES set(TEST_SYSINCLS ${HIPFILE_INCLUDE_PATH} - ${HIPFILE_TEST_PATH} - ${SHARED_TEST_INCLUDE_PATH} + ${HIPFILE_TEST_INCLUDE_PATH} ) -if(CMAKE_HIP_PLATFORM STREQUAL "nvidia") - list(APPEND UNIT_TEST_SOURCE_FILES hipfile-cufile.cpp) +if(BUILD_NVIDIA_DETAIL) + list(APPEND UNIT_TEST_SOURCE_FILES nvidia_detail/cufile-api-compat.cpp) list(APPEND TEST_SYSINCLS ${HIPFILE_NVIDIA_SOURCE_PATH}) -elseif(CMAKE_HIP_PLATFORM STREQUAL "amd") - list(APPEND UNIT_TEST_SOURCE_FILES hipfile-rocfile.cpp) +else() list(APPEND TEST_SYSINCLS ${HIPFILE_AMD_SOURCE_PATH}) endif() @@ -56,9 +49,6 @@ target_compile_options(hipfile_tests ) target_link_libraries(hipfile_tests PRIVATE GTest::gtest) target_link_libraries(hipfile_tests PRIVATE GTest::gtest_main) -if(CMAKE_HIP_PLATFORM STREQUAL "amd") - target_link_libraries(hipfile_tests PRIVATE rocfile_shared) -endif() ais_gtest_discover_tests( hipfile_tests @@ -74,9 +64,6 @@ ais_add_executable( ) target_link_libraries(hipfile_system_tests PRIVATE GTest::gtest) target_link_libraries(hipfile_system_tests PRIVATE Boost::program_options) -if(CMAKE_HIP_PLATFORM STREQUAL "amd") - target_link_libraries(hipfile_system_tests PRIVATE rocfile_shared) -endif() gtest_discover_tests( hipfile_system_tests @@ -90,12 +77,12 @@ gtest_discover_tests( # ---------------------------------------- ais_add_executable( NAME test_hipfile_basic - SRCS test-hipfile.cpp + SRCS legacy/test-hipfile.cpp DEPS hipfile_shared ) ais_add_executable( NAME test_hipfile_batch - SRCS test-hipfile-batch.cpp + SRCS legacy/test-hipfile-batch.cpp DEPS hipfile_shared ) # ---------------------------------------- diff --git a/hipfile/test/README.md b/hipfile/test/README.md new file mode 100644 index 00000000..c4383974 --- /dev/null +++ b/hipfile/test/README.md @@ -0,0 +1,31 @@ +# hipFile Test Directories + +## `amd_detail` + +AMD-specific tests. Primarily consists of tests of the internals +of hipFile. + +## `common` + +Header and source files that are used by multiple test programs. + +## `legacy` + +A couple of test programs from the early days of hipFile. They are +built but require a bit of setup to run properly and are thus not +in CI. + +These will be removed when we have more extensive testing. + +## `nvidia_detail` + +NVIDIA-specific tests. Currently limited to API compatibility tests. + +## `system` + +hipFile API unit tests that require a GPU go here. These should run on +both AMD and NVIDIA. + +## `unit` + +Doesn't exist yet, but any hipFile unit tests that don't require a GPU would go here. diff --git a/rocfile/test/CMakeLists.txt b/hipfile/test/amd_detail/CMakeLists.txt similarity index 57% rename from rocfile/test/CMakeLists.txt rename to hipfile/test/amd_detail/CMakeLists.txt index caeba059..a651ffa8 100644 --- a/rocfile/test/CMakeLists.txt +++ b/hipfile/test/amd_detail/CMakeLists.txt @@ -6,11 +6,7 @@ include(AISAddExecutable) include(AISUseGTest) set(SHARED_SOURCE_FILES - "${CMAKE_SOURCE_DIR}/shared/test/magic-word.cpp" -) - -set(SHARED_TEST_INCLUDE_PATH - "${CMAKE_SOURCE_DIR}/shared/test/" + "${CMAKE_SOURCE_DIR}/hipfile/test/common/magic-word.cpp" ) set(TEST_SOURCE_FILES @@ -21,38 +17,37 @@ set(TEST_SOURCE_FILES driver.cpp handle.cpp hip.cpp + hipfile-api.cpp fallback.cpp fastpath.cpp - misc.cpp mountinfo.cpp - rocfile.cpp stream.cpp ) set(TEST_SYSINCLS - ${ROCFILE_SOURCE_PATH} - ${ROCFILE_INCLUDE_PATH} - ${ROCFILE_TEST_PATH} - ${SHARED_TEST_INCLUDE_PATH} + ${HIPFILE_AMD_SOURCE_PATH} + ${HIPFILE_INCLUDE_PATH} + ${HIPFILE_TEST_INCLUDE_PATH} + ${HIPFILE_AMD_TEST_PATH} ) ais_add_executable( - NAME rocfile_tests - DEPS rocfile_shared + NAME internal_tests + DEPS hipfile_shared SRCS ${TEST_SOURCE_FILES} ${SHARED_SOURCE_FILES} SYSINCLS ${TEST_SYSINCLS} ) -target_compile_options(rocfile_tests PRIVATE "-UNDEBUG") +target_compile_options(internal_tests PRIVATE "-UNDEBUG") # Add gtest -target_link_libraries(rocfile_tests PRIVATE GTest::gmock) -target_link_libraries(rocfile_tests PRIVATE GTest::gtest) -target_link_libraries(rocfile_tests PRIVATE GTest::gtest_main) +target_link_libraries(internal_tests PRIVATE GTest::gmock) +target_link_libraries(internal_tests PRIVATE GTest::gtest) +target_link_libraries(internal_tests PRIVATE GTest::gtest_main) ais_gtest_discover_tests( - rocfile_tests - PROPERTIES "LABELS;unit;LABELS;rocfile" - TEST_LIST rocfile_unit_tests + internal_tests + PROPERTIES "LABELS;unit;LABELS;internal" + TEST_LIST internal_unit_tests ) # The following tests are concurrency testers. They run for a short @@ -63,24 +58,24 @@ ais_gtest_discover_tests( ais_add_executable( NAME state_mt - DEPS rocfile_shared + DEPS hipfile_shared SRCS "state_mt.cpp" - SYSINCLS ${ROCFILE_SOURCE_PATH} ${ROCFILE_INCLUDE_PATH} + SYSINCLS ${HIPFILE_AMD_SOURCE_PATH} ${HIPFILE_INCLUDE_PATH} ) add_test( NAME state_mt_test COMMAND gdb --batch --quiet -ex run -ex "thread apply all bt full" --return-child-result --args $ ) -set_tests_properties(state_mt_test PROPERTIES LABELS "stress;rocfile") +set_tests_properties(state_mt_test PROPERTIES LABELS "stress;internal") ais_add_executable( NAME batch_mt - DEPS rocfile_shared + DEPS hipfile_shared SRCS "batch/batch_mt.cpp" - SYSINCLS ${ROCFILE_SOURCE_PATH} ${ROCFILE_INCLUDE_PATH} + SYSINCLS ${HIPFILE_AMD_SOURCE_PATH} ${HIPFILE_INCLUDE_PATH} ) add_test( NAME batch_mt_test COMMAND gdb --batch --quiet -ex run -ex "thread apply all bt full" --return-child-result --args $ ) -set_tests_properties(batch_mt_test PROPERTIES LABELS "stress;rocfile") +set_tests_properties(batch_mt_test PROPERTIES LABELS "stress;internal") diff --git a/rocfile/test/async.cpp b/hipfile/test/amd_detail/async.cpp similarity index 86% rename from rocfile/test/async.cpp rename to hipfile/test/amd_detail/async.cpp index fc887fdf..9a0c18bc 100644 --- a/rocfile/test/async.cpp +++ b/hipfile/test/amd_detail/async.cpp @@ -6,6 +6,7 @@ #include "async.h" #include "backend/asyncop-fallback.h" #include "hip.h" +#include "hipfile.h" #include "hipfile-warnings.h" #include "io.h" #include "mbuffer.h" @@ -13,7 +14,6 @@ #include "mhip.h" #include "mstream.h" #include "msys.h" -#include "rocfile.h" #include #include @@ -32,7 +32,7 @@ // warnings HIPFILE_WARN_NO_GLOBAL_CTOR_OFF -using namespace rocFile; +using namespace hipFile; using std::shared_ptr; using ::testing::_; using ::testing::AnyNumber; @@ -47,8 +47,8 @@ using ::testing::WithParamInterface; typedef struct stat stat_t; -struct RocFileAsyncOp : public Test { - RocFileAsyncOp() +struct HipFileAsyncOp : public Test { + HipFileAsyncOp() : buffer{std::make_shared>()}, file{std::make_shared>()}, stream{std::make_shared>()} { @@ -68,21 +68,21 @@ struct RocFileAsyncOp : public Test { shared_ptr stream; }; -struct RocFileAsyncMonitor : RocFileAsyncOp { +struct HipFileAsyncMonitor : HipFileAsyncOp { AsyncMonitor monitor; }; static auto -rocfileFlagsPowerSet() +hipfileFlagsPowerSet() { - return Combine(Values(0, ROCFILE_STREAM_FIXED_BUF_OFFSET), Values(0, ROCFILE_STREAM_FIXED_FILE_OFFSET), - Values(0, ROCFILE_STREAM_FIXED_FILE_SIZE), Values(0, ROCFILE_STREAM_PAGE_ALIGNED_INPUTS)); + return Combine(Values(0, HIPFILE_STREAM_FIXED_BUF_OFFSET), Values(0, HIPFILE_STREAM_FIXED_FILE_OFFSET), + Values(0, HIPFILE_STREAM_FIXED_FILE_SIZE), Values(0, HIPFILE_STREAM_PAGE_ALIGNED_INPUTS)); } -struct RocFileAsyncOpStreamParams - : public RocFileAsyncOp, +struct HipFileAsyncOpStreamParams + : public HipFileAsyncOp, public WithParamInterface> { - RocFileAsyncOpStreamParams() : RocFileAsyncOp{} + HipFileAsyncOpStreamParams() : HipFileAsyncOp{} { auto params = GetParam(); bool fixed_buf_offset = std::get<0>(params) > 0; @@ -102,7 +102,7 @@ struct RocFileAsyncOpStreamParams unsigned flags; }; -TEST_P(RocFileAsyncOpStreamParams, asyncOp_construction_has_correct_variants) +TEST_P(HipFileAsyncOpStreamParams, asyncOp_construction_has_correct_variants) { size_t size = 100; hoff_t file_offset = 0; @@ -112,28 +112,28 @@ TEST_P(RocFileAsyncOpStreamParams, asyncOp_construction_has_correct_variants) &buffer_offset, &bytes_transferred); // Unfixed flags will be pointers - if (flags & ROCFILE_STREAM_FIXED_BUF_OFFSET) { + if (flags & HIPFILE_STREAM_FIXED_BUF_OFFSET) { EXPECT_NO_THROW(std::get(op->buffer_offset)); } else { EXPECT_NO_THROW(std::get(op->buffer_offset)); } - if (flags & ROCFILE_STREAM_FIXED_FILE_OFFSET) { + if (flags & HIPFILE_STREAM_FIXED_FILE_OFFSET) { EXPECT_NO_THROW(std::get(op->file_offset)); } else { EXPECT_NO_THROW(std::get(op->file_offset)); } - if (flags & ROCFILE_STREAM_FIXED_FILE_SIZE) { + if (flags & HIPFILE_STREAM_FIXED_FILE_SIZE) { EXPECT_NO_THROW(std::get(op->size)); } else { EXPECT_NO_THROW(std::get(op->size)); } } -INSTANTIATE_TEST_SUITE_P(StreamSuite, RocFileAsyncOpStreamParams, rocfileFlagsPowerSet()); +INSTANTIATE_TEST_SUITE_P(StreamSuite, HipFileAsyncOpStreamParams, hipfileFlagsPowerSet()); -TEST_F(RocFileAsyncOp, AsyncOpFallback_new_uses_pinned_host_memory) +TEST_F(HipFileAsyncOp, AsyncOpFallback_new_uses_pinned_host_memory) { size_t size = 100; hoff_t file_offset = 0; @@ -149,7 +149,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_new_uses_pinned_host_memory) IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); } -TEST_F(RocFileAsyncOp, AsyncOpFallback_new_failure_throws_bad_alloc) +TEST_F(HipFileAsyncOp, AsyncOpFallback_new_failure_throws_bad_alloc) { size_t size = 100; hoff_t file_offset = 0; @@ -163,7 +163,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_new_failure_throws_bad_alloc) std::bad_alloc); } -TEST_F(RocFileAsyncOp, AsyncOpFallback_bounce_alloc_failure_throws) +TEST_F(HipFileAsyncOp, AsyncOpFallback_bounce_alloc_failure_throws) { size_t size = 100; hoff_t file_offset = 0; @@ -180,7 +180,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_bounce_alloc_failure_throws) Hip::RuntimeError); } -TEST_F(RocFileAsyncOp, AsyncOpFallback_bounce_buffer_deleter_failure_calls_syslog) +TEST_F(HipFileAsyncOp, AsyncOpFallback_bounce_buffer_deleter_failure_calls_syslog) { size_t size = 100; hoff_t file_offset = 0; @@ -198,7 +198,7 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_bounce_buffer_deleter_failure_calls_syslo IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); } -TEST_F(RocFileAsyncOp, AsyncOpFallback_delete_failure_calls_syslog) +TEST_F(HipFileAsyncOp, AsyncOpFallback_delete_failure_calls_syslog) { size_t size = 100; hoff_t file_offset = 0; @@ -216,8 +216,8 @@ TEST_F(RocFileAsyncOp, AsyncOpFallback_delete_failure_calls_syslog) IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred}); } -struct RocFileAsyncOpFallbackFunctions : public RocFileAsyncOp { - RocFileAsyncOpFallbackFunctions() : bounce_buffer{new uint8_t[size]} +struct HipFileAsyncOpFallbackFunctions : public HipFileAsyncOp { + HipFileAsyncOpFallbackFunctions() : bounce_buffer{new uint8_t[size]} { // make_shared uses placement new, which will not use hipHostMalloc/hipHostFree for // AsyncOpFallback @@ -226,7 +226,7 @@ struct RocFileAsyncOpFallbackFunctions : public RocFileAsyncOp { op = std::make_shared(IoType::Read, file, buffer, stream, &size, &file_offset, &buffer_offset, &bytes_transferred); } - ~RocFileAsyncOpFallbackFunctions() override + ~HipFileAsyncOpFallbackFunctions() override { EXPECT_CALL(mhip, hipHostFree(Eq(bounce_buffer.get()))); } @@ -239,19 +239,19 @@ struct RocFileAsyncOpFallbackFunctions : public RocFileAsyncOp { std::shared_ptr op; }; -TEST_F(RocFileAsyncOpFallbackFunctions, bounceBufferHostPtr_returns_pointer) +TEST_F(HipFileAsyncOpFallbackFunctions, bounceBufferHostPtr_returns_pointer) { ASSERT_EQ(op->bounceBufferHostPtr(), bounce_buffer.get()); } -TEST_F(RocFileAsyncOpFallbackFunctions, devPtr_calls_hipHostGetDevicePointer) +TEST_F(HipFileAsyncOpFallbackFunctions, devPtr_calls_hipHostGetDevicePointer) { void *addr = reinterpret_cast(0xABACADBA); EXPECT_CALL(mhip, hipHostGetDevicePointer).WillOnce(Return(addr)); ASSERT_EQ(op->devPtr(), addr); } -TEST_F(RocFileAsyncMonitor, addOp_and_completeOp_with_valid_params_works) +TEST_F(HipFileAsyncMonitor, addOp_and_completeOp_with_valid_params_works) { size_t size = 100; hoff_t file_offset = 0; @@ -264,12 +264,12 @@ TEST_F(RocFileAsyncMonitor, addOp_and_completeOp_with_valid_params_works) EXPECT_NO_THROW(monitor.completeOp(op.get())); } -TEST_F(RocFileAsyncMonitor, completeOp_with_invalid_op_throws) +TEST_F(HipFileAsyncMonitor, completeOp_with_invalid_op_throws) { EXPECT_THROW(monitor.completeOp(reinterpret_cast(0xDEADBEEF)), std::invalid_argument); } -TEST_F(RocFileAsyncMonitor, addOp_without_completeOp_prints_error_on_AsyncMonitor_destruction) +TEST_F(HipFileAsyncMonitor, addOp_without_completeOp_prints_error_on_AsyncMonitor_destruction) { size_t size = 100; hoff_t file_offset = 0; diff --git a/rocfile/test/batch/batch.cpp b/hipfile/test/amd_detail/batch/batch.cpp similarity index 68% rename from rocfile/test/batch/batch.cpp rename to hipfile/test/amd_detail/batch/batch.cpp index c8a219e9..1c1c0044 100644 --- a/rocfile/test/batch/batch.cpp +++ b/hipfile/test/amd_detail/batch/batch.cpp @@ -6,13 +6,13 @@ #include "batch/batch.h" #include "buffer.h" #include "file.h" +#include "hipfile.h" +#include "hipfile-test.h" #include "hipfile-warnings.h" #include "invalid-enum.h" #include "mbuffer.h" #include "mfile.h" #include "mstate.h" -#include "rocfile.h" -#include "rocfile-test.h" #include "state.h" #include @@ -28,16 +28,16 @@ using ::testing::Return; using ::testing::StrictMock; using ::testing::Throw; -using namespace rocFile; +using namespace hipFile; HIPFILE_WARN_NO_GLOBAL_CTOR_OFF -struct RocFileBatch : public RocFileUnopened { +struct HipFileBatch : public HipFileUnopened { BatchContextMap batch_map = BatchContextMap{}; - std::unique_ptr io_params; + std::unique_ptr io_params; std::shared_ptr> default_mock_buffer; std::shared_ptr> default_mock_file; - const rocFileHandle_t file_handle{reinterpret_cast(0xDEADBEEF)}; + const hipFileHandle_t file_handle{reinterpret_cast(0xDEADBEEF)}; void *const buffer_pointer{reinterpret_cast(0x0BADF00D)}; void SetUp() override @@ -49,50 +49,50 @@ struct RocFileBatch : public RocFileUnopened { default_mock_file = std::make_shared>(); EXPECT_CALL(*default_mock_file, getHandle).WillRepeatedly(Return(file_handle)); - io_params = std::make_unique(); + io_params = std::make_unique(); io_params->u.batch.devPtr_base = const_cast(buffer_pointer); io_params->u.batch.size = 1; io_params->fh = file_handle; - io_params->mode = rocFileBatch; - io_params->opcode = rocFileBatchRead; + io_params->mode = hipFileBatch; + io_params->opcode = hipFileBatchRead; } - RocFileBatch() + HipFileBatch() { batch_map.clear(); } }; -TEST_F(RocFileBatch, CreateOperationRead) +TEST_F(HipFileBatch, CreateOperationRead) { - io_params->opcode = rocFileBatchRead; + io_params->opcode = hipFileBatchRead; BatchOperation op = BatchOperation{std::move(io_params), default_mock_buffer, default_mock_file}; } -TEST_F(RocFileBatch, CreateOperationWrite) +TEST_F(HipFileBatch, CreateOperationWrite) { - io_params->opcode = rocFileBatchWrite; + io_params->opcode = hipFileBatchWrite; BatchOperation op = BatchOperation{std::move(io_params), default_mock_buffer, default_mock_file}; } -TEST_F(RocFileBatch, CreateOperationBadBuffer) +TEST_F(HipFileBatch, CreateOperationBadBuffer) { EXPECT_CALL(*default_mock_buffer, getBuffer).WillOnce(Return(reinterpret_cast(0xFACEFEED))); EXPECT_THROW(BatchOperation(std::move(io_params), default_mock_buffer, default_mock_file), std::invalid_argument); } -TEST_F(RocFileBatch, CreateOperationBadFileHandle) +TEST_F(HipFileBatch, CreateOperationBadFileHandle) { EXPECT_CALL(*default_mock_file, getHandle) - .WillOnce(Return(reinterpret_cast(0xFACEFEED))); + .WillOnce(Return(reinterpret_cast(0xFACEFEED))); EXPECT_THROW(BatchOperation(std::move(io_params), default_mock_buffer, default_mock_file), std::invalid_argument); } -TEST_F(RocFileBatch, CreateOperationBadbufferOffsetIsNegative) +TEST_F(HipFileBatch, CreateOperationBadbufferOffsetIsNegative) { io_params->u.batch.devPtr_offset = -1; @@ -100,7 +100,7 @@ TEST_F(RocFileBatch, CreateOperationBadbufferOffsetIsNegative) std::invalid_argument); } -TEST_F(RocFileBatch, CreateOperationBadBufferOffsetExceedsBuffer) +TEST_F(HipFileBatch, CreateOperationBadBufferOffsetExceedsBuffer) { io_params->u.batch.devPtr_offset = 1; @@ -108,7 +108,7 @@ TEST_F(RocFileBatch, CreateOperationBadBufferOffsetExceedsBuffer) std::invalid_argument); } -TEST_F(RocFileBatch, CreateOperationBadOperationLargerThanBuffer) +TEST_F(HipFileBatch, CreateOperationBadOperationLargerThanBuffer) { io_params->u.batch.size = 2; @@ -116,7 +116,7 @@ TEST_F(RocFileBatch, CreateOperationBadOperationLargerThanBuffer) std::invalid_argument); } -TEST_F(RocFileBatch, CreateOperationBadOperationLargerThanBufferWithOffset) +TEST_F(HipFileBatch, CreateOperationBadOperationLargerThanBufferWithOffset) { EXPECT_CALL(*default_mock_buffer, getLength).WillRepeatedly(Return(10)); io_params->u.batch.devPtr_offset = 6; @@ -126,7 +126,7 @@ TEST_F(RocFileBatch, CreateOperationBadOperationLargerThanBufferWithOffset) std::invalid_argument); } -TEST_F(RocFileBatch, CreateOperationBadFileOffsetIsNegative) +TEST_F(HipFileBatch, CreateOperationBadFileOffsetIsNegative) { io_params->u.batch.file_offset = -1; @@ -134,103 +134,103 @@ TEST_F(RocFileBatch, CreateOperationBadFileOffsetIsNegative) std::invalid_argument); } -TEST_F(RocFileBatch, CreateOperationBadOpcode) +TEST_F(HipFileBatch, CreateOperationBadOpcode) { - io_params->opcode = invalidEnum(-1); + io_params->opcode = invalidEnum(-1); EXPECT_THROW(BatchOperation(std::move(io_params), default_mock_buffer, default_mock_file), std::invalid_argument); } -TEST_F(RocFileBatch, CreateOperationBadMode) +TEST_F(HipFileBatch, CreateOperationBadMode) { - io_params->mode = invalidEnum(-1); + io_params->mode = invalidEnum(-1); EXPECT_THROW(BatchOperation(std::move(io_params), default_mock_buffer, default_mock_file), std::invalid_argument); } -TEST_F(RocFileBatch, CreateContext) +TEST_F(HipFileBatch, CreateContext) { - rocFileBatchHandle_t handle = batch_map.createContext(32); + hipFileBatchHandle_t handle = batch_map.createContext(32); ASSERT_NE(nullptr, handle); } -TEST_F(RocFileBatch, CreateTwoContexts) +TEST_F(HipFileBatch, CreateTwoContexts) { - rocFileBatchHandle_t handle1 = batch_map.createContext(1); - rocFileBatchHandle_t handle2 = batch_map.createContext(1); + hipFileBatchHandle_t handle1 = batch_map.createContext(1); + hipFileBatchHandle_t handle2 = batch_map.createContext(1); ASSERT_NE(handle1, handle2); } -TEST_F(RocFileBatch, CreateContextZeroCapacity) +TEST_F(HipFileBatch, CreateContextZeroCapacity) { ASSERT_THROW(batch_map.createContext(0), std::invalid_argument); } -TEST_F(RocFileBatch, CreateContextMaxCapacity) +TEST_F(HipFileBatch, CreateContextMaxCapacity) { - rocFileBatchHandle_t handle = batch_map.createContext(BatchContext::MAX_SIZE); + hipFileBatchHandle_t handle = batch_map.createContext(BatchContext::MAX_SIZE); ASSERT_NE(nullptr, handle); } -TEST_F(RocFileBatch, CreateContextOverCapacity) +TEST_F(HipFileBatch, CreateContextOverCapacity) { ASSERT_THROW(batch_map.createContext(BatchContext::MAX_SIZE + 1), std::invalid_argument); } -TEST_F(RocFileBatch, DestroyContext) +TEST_F(HipFileBatch, DestroyContext) { - rocFileBatchHandle_t handle = batch_map.createContext(1); + hipFileBatchHandle_t handle = batch_map.createContext(1); batch_map.destroyContext(handle); } -TEST_F(RocFileBatch, DestroyMissingContext) +TEST_F(HipFileBatch, DestroyMissingContext) { - ASSERT_THROW(batch_map.destroyContext(reinterpret_cast(1)), InvalidBatchHandle); + ASSERT_THROW(batch_map.destroyContext(reinterpret_cast(1)), InvalidBatchHandle); } -TEST_F(RocFileBatch, DestroyNullptrContext) +TEST_F(HipFileBatch, DestroyNullptrContext) { ASSERT_THROW(batch_map.destroyContext(nullptr), InvalidBatchHandle); } -TEST_F(RocFileBatch, GetContext) +TEST_F(HipFileBatch, GetContext) { - rocFileBatchHandle_t handle = batch_map.createContext(1); + hipFileBatchHandle_t handle = batch_map.createContext(1); std::shared_ptr context = batch_map.get(handle); ASSERT_EQ(handle, context.get()); } -TEST_F(RocFileBatch, GetNullptrContext) +TEST_F(HipFileBatch, GetNullptrContext) { ASSERT_THROW(batch_map.get(nullptr), InvalidBatchHandle); } -TEST_F(RocFileBatch, GetInvalidContext) +TEST_F(HipFileBatch, GetInvalidContext) { - ASSERT_THROW(batch_map.get(reinterpret_cast(0xBAC00001)), InvalidBatchHandle); + ASSERT_THROW(batch_map.get(reinterpret_cast(0xBAC00001)), InvalidBatchHandle); } -TEST_F(RocFileBatch, GetDestroyedContext) +TEST_F(HipFileBatch, GetDestroyedContext) { - rocFileBatchHandle_t handle = batch_map.createContext(1); + hipFileBatchHandle_t handle = batch_map.createContext(1); batch_map.destroyContext(handle); ASSERT_THROW(batch_map.get(handle), InvalidBatchHandle); } -struct RocFileBatchContext : public RocFileUnopened { +struct HipFileBatchContext : public HipFileUnopened { BatchContextMap batch_map = BatchContextMap{}; std::shared_ptr _context; unsigned _context_capacity = 2; std::unique_ptr> mock_driver_state; - rocFileIOParams_t io_params{}; + hipFileIOParams_t io_params{}; std::shared_ptr> default_mock_buffer; int default_mock_buffer_length = 1; std::shared_ptr> default_mock_file; @@ -249,8 +249,8 @@ struct RocFileBatchContext : public RocFileUnopened { io_params.u.batch.devPtr_base = default_mock_buffer->getBuffer(); io_params.u.batch.size = 1; io_params.fh = default_mock_file->getHandle(); - io_params.mode = rocFileBatch; - io_params.opcode = rocFileBatchRead; + io_params.mode = hipFileBatch; + io_params.opcode = hipFileBatchRead; mock_driver_state = std::make_unique>(); _context = batch_map.get(batch_map.createContext(_context_capacity)); @@ -265,23 +265,23 @@ struct RocFileBatchContext : public RocFileUnopened { } }; -TEST_F(RocFileBatchContext, SubmitSingleGoodOp) +TEST_F(HipFileBatchContext, SubmitSingleGoodOp) { _context->submit_operations(&io_params, 1); } -TEST_F(RocFileBatchContext, SubmitZeroOperations) +TEST_F(HipFileBatchContext, SubmitZeroOperations) { _context->submit_operations(nullptr, 0); } -TEST_F(RocFileBatchContext, SubmitOverCapacity) +TEST_F(HipFileBatchContext, SubmitOverCapacity) { // We should fail before we ever try touching the nullptr. ASSERT_THROW(_context->submit_operations(nullptr, _context_capacity + 1), std::invalid_argument); } -TEST_F(RocFileBatchContext, SubmitOverCapacityOverMultipleSubmissions) +TEST_F(HipFileBatchContext, SubmitOverCapacityOverMultipleSubmissions) { // Submit one at a time up to the capacity. // In the future we might care that we are submitting the same operation. @@ -293,58 +293,58 @@ TEST_F(RocFileBatchContext, SubmitOverCapacityOverMultipleSubmissions) ASSERT_THROW(_context->submit_operations(nullptr, 1), std::invalid_argument); } -TEST_F(RocFileBatchContext, SubmitSingleBadBuffer) +TEST_F(HipFileBatchContext, SubmitSingleBadBuffer) { EXPECT_CALL(*mock_driver_state, getFileAndBuffer).WillOnce(Throw(BufferNotRegistered())); ASSERT_THROW(_context->submit_operations(&io_params, 1), BufferNotRegistered); } -TEST_F(RocFileBatchContext, SubmitSingleBadFileHandle) +TEST_F(HipFileBatchContext, SubmitSingleBadFileHandle) { EXPECT_CALL(*mock_driver_state, getFileAndBuffer).WillOnce(Throw(FileNotRegistered())); ASSERT_THROW(_context->submit_operations(&io_params, 1), FileNotRegistered); } // BatchOperation is not mocked. -TEST_F(RocFileBatchContext, SubmitSingleBadParamBufferOffsetNegative) +TEST_F(HipFileBatchContext, SubmitSingleBadParamBufferOffsetNegative) { - rocFileIOParams_t bad_io_params = io_params; + hipFileIOParams_t bad_io_params = io_params; bad_io_params.u.batch.devPtr_offset = -1; ASSERT_THROW(_context->submit_operations(&bad_io_params, 1), std::invalid_argument); } -TEST_F(RocFileBatchContext, SubmitSingleBadParamBufferOffsetTooLarge) +TEST_F(HipFileBatchContext, SubmitSingleBadParamBufferOffsetTooLarge) { - rocFileIOParams_t bad_io_params = io_params; + hipFileIOParams_t bad_io_params = io_params; bad_io_params.u.batch.devPtr_offset = default_mock_buffer_length; ASSERT_THROW(_context->submit_operations(&bad_io_params, 1), std::invalid_argument); } -TEST_F(RocFileBatchContext, SubmitSingleBadParamIOSizeTooLarge) +TEST_F(HipFileBatchContext, SubmitSingleBadParamIOSizeTooLarge) { - rocFileIOParams_t bad_io_params = io_params; + hipFileIOParams_t bad_io_params = io_params; bad_io_params.u.batch.size = static_cast(default_mock_buffer_length + 1); ASSERT_THROW(_context->submit_operations(&bad_io_params, 1), std::invalid_argument); } -TEST_F(RocFileBatchContext, SubmitSingleBadParamFileOffsetNegative) +TEST_F(HipFileBatchContext, SubmitSingleBadParamFileOffsetNegative) { - rocFileIOParams_t bad_io_params = io_params; + hipFileIOParams_t bad_io_params = io_params; bad_io_params.u.batch.file_offset = -1; ASSERT_THROW(_context->submit_operations(&bad_io_params, 1), std::invalid_argument); } -TEST_F(RocFileBatchContext, SubmitSingleBadParamOpcodeInvalid) +TEST_F(HipFileBatchContext, SubmitSingleBadParamOpcodeInvalid) { - rocFileIOParams_t bad_io_params = io_params; - bad_io_params.opcode = invalidEnum(-1); + hipFileIOParams_t bad_io_params = io_params; + bad_io_params.opcode = invalidEnum(-1); ASSERT_THROW(_context->submit_operations(&bad_io_params, 1), std::invalid_argument); } -TEST_F(RocFileBatchContext, SubmitSingleBadParamModeInvalid) +TEST_F(HipFileBatchContext, SubmitSingleBadParamModeInvalid) { - rocFileIOParams_t bad_io_params = io_params; - bad_io_params.mode = invalidEnum(-1); + hipFileIOParams_t bad_io_params = io_params; + bad_io_params.mode = invalidEnum(-1); ASSERT_THROW(_context->submit_operations(&bad_io_params, 1), std::invalid_argument); } diff --git a/rocfile/test/batch/batch_mt.cpp b/hipfile/test/amd_detail/batch/batch_mt.cpp similarity index 94% rename from rocfile/test/batch/batch_mt.cpp rename to hipfile/test/amd_detail/batch/batch_mt.cpp index ba53d80e..c50d4381 100644 --- a/rocfile/test/batch/batch_mt.cpp +++ b/hipfile/test/amd_detail/batch/batch_mt.cpp @@ -3,13 +3,13 @@ * SPDX-License-Identifier: MIT */ -// Multithreading stress test for rocFile's batch context map +// Multithreading stress test for hipFile's batch context map // // Just run the program. It takes no special arguments. // #include "batch/batch.h" -#include "rocfile.h" +#include "hipfile.h" #include #include @@ -23,7 +23,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using namespace std; @@ -47,7 +47,7 @@ thread_function(int id) auto bcm = BatchContextMap{}; - vector handles; + vector handles; // Preload with data for (int i{0}; i < N_PRELOAD; i++) { @@ -80,7 +80,7 @@ thread_function(int id) uniform_int_distribution vec_dist{0, handles.size() - 1}; size_t idx = vec_dist(gen); - rocFileBatchHandle_t bh = handles[idx]; + hipFileBatchHandle_t bh = handles[idx]; bcm.destroyContext(bh); swap(handles[idx], handles.back()); diff --git a/rocfile/test/buffer.cpp b/hipfile/test/amd_detail/buffer.cpp similarity index 67% rename from rocfile/test/buffer.cpp rename to hipfile/test/amd_detail/buffer.cpp index 65f52f61..0eb34880 100644 --- a/rocfile/test/buffer.cpp +++ b/hipfile/test/amd_detail/buffer.cpp @@ -6,10 +6,10 @@ #include "buffer.h" #include "context.h" #include "hip.h" +#include "hipfile.h" +#include "hipfile-test.h" #include "hipfile-warnings.h" #include "mhip.h" -#include "rocfile.h" -#include "rocfile-test.h" #include "state.h" #include @@ -21,7 +21,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using ::testing::StrictMock; @@ -39,14 +39,14 @@ expect_buffer_registration(MHip &mhip, hipMemoryType memory_type) EXPECT_CALL(mhip, hipMemGetAddressRange).WillOnce(testing::Return(range)); } -struct RocFileBuffer : public RocFileOpened { - RocFileBuffer() : nonnull_ptr(reinterpret_cast(0x1)) +struct HipFileBuffer : public HipFileOpened { + HipFileBuffer() : nonnull_ptr(reinterpret_cast(0x1)) { } void *nonnull_ptr; }; -TEST_F(RocFileBuffer, register_internal_supported_hip_memory) +TEST_F(HipFileBuffer, register_internal_supported_hip_memory) { for (const auto memoryType : SupportedHipMemoryTypes) { StrictMock mhip; @@ -55,16 +55,16 @@ TEST_F(RocFileBuffer, register_internal_supported_hip_memory) } } -TEST_F(RocFileBuffer, register_supported_hip_memory) +TEST_F(HipFileBuffer, register_supported_hip_memory) { for (const auto memoryType : SupportedHipMemoryTypes) { StrictMock mhip; expect_buffer_registration(mhip, memoryType); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HIPFILE_SUCCESS); } } -TEST_F(RocFileBuffer, register_internal_unsupported_hip_memory) +TEST_F(HipFileBuffer, register_internal_unsupported_hip_memory) { for (const auto memoryType : UnsupportedHipMemoryTypes) { StrictMock mhip; @@ -75,58 +75,58 @@ TEST_F(RocFileBuffer, register_internal_unsupported_hip_memory) } } -TEST_F(RocFileBuffer, register_unsupported_hip_memory) +TEST_F(HipFileBuffer, register_unsupported_hip_memory) { for (const auto memoryType : UnsupportedHipMemoryTypes) { StrictMock mhip; hipPointerAttribute_t attrs{}; attrs.type = memoryType; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Return(attrs)); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), RocFileOpError(rocFileHipMemoryTypeInvalid)); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HipFileOpError(hipFileHipMemoryTypeInvalid)); } } -TEST_F(RocFileBuffer, register_internal_hip_pointer_get_attributes_error) +TEST_F(HipFileBuffer, register_internal_hip_pointer_get_attributes_error) { StrictMock mhip; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Throw(Hip::RuntimeError(hipErrorUnknown))); ASSERT_THROW(Context::get()->registerBuffer(nonnull_ptr, 0, 0), Hip::RuntimeError); } -TEST_F(RocFileBuffer, register_hip_pointer_get_attributes_error) +TEST_F(HipFileBuffer, register_hip_pointer_get_attributes_error) { StrictMock mhip; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Throw(Hip::RuntimeError(hipErrorUnknown))); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), RocFileHipError(hipErrorUnknown)); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HipFileHipError(hipErrorUnknown)); // hipErrorInvalidValue is handled differently to match the behaviour of cufile EXPECT_CALL(mhip, hipPointerGetAttributes) .WillOnce(testing::Throw(Hip::RuntimeError(hipErrorInvalidValue))); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), RocFileOpError(rocFileInvalidValue)); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HipFileOpError(hipFileInvalidValue)); } -TEST_F(RocFileBuffer, register_internal_already_registered) +TEST_F(HipFileBuffer, register_internal_already_registered) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HIPFILE_SUCCESS); ASSERT_THROW(Context::get()->registerBuffer(nonnull_ptr, 0, 0), BufferAlreadyRegistered); } -TEST_F(RocFileBuffer, register_already_registered) +TEST_F(HipFileBuffer, register_already_registered) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), RocFileOpError(rocFileMemoryAlreadyRegistered)); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HipFileOpError(hipFileMemoryAlreadyRegistered)); } -TEST_F(RocFileBuffer, registerNullPointerReturnsError) +TEST_F(HipFileBuffer, registerNullPointerReturnsError) { - ASSERT_EQ(rocFileBufRegister(nullptr, 0x10000, 0), RocFileOpError(rocFileInvalidValue)); + ASSERT_EQ(hipFileBufRegister(nullptr, 0x10000, 0), HipFileOpError(hipFileInvalidValue)); } -TEST_F(RocFileBuffer, registerOversizeRangeReturnsError) +TEST_F(HipFileBuffer, registerOversizeRangeReturnsError) { StrictMock mhip; HipMemAddressRange range{nonnull_ptr, 100}; @@ -134,21 +134,21 @@ TEST_F(RocFileBuffer, registerOversizeRangeReturnsError) hipPointerAttribute_t attrs{}; attrs.type = hipMemoryTypeDevice; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Return(attrs)); - ASSERT_EQ(rocFileBufRegister(reinterpret_cast(0x1), 101, 0), - RocFileOpError(rocFileHipPointerRangeError)); + ASSERT_EQ(hipFileBufRegister(reinterpret_cast(0x1), 101, 0), + HipFileOpError(hipFileHipPointerRangeError)); } -TEST_F(RocFileBuffer, registerHipMemGetAddressRangeThrowReturnsError) +TEST_F(HipFileBuffer, registerHipMemGetAddressRangeThrowReturnsError) { StrictMock mhip; EXPECT_CALL(mhip, hipMemGetAddressRange).WillOnce(testing::Throw(Hip::RuntimeError(hipErrorNotFound))); hipPointerAttribute_t attrs{}; attrs.type = hipMemoryTypeDevice; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Return(attrs)); - ASSERT_EQ(rocFileBufRegister(reinterpret_cast(0x1), 100, 0), RocFileOpError(rocFileInvalidValue)); + ASSERT_EQ(hipFileBufRegister(reinterpret_cast(0x1), 100, 0), HipFileOpError(hipFileInvalidValue)); } -TEST_F(RocFileBuffer, registerOverflowingRangeReturnsError) +TEST_F(HipFileBuffer, registerOverflowingRangeReturnsError) { StrictMock mhip; HipMemAddressRange range{nonnull_ptr, 100}; @@ -156,21 +156,21 @@ TEST_F(RocFileBuffer, registerOverflowingRangeReturnsError) hipPointerAttribute_t attrs{}; attrs.type = hipMemoryTypeDevice; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Return(attrs)); - ASSERT_EQ(rocFileBufRegister(reinterpret_cast(0xFFFF0000), 0x10000, 0), - RocFileOpError(rocFileHipPointerRangeError)); + ASSERT_EQ(hipFileBufRegister(reinterpret_cast(0xFFFF0000), 0x10000, 0), + HipFileOpError(hipFileHipPointerRangeError)); } -TEST_F(RocFileBuffer, deregister_internal_not_registered) +TEST_F(HipFileBuffer, deregister_internal_not_registered) { ASSERT_THROW(Context::get()->deregisterBuffer(nonnull_ptr), BufferNotRegistered); } -TEST_F(RocFileBuffer, deregister_not_registered) +TEST_F(HipFileBuffer, deregister_not_registered) { - ASSERT_EQ(rocFileBufDeregister(nonnull_ptr), RocFileOpError(rocFileMemoryNotRegistered)); + ASSERT_EQ(hipFileBufDeregister(nonnull_ptr), HipFileOpError(hipFileMemoryNotRegistered)); } -TEST_F(RocFileBuffer, deregister_internal) +TEST_F(HipFileBuffer, deregister_internal) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); @@ -178,15 +178,15 @@ TEST_F(RocFileBuffer, deregister_internal) Context::get()->deregisterBuffer(nonnull_ptr); } -TEST_F(RocFileBuffer, deregister) +TEST_F(HipFileBuffer, deregister) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileBufDeregister(nonnull_ptr), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileBufDeregister(nonnull_ptr), HIPFILE_SUCCESS); } -TEST_F(RocFileBuffer, deregister_internal_duplicate_deregister) +TEST_F(HipFileBuffer, deregister_internal_duplicate_deregister) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); @@ -195,16 +195,16 @@ TEST_F(RocFileBuffer, deregister_internal_duplicate_deregister) ASSERT_THROW(Context::get()->deregisterBuffer(nonnull_ptr), BufferNotRegistered); } -TEST_F(RocFileBuffer, deregister_duplicate_deregister) +TEST_F(HipFileBuffer, deregister_duplicate_deregister) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileBufDeregister(nonnull_ptr), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileBufDeregister(nonnull_ptr), RocFileOpError(rocFileMemoryNotRegistered)); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileBufDeregister(nonnull_ptr), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileBufDeregister(nonnull_ptr), HipFileOpError(hipFileMemoryNotRegistered)); } -TEST_F(RocFileBuffer, deregister_internal_get_prevents_deregister) +TEST_F(HipFileBuffer, deregister_internal_get_prevents_deregister) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); @@ -216,24 +216,24 @@ TEST_F(RocFileBuffer, deregister_internal_get_prevents_deregister) Context::get()->deregisterBuffer(nonnull_ptr); } -TEST_F(RocFileBuffer, deregister_get_prevents_deregister) +TEST_F(HipFileBuffer, deregister_get_prevents_deregister) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HIPFILE_SUCCESS); { auto buffer = Context::get()->getBuffer(nonnull_ptr); - ASSERT_EQ(rocFileBufDeregister(nonnull_ptr), RocFileOpError(rocFileInternalError)); + ASSERT_EQ(hipFileBufDeregister(nonnull_ptr), HipFileOpError(hipFileInternalError)); } - ASSERT_EQ(rocFileBufDeregister(nonnull_ptr), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileBufDeregister(nonnull_ptr), HIPFILE_SUCCESS); } -TEST_F(RocFileBuffer, get_not_registered) +TEST_F(HipFileBuffer, get_not_registered) { ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), BufferNotRegistered); } -TEST_F(RocFileBuffer, get_internal_after_register) +TEST_F(HipFileBuffer, get_internal_after_register) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); @@ -241,15 +241,15 @@ TEST_F(RocFileBuffer, get_internal_after_register) auto buffer = Context::get()->getBuffer(nonnull_ptr); } -TEST_F(RocFileBuffer, get_after_register) +TEST_F(HipFileBuffer, get_after_register) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HIPFILE_SUCCESS); auto buffer = Context::get()->getBuffer(nonnull_ptr); } -TEST_F(RocFileBuffer, get_internal_after_deregister) +TEST_F(HipFileBuffer, get_internal_after_deregister) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); @@ -258,16 +258,16 @@ TEST_F(RocFileBuffer, get_internal_after_deregister) ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), BufferNotRegistered); } -TEST_F(RocFileBuffer, get_after_deregister) +TEST_F(HipFileBuffer, get_after_deregister) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(nonnull_ptr, 0, 0), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileBufDeregister(nonnull_ptr), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileBufRegister(nonnull_ptr, 0, 0), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileBufDeregister(nonnull_ptr), HIPFILE_SUCCESS); ASSERT_THROW(Context::get()->getBuffer(nonnull_ptr), BufferNotRegistered); } -TEST_F(RocFileBuffer, get_buffer_makes_temporary_buffer) +TEST_F(HipFileBuffer, get_buffer_makes_temporary_buffer) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); @@ -275,7 +275,7 @@ TEST_F(RocFileBuffer, get_buffer_makes_temporary_buffer) ASSERT_EQ(buffer.use_count(), 1); } -TEST_F(RocFileBuffer, get_buffer_returns_registered_buffer) +TEST_F(HipFileBuffer, get_buffer_returns_registered_buffer) { StrictMock mhip; expect_buffer_registration(mhip, hipMemoryTypeDevice); @@ -284,7 +284,7 @@ TEST_F(RocFileBuffer, get_buffer_returns_registered_buffer) Context::get()->getBuffer(nonnull_ptr)); } -TEST_F(RocFileBuffer, get_buffer_throws_if_length_larger_than_registered_length) +TEST_F(HipFileBuffer, get_buffer_throws_if_length_larger_than_registered_length) { StrictMock mhip; size_t buffer_length = 0; @@ -294,7 +294,7 @@ TEST_F(RocFileBuffer, get_buffer_throws_if_length_larger_than_registered_length) std::invalid_argument); } -TEST_F(RocFileBuffer, get_buffer_throws_on_getPointerAttributes_error) +TEST_F(HipFileBuffer, get_buffer_throws_on_getPointerAttributes_error) { StrictMock mhip; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Throw(Hip::RuntimeError(hipErrorUnknown))); diff --git a/rocfile/test/context.cpp b/hipfile/test/amd_detail/context.cpp similarity index 82% rename from rocfile/test/context.cpp rename to hipfile/test/amd_detail/context.cpp index 01afb73c..af44655a 100644 --- a/rocfile/test/context.cpp +++ b/hipfile/test/amd_detail/context.cpp @@ -10,19 +10,19 @@ #include #include -using namespace rocFile; +using namespace hipFile; // Put tests inside the macros to suppress the global constructor // warnings HIPFILE_WARN_NO_GLOBAL_CTOR_OFF -TEST(RocFileContext, get_default_context) +TEST(HipFileContext, get_default_context) { Hip *hip = Context::get(); ASSERT_NE(hip, nullptr); } -TEST(RocFileContext, override_works_and_is_reverted_on_destruction) +TEST(HipFileContext, override_works_and_is_reverted_on_destruction) { Hip *orig_context = Context::get(); { @@ -35,7 +35,7 @@ TEST(RocFileContext, override_works_and_is_reverted_on_destruction) ASSERT_EQ(orig_context, hip_context); } -TEST(RocFileContext, default_is_set_when_override_called_before_get) +TEST(HipFileContext, default_is_set_when_override_called_before_get) { Hip *override_context; { @@ -48,7 +48,7 @@ TEST(RocFileContext, default_is_set_when_override_called_before_get) ASSERT_NE(context, nullptr); } -TEST(RocFileContext, context_throws_on_second_override) +TEST(HipFileContext, context_throws_on_second_override) { Hip hip; ContextOverride ho(&hip); diff --git a/hipfile/test/amd_detail/driver.cpp b/hipfile/test/amd_detail/driver.cpp new file mode 100644 index 00000000..636fb79c --- /dev/null +++ b/hipfile/test/amd_detail/driver.cpp @@ -0,0 +1,242 @@ +/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. + * + * SPDX-License-Identifier: MIT + */ + +#include "hipfile.h" +#include "hipfile-test.h" +#include "hipfile-warnings.h" +#include "mhip.h" +#include "mmountinfo.h" +#include "msys.h" +#include "sys.h" + +#include +#include +#include +#include +#include +#include + +using namespace hipFile; +using namespace testing; + +// Put tests inside the macros to suppress the global constructor +// warnings +HIPFILE_WARN_NO_GLOBAL_CTOR_OFF + +struct HipFileDriverAdmin : public HipFileUnopened {}; + +// Ensure that hipFileOpen() and hipFileClose() increment and +// decrement the reference count +TEST_F(HipFileDriverAdmin, OpenClose) +{ + const int64_t N = 10; + + ASSERT_EQ(hipFileUseCount(), 0); + + for (int64_t i = 1; i <= N; i++) { + ASSERT_EQ(hipFileDriverOpen(), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), i); + } + + for (int64_t i = N; i >= 1; i--) { + ASSERT_EQ(hipFileDriverClose(), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), i - 1); + } + + ASSERT_EQ(hipFileUseCount(), 0); +} + +// Ensure hipFileHandleRegister() initializes the driver +// and DOES bump the reference count +TEST_F(HipFileDriverAdmin, HandleRegisterInitsDriver) +{ + StrictMock msys{}; + StrictMock mlibmounthelper{}; + + hipFileHandle_t handle{}; + hipFileDescr_t descr{}; + + descr.handle.fd = 1234; + descr.type = hipFileHandleTypeOpaqueFD; + descr.fs_ops = nullptr; + + ASSERT_EQ(hipFileUseCount(), 0); + expect_file_registration(msys, mlibmounthelper); + ASSERT_EQ(hipFileHandleRegister(&handle, &descr), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 1); +} + +// Ensure hipFileHandleRegister() handles a file descriptor +// of zero (technically a legal POSIX value) and DOES bump +// the reference count +TEST_F(HipFileDriverAdmin, HandleRegisterGoodFD) +{ + StrictMock msys{}; + StrictMock mlibmounthelper{}; + + hipFileHandle_t handle{}; + hipFileDescr_t descr{}; + + descr.handle.fd = 0; + descr.type = hipFileHandleTypeOpaqueFD; + descr.fs_ops = nullptr; + + expect_file_registration(msys, mlibmounthelper); + + ASSERT_EQ(hipFileUseCount(), 0); + ASSERT_EQ(hipFileHandleRegister(&handle, &descr), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 1); + hipFileHandleDeregister(handle); + ASSERT_EQ(hipFileUseCount(), 1); +} + +// Ensure hipFileHandleRegister() fails when passed a negative file +// descriptor and does NOT bump the reference count +TEST_F(HipFileDriverAdmin, HandleRegisterBadFD) +{ + StrictMock msys{}; + StrictMock mlibmounthelper{}; + + hipFileHandle_t handle{}; + hipFileDescr_t descr{}; + + descr.handle.fd = -1; + descr.type = hipFileHandleTypeOpaqueFD; + + EXPECT_CALL(msys, statx).WillOnce(Throw(Sys::RuntimeError(EBADF))); + + ASSERT_EQ(hipFileUseCount(), 0); + ASSERT_NE(hipFileHandleRegister(&handle, &descr), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 0); +} + +// Ensure hipFileHandleDeregister() does NOT bump the driver reference +// count when passed a NULL or unregistered pointer +TEST_F(HipFileDriverAdmin, HandleDeregisterDoesNotInitDriver) +{ + StrictMock msys{}; + StrictMock mlibmounthelper{}; + + // Check NULL + ASSERT_EQ(hipFileUseCount(), 0); + hipFileHandleDeregister(nullptr); + ASSERT_EQ(hipFileUseCount(), 0); + + // Check unregistered handle + hipFileHandle_t handle{}; + + ASSERT_EQ(hipFileUseCount(), 0); + hipFileHandleDeregister(handle); + ASSERT_EQ(hipFileUseCount(), 0); +} + +// Ensure that closing the driver will also close any open handles. This +// is checked by trying to re-register a handle, which should fail if +// the handle were still open. +TEST_F(HipFileDriverAdmin, CloseDeregistersFile) +{ + StrictMock msys{}; + StrictMock mlibmounthelper{}; + + hipFileHandle_t handle{}; + hipFileDescr_t descr{}; + + descr.handle.fd = 1234; + descr.type = hipFileHandleTypeOpaqueFD; + descr.fs_ops = nullptr; + + ASSERT_EQ(hipFileUseCount(), 0); + expect_file_registration(msys, mlibmounthelper); + ASSERT_EQ(hipFileHandleRegister(&handle, &descr), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 1); + ASSERT_EQ(hipFileDriverClose(), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 0); + expect_file_registration(msys, mlibmounthelper); + ASSERT_EQ(hipFileHandleRegister(&handle, &descr), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 1); +} + +// Ensure that registering a buffer increments the driver reference +// count +TEST_F(HipFileDriverAdmin, BufRegisterInitsDriver) +{ + StrictMock mhip; + + expect_buffer_registration(mhip, hipMemoryTypeDevice); + + ASSERT_EQ(hipFileUseCount(), 0); + ASSERT_EQ(hipFileBufRegister(reinterpret_cast(0x1), 0, 0), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 1); +} + +// Ensure that buffer deregistration does not increment the driver +// reference count (the odd error mimics cuFile) +TEST_F(HipFileDriverAdmin, BufDeregisterDoesNotInitDriver) +{ + ASSERT_EQ(hipFileUseCount(), 0); + ASSERT_EQ(hipFileBufDeregister(nullptr), HipFileOpError(hipFileDriverClosing)); + ASSERT_EQ(hipFileUseCount(), 0); +} + +// Ensure that closing the driver also closes open buffers. This is +// checked by attempting to re-register a buffer, which should fail +// if it's already registered. +TEST_F(HipFileDriverAdmin, CloseDeregistersBuffer) +{ + StrictMock mhip; + + ASSERT_EQ(hipFileUseCount(), 0); + expect_buffer_registration(mhip, hipMemoryTypeDevice); + ASSERT_EQ(hipFileBufRegister(reinterpret_cast(0x1), 0, 0), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 1); + + ASSERT_EQ(hipFileDriverClose(), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 0); + + expect_buffer_registration(mhip, hipMemoryTypeDevice); + ASSERT_EQ(hipFileBufRegister(reinterpret_cast(0x1), 0, 0), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileUseCount(), 1); +} + +// Ensure hipFileReadAsync(): +// * Returns hipFileInvalidValue when called w/o a driver init +// * Initializes the driver and returns a reference count of 1 (like cuFile) +TEST_F(HipFileDriverAdmin, ReadAsyncInitsDriver) +{ + ASSERT_EQ(hipFileReadAsync(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr), + HipFileOpError(hipFileInvalidValue)); + ASSERT_EQ(hipFileUseCount(), 1); +} + +// Ensure hipFileWriteAsync(): +// * Returns hipFileInvalidValue when called w/o a driver init +// * Initializes the driver and returns a reference count of 1 (like cuFile) +TEST_F(HipFileDriverAdmin, WriteAsyncInitsDriver) +{ + // Error value matches cuFile + ASSERT_EQ(hipFileWriteAsync(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr), + HipFileOpError(hipFileInvalidValue)); + ASSERT_EQ(hipFileUseCount(), 1); +} + +// Ensure hipFileRead(): +// * Returns -1 (like cuFile) when called w/o a driver init +// * Does NOT initialize the driver and returns a reference count of 0 +TEST_F(HipFileDriverAdmin, ReadDoesNotInitsDriver) +{ + ASSERT_EQ(hipFileRead(nullptr, nullptr, 0, 0, 0), -1); + ASSERT_EQ(hipFileUseCount(), 0); +} + +// Ensure hipFileWrite(): +// * Returns -1 (like cuFile) when called w/o a driver init +// * Does NOT initialize the driver and returns a reference count of 0 +TEST_F(HipFileDriverAdmin, WriteDoesNotInitDriver) +{ + ASSERT_EQ(hipFileWrite(nullptr, nullptr, 0, 0, 0), -1); + ASSERT_EQ(hipFileUseCount(), 0); +} + +HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/rocfile/test/fallback.cpp b/hipfile/test/amd_detail/fallback.cpp similarity index 98% rename from rocfile/test/fallback.cpp rename to hipfile/test/amd_detail/fallback.cpp index a987aa41..560a3faa 100644 --- a/rocfile/test/fallback.cpp +++ b/hipfile/test/amd_detail/fallback.cpp @@ -8,7 +8,8 @@ #include "buffer.h" #include "context.h" #include "hip.h" -#include "hipfile-types.h" +#include "hipfile.h" +#include "hipfile-test.h" #include "hipfile-warnings.h" #include "io.h" #include "mbuffer.h" @@ -16,8 +17,6 @@ #include "mhip.h" #include "mmountinfo.h" #include "msys.h" -#include "rocfile.h" -#include "rocfile-test.h" #include "state.h" #include "sys.h" @@ -39,14 +38,14 @@ #include #include -using namespace rocFile; +using namespace hipFile; using namespace testing; using std::shared_ptr; using ::testing::Return; using ::testing::StrictMock; -namespace rocFile { +namespace hipFile { class IFile; } @@ -111,7 +110,7 @@ contains_expected_data(std::vector &buffer, hoff_t buffer_offset, std:: return true; } -struct FallbackIo : public RocFileOpened { +struct FallbackIo : public HipFileOpened { shared_ptr buffer; std::vector buffer_data; @@ -151,7 +150,7 @@ struct FallbackIo : public RocFileOpened { } }; -TEST(RocFileFallbackBackend, FallbackBackendIsBarelyWillingToHandleDeviceMemory) +TEST(HipFileFallbackBackend, FallbackBackendIsBarelyWillingToHandleDeviceMemory) { auto mfile{std::make_shared>()}; auto mbuffer{std::make_shared>()}; @@ -164,7 +163,7 @@ TEST(RocFileFallbackBackend, FallbackBackendIsBarelyWillingToHandleDeviceMemory) ASSERT_EQ(Fallback().score(mfile, mbuffer, io_size, file_offset, buffer_offset), 0); } -TEST(RocFileFallbackBackend, FallbackBackendRejectsUnsupportedHipMemoryTypes) +TEST(HipFileFallbackBackend, FallbackBackendRejectsUnsupportedHipMemoryTypes) { auto mfile{std::make_shared>()}; size_t io_size{2048}; @@ -189,7 +188,7 @@ struct FallbackParam : ::testing::TestWithParam { StrictMock msys; StrictMock mlibmounthelper; - assert(rocFileDriverOpen() == ROCFILE_SUCCESS); + assert(hipFileDriverOpen() == HIPFILE_SUCCESS); expect_buffer_registration(mhip, hipMemoryTypeDevice); void *buf = reinterpret_cast(0xFEFEFEFE); @@ -203,12 +202,12 @@ struct FallbackParam : ::testing::TestWithParam { ~FallbackParam() override { // Drop the references to the file & buffer so that they can be - // deregistered in rocFileDriverClose() + // deregistered in hipFileDriverClose() file.reset(); buffer.reset(); - while (rocFileUseCount()) { - assert(rocFileDriverClose() == ROCFILE_SUCCESS); + while (hipFileUseCount()) { + assert(hipFileDriverClose() == HIPFILE_SUCCESS); } } diff --git a/rocfile/test/fastpath.cpp b/hipfile/test/amd_detail/fastpath.cpp similarity index 99% rename from rocfile/test/fastpath.cpp rename to hipfile/test/amd_detail/fastpath.cpp index f7c2c01f..9a3ca95d 100644 --- a/rocfile/test/fastpath.cpp +++ b/hipfile/test/amd_detail/fastpath.cpp @@ -5,12 +5,12 @@ #include "backend/fastpath.h" #include "hip.h" +#include "hipfile-test.h" #include "hipfile-warnings.h" #include "io.h" #include "mbuffer.h" #include "mfile.h" #include "mhip.h" -#include "rocfile-test.h" #include #include @@ -25,7 +25,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using namespace testing; using namespace std; @@ -42,7 +42,7 @@ static uint32_t DEFAULT_MEM_ALIGN{4096}; static uint32_t DEFAULT_OFFSET_ALIGN{4096}; #endif -namespace rocFile { +namespace hipFile { inline bool operator==(const hipAmdFileHandle_t &lhs, const hipAmdFileHandle_t &rhs) { diff --git a/rocfile/test/handle.cpp b/hipfile/test/amd_detail/handle.cpp similarity index 57% rename from rocfile/test/handle.cpp rename to hipfile/test/amd_detail/handle.cpp index f9a31bcd..a4ca5a73 100644 --- a/rocfile/test/handle.cpp +++ b/hipfile/test/amd_detail/handle.cpp @@ -5,12 +5,12 @@ #include "context.h" #include "file.h" +#include "hipfile.h" +#include "hipfile-test.h" #include "hipfile-warnings.h" #include "msys.h" #include "mmountinfo.h" #include "mountinfo.h" -#include "rocfile.h" -#include "rocfile-test.h" #include "state.h" #include "sys.h" @@ -24,7 +24,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using namespace testing; // Put tests inside the macros to suppress the global constructor @@ -48,12 +48,12 @@ expect_file_registration(MSys &msys, MLibMountHelper &mlibmounthelper, struct st EXPECT_CALL(mlibmounthelper, getMountInfo).WillOnce(Return(mountinfo)); } -struct RocFileHandle : public RocFileOpened { +struct HipFileHandle : public HipFileOpened { StrictMock msys; StrictMock mlibmounthelper; }; -TEST_F(RocFileHandle, register_handle_internal_linux_fd) +TEST_F(HipFileHandle, register_handle_internal_linux_fd) { int fd{0xBADF00D}; @@ -61,7 +61,7 @@ TEST_F(RocFileHandle, register_handle_internal_linux_fd) ASSERT_NE(Context::get()->registerFile(fd), nullptr); } -TEST_F(RocFileHandle, file_initialization) +TEST_F(HipFileHandle, file_initialization) { int fd{0x12345678}; int status_flags{0x789ABCDE}; @@ -86,7 +86,7 @@ TEST_F(RocFileHandle, file_initialization) file->getMountInfo().value().options.ext4.journaling_mode); } -TEST_F(RocFileHandle, register_handle_internal_linux_fd_already_registered) +TEST_F(HipFileHandle, register_handle_internal_linux_fd_already_registered) { int fd{0xBADF00D}; expect_file_registration(msys, mlibmounthelper); @@ -95,111 +95,110 @@ TEST_F(RocFileHandle, register_handle_internal_linux_fd_already_registered) ASSERT_THROW(Context::get()->registerFile(fd), FileAlreadyRegistered); } -TEST_F(RocFileHandle, register_handle_linux_fd) +TEST_F(HipFileHandle, register_handle_linux_fd) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeOpaqueFD; + rfd.type = hipFileHandleTypeOpaqueFD; rfd.handle.fd = 0xBADF00D; expect_file_registration(msys, mlibmounthelper); - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HIPFILE_SUCCESS); ASSERT_NE(fh, nullptr); } -// If statx() fails during file registration return rocfileInternalError -TEST_F(RocFileHandle, RocfileHandleRegisterStatxError) +// If statx() fails during file registration return hipfileInternalError +TEST_F(HipFileHandle, RocfileHandleRegisterStatxError) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeOpaqueFD; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; + rfd.type = hipFileHandleTypeOpaqueFD; rfd.handle.fd = 0xBADF00D; EXPECT_CALL(msys, statx).WillOnce(Throw(Sys::RuntimeError(EBADF))); - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), RocFileOpError(rocFileInternalError)); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HipFileOpError(hipFileInternalError)); } -// If the fcntl() fails during file registration return rocfileInternalError -TEST_F(RocFileHandle, RocfileHandleRegisterFcntlError) +// If the fcntl() fails during file registration return hipfileInternalError +TEST_F(HipFileHandle, RocfileHandleRegisterFcntlError) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeOpaqueFD; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; + rfd.type = hipFileHandleTypeOpaqueFD; rfd.handle.fd = 0xBADF00D; EXPECT_CALL(msys, statx); EXPECT_CALL(msys, fcntl).WillOnce(Throw(Sys::RuntimeError(EBADF))); - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), RocFileOpError(rocFileInternalError)); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HipFileOpError(hipFileInternalError)); } -// If getting mount information fails during file registration return rocfileInternalError -TEST_F(RocFileHandle, RocfileHandleRegisterLibMountError) +// If getting mount information fails during file registration return hipfileInternalError +TEST_F(HipFileHandle, RocfileHandleRegisterLibMountError) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeOpaqueFD; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; + rfd.type = hipFileHandleTypeOpaqueFD; rfd.handle.fd = 0xBADF00D; EXPECT_CALL(msys, statx); EXPECT_CALL(msys, fcntl); EXPECT_CALL(mlibmounthelper, getMountInfo).WillOnce(Throw(std::runtime_error("error from test"))); - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), RocFileOpError(rocFileInternalError)); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HipFileOpError(hipFileInternalError)); } -TEST_F(RocFileHandle, register_handle_linux_fd_already_registered) +TEST_F(HipFileHandle, register_handle_linux_fd_already_registered) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeOpaqueFD; + rfd.type = hipFileHandleTypeOpaqueFD; rfd.handle.fd = 0xBADF00D; expect_file_registration(msys, mlibmounthelper); - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HIPFILE_SUCCESS); ASSERT_NE(fh, nullptr); expect_file_registration(msys, mlibmounthelper); - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), RocFileOpError(rocFileHandleAlreadyRegistered)); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HipFileOpError(hipFileHandleAlreadyRegistered)); } -TEST_F(RocFileHandle, register_handle_windows_handle_not_supported) +TEST_F(HipFileHandle, register_handle_windows_handle_not_supported) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeOpaqueWin32; + rfd.type = hipFileHandleTypeOpaqueWin32; rfd.handle.fd = 0xBADF00D; - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), RocFileOpError(rocFileIONotSupported)); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HipFileOpError(hipFileIONotSupported)); } -TEST_F(RocFileHandle, register_handle_userspace_fs_not_supported) +TEST_F(HipFileHandle, register_handle_userspace_fs_not_supported) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeUserspaceFS; + rfd.type = hipFileHandleTypeUserspaceFS; rfd.handle.fd = 0xBADF00D; - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), RocFileOpError(rocFileIONotSupported)); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HipFileOpError(hipFileIONotSupported)); } -TEST_F(RocFileHandle, deregister_handle_internal_throws_if_not_registered) +TEST_F(HipFileHandle, deregister_handle_internal_throws_if_not_registered) { - ASSERT_THROW(Context::get()->deregisterFile(reinterpret_cast(0xdeadbeef)), + ASSERT_THROW(Context::get()->deregisterFile(reinterpret_cast(0xdeadbeef)), FileNotRegistered); } -TEST_F(RocFileHandle, deregister_handle_returns_error_if_not_registered) +TEST_F(HipFileHandle, deregister_handle_doesnt_throw_if_not_registered) { - ASSERT_EQ(rocFileHandleDeregister(reinterpret_cast(0xdeadbeef)), - RocFileOpError(rocFileHandleNotRegistered)); + hipFileHandleDeregister(reinterpret_cast(0xdeadbeef)); } -TEST_F(RocFileHandle, deregister_handle_internal) +TEST_F(HipFileHandle, deregister_handle_internal) { expect_file_registration(msys, mlibmounthelper); auto fh = Context::get()->registerFile(0xBADF00D); @@ -207,21 +206,21 @@ TEST_F(RocFileHandle, deregister_handle_internal) ASSERT_THROW(Context::get()->deregisterFile(fh), FileNotRegistered); } -TEST_F(RocFileHandle, deregister_handle) +TEST_F(HipFileHandle, deregister_handle) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeOpaqueFD; + rfd.type = hipFileHandleTypeOpaqueFD; rfd.handle.fd = 0xBADF00D; expect_file_registration(msys, mlibmounthelper); - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileHandleDeregister(fh), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileHandleDeregister(fh), RocFileOpError(rocFileHandleNotRegistered)); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HIPFILE_SUCCESS); + hipFileHandleDeregister(fh); + hipFileHandleDeregister(fh); } -TEST_F(RocFileHandle, deregister_handle_internal_fails_when_operations_are_oustanding) +TEST_F(HipFileHandle, deregister_handle_internal_fails_when_operations_are_oustanding) { expect_file_registration(msys, mlibmounthelper); auto fh = Context::get()->registerFile(0xBADF00D); @@ -232,21 +231,21 @@ TEST_F(RocFileHandle, deregister_handle_internal_fails_when_operations_are_ousta Context::get()->deregisterFile(fh); } -TEST_F(RocFileHandle, deregister_handle_fails_when_operations_are_oustanding) +TEST_F(HipFileHandle, deregister_handle_fails_when_operations_are_oustanding) { - rocFileHandle_t fh{}; - rocFileDescr_t rfd{}; + hipFileHandle_t fh{}; + hipFileDescr_t rfd{}; - rfd.type = rocFileHandleTypeOpaqueFD; + rfd.type = hipFileHandleTypeOpaqueFD; rfd.handle.fd = 0xBADF00D; expect_file_registration(msys, mlibmounthelper); - ASSERT_EQ(rocFileHandleRegister(&fh, &rfd), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileHandleRegister(&fh, &rfd), HIPFILE_SUCCESS); { auto file = Context::get()->getFile(fh); - ASSERT_EQ(rocFileHandleDeregister(fh), RocFileOpError(rocFileInternalError)); + hipFileHandleDeregister(fh); } - ASSERT_EQ(rocFileHandleDeregister(fh), ROCFILE_SUCCESS); + hipFileHandleDeregister(fh); } HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/rocfile/test/hip.cpp b/hipfile/test/amd_detail/hip.cpp similarity index 98% rename from rocfile/test/hip.cpp rename to hipfile/test/amd_detail/hip.cpp index 597384dc..7b1619a6 100644 --- a/rocfile/test/hip.cpp +++ b/hipfile/test/amd_detail/hip.cpp @@ -11,7 +11,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using namespace testing; HIPFILE_WARN_NO_GLOBAL_CTOR_OFF diff --git a/rocfile/test/rocfile.cpp b/hipfile/test/amd_detail/hipfile-api.cpp similarity index 64% rename from rocfile/test/rocfile.cpp rename to hipfile/test/amd_detail/hipfile-api.cpp index bf112657..3b96e896 100644 --- a/rocfile/test/rocfile.cpp +++ b/hipfile/test/amd_detail/hipfile-api.cpp @@ -4,8 +4,8 @@ */ /* - * These tests are integration-level tests against th rocFile API. - * They should test that the various rocFile modules are compatible with + * These tests are integration-level tests against the hipFile API. + * They should test that the various hipFile modules are compatible with * one another. Running IO is not intended to be guaranteed to run here. * * All tests in this file are expected to pass on a CPU-only node. @@ -14,7 +14,9 @@ #include "batch/batch.h" #include "context.h" #include "hip.h" -#include "hipfile-types.h" +#include "hipfile.h" +#include "hipfile-private.h" +#include "hipfile-test.h" #include "hipfile-warnings.h" #include "io.h" #include "mbackend.h" @@ -25,9 +27,6 @@ #include "mmountinfo.h" #include "mstate.h" #include "msys.h" -#include "rocfile-private.h" -#include "rocfile-test.h" -#include "rocfile.h" #include "state.h" #include "sys.h" @@ -41,11 +40,11 @@ #include #include -namespace rocFile { +namespace hipFile { struct Backend; } -using namespace rocFile; +using namespace hipFile; using namespace std; using namespace testing; @@ -53,92 +52,92 @@ using namespace testing; // warnings HIPFILE_WARN_NO_GLOBAL_CTOR_OFF -struct RocFileUnit : public RocFileUnopened { +struct HipFileUnit : public HipFileUnopened { StrictMock mock_state; void SetUp() override { } }; -TEST_F(RocFileUnit, TestRocFileBatchIOSetupSuccess) +TEST_F(HipFileUnit, TestHipFileBatchIOSetupSuccess) { - rocFileBatchHandle_t b_handle = nullptr; - rocFileBatchHandle_t expected_b_handle = reinterpret_cast(0x12345678); + hipFileBatchHandle_t b_handle = nullptr; + hipFileBatchHandle_t expected_b_handle = reinterpret_cast(0x12345678); EXPECT_CALL(mock_state, createBatchContext).WillOnce(Return(expected_b_handle)); - auto result = rocFileBatchIOSetUp(&b_handle, 1); - EXPECT_EQ(result, ROCFILE_SUCCESS); + auto result = hipFileBatchIOSetUp(&b_handle, 1); + EXPECT_EQ(result, HIPFILE_SUCCESS); EXPECT_EQ(b_handle, expected_b_handle); } -TEST_F(RocFileUnit, TestRocFileBatchIOSetupBadArgument) +TEST_F(HipFileUnit, TestHipFileBatchIOSetupBadArgument) { - rocFileBatchHandle_t b_handle = nullptr; + hipFileBatchHandle_t b_handle = nullptr; EXPECT_CALL(mock_state, createBatchContext).WillOnce(Throw(std::invalid_argument(""))); - auto result = rocFileBatchIOSetUp(&b_handle, 0); - EXPECT_EQ(result, ROCFILE_INVALID_VALUE); + auto result = hipFileBatchIOSetUp(&b_handle, 0); + EXPECT_EQ(result, HIPFILE_INVALID_VALUE); EXPECT_EQ(b_handle, nullptr); } -TEST_F(RocFileUnit, TestRocFileBatchIOSetupNullptrHandle) +TEST_F(HipFileUnit, TestHipFileBatchIOSetupNullptrHandle) { - auto result = rocFileBatchIOSetUp(nullptr, 1); - ASSERT_EQ(result, ROCFILE_INVALID_VALUE); + auto result = hipFileBatchIOSetUp(nullptr, 1); + ASSERT_EQ(result, HIPFILE_INVALID_VALUE); } -TEST_F(RocFileUnit, TestRocFileBatchIOSubmitSuccess) +TEST_F(HipFileUnit, TestHipFileBatchIOSubmitSuccess) { - rocFileBatchHandle_t b_handle = reinterpret_cast(0x12345678); - rocFileIOParams_t io_param; + hipFileBatchHandle_t b_handle = reinterpret_cast(0x12345678); + hipFileIOParams_t io_param; std::shared_ptr mock_b_context = std::make_shared(); EXPECT_CALL(mock_state, getBatchContext).WillOnce(Return(mock_b_context)); EXPECT_CALL(*mock_b_context, submit_operations); - auto result = rocFileBatchIOSubmit(b_handle, 1, &io_param, 0); - ASSERT_EQ(result, ROCFILE_SUCCESS); + auto result = hipFileBatchIOSubmit(b_handle, 1, &io_param, 0); + ASSERT_EQ(result, HIPFILE_SUCCESS); } -TEST_F(RocFileUnit, TestRocFileBatchIOSubmitBadHandle) +TEST_F(HipFileUnit, TestHipFileBatchIOSubmitBadHandle) { - rocFileBatchHandle_t b_handle = nullptr; - rocFileIOParams_t io_param; + hipFileBatchHandle_t b_handle = nullptr; + hipFileIOParams_t io_param; std::shared_ptr mock_b_context = std::make_shared(); EXPECT_CALL(mock_state, getBatchContext).WillOnce(Throw(InvalidBatchHandle())); EXPECT_CALL(*mock_b_context, submit_operations).Times(0); - auto result = rocFileBatchIOSubmit(b_handle, 1, &io_param, 0); - rocFileError_t expected_result = {rocFileInvalidValue, hipSuccess}; + auto result = hipFileBatchIOSubmit(b_handle, 1, &io_param, 0); + hipFileError_t expected_result = {hipFileInvalidValue, hipSuccess}; ASSERT_EQ(result, expected_result); } -TEST_F(RocFileUnit, TestRocFileBatchIOSubmitBadArgument) +TEST_F(HipFileUnit, TestHipFileBatchIOSubmitBadArgument) { - rocFileBatchHandle_t b_handle = reinterpret_cast(0x12345678); - rocFileIOParams_t io_param; + hipFileBatchHandle_t b_handle = reinterpret_cast(0x12345678); + hipFileIOParams_t io_param; std::shared_ptr mock_b_context = std::make_shared(); EXPECT_CALL(mock_state, getBatchContext).WillOnce(Return(mock_b_context)); EXPECT_CALL(*mock_b_context, submit_operations).WillOnce(Throw(std::invalid_argument(""))); - auto result = rocFileBatchIOSubmit(b_handle, 1, &io_param, 0); - ASSERT_EQ(result, ROCFILE_INVALID_VALUE); + auto result = hipFileBatchIOSubmit(b_handle, 1, &io_param, 0); + ASSERT_EQ(result, HIPFILE_INVALID_VALUE); } -/// @brief Test rocFileIO function -struct RocFileIoParam : public TestWithParam { - rocFileHandle_t file_handle{}; +/// @brief Test hipFileIO function +struct HipFileIoParam : public TestWithParam { + hipFileHandle_t file_handle{}; void *bufptr{reinterpret_cast(0xDEC0DE)}; size_t buflen{4096}; const void *unreg_bufptr{reinterpret_cast(0xFACEFEED)}; shared_ptr> mbackend{make_shared>()}; vector> mbackends{mbackend}; - RocFileIoParam() + HipFileIoParam() { { StrictMock msys; @@ -155,67 +154,67 @@ struct RocFileIoParam : public TestWithParam { } }; -TEST_P(RocFileIoParam, RocFileIoHandlesHipPointerGetAttributesError) +TEST_P(HipFileIoParam, HipFileIoHandlesHipPointerGetAttributesError) { StrictMock mhip; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Throw(Hip::RuntimeError(hipErrorUnknown))); - ASSERT_EQ(rocFileIo(GetParam(), file_handle, unreg_bufptr, 0, 0, 0, mbackends), -hipErrorUnknown); + ASSERT_EQ(hipFileIo(GetParam(), file_handle, unreg_bufptr, 0, 0, 0, mbackends), -hipErrorUnknown); } -TEST_P(RocFileIoParam, RocFileIoHandlesUnsupportedHipMemoryType) +TEST_P(HipFileIoParam, HipFileIoHandlesUnsupportedHipMemoryType) { for (const auto memoryType : UnsupportedHipMemoryTypes) { StrictMock mhip; hipPointerAttribute_t attrs{}; attrs.type = memoryType; EXPECT_CALL(mhip, hipPointerGetAttributes).WillOnce(testing::Return(attrs)); - ASSERT_EQ(rocFileIo(GetParam(), file_handle, unreg_bufptr, 0, 0, 0, mbackends), - -static_cast(rocFileHipMemoryTypeInvalid)); + ASSERT_EQ(hipFileIo(GetParam(), file_handle, unreg_bufptr, 0, 0, 0, mbackends), + -static_cast(hipFileHipMemoryTypeInvalid)); } } -TEST_P(RocFileIoParam, RocFileIoHandlesInvalidRegisteredBufferLength) +TEST_P(HipFileIoParam, HipFileIoHandlesInvalidRegisteredBufferLength) { StrictMock mhip; - ASSERT_EQ(rocFileIo(GetParam(), file_handle, bufptr, buflen + 1, 0, 0, mbackends), - -static_cast(rocFileInvalidValue)); + ASSERT_EQ(hipFileIo(GetParam(), file_handle, bufptr, buflen + 1, 0, 0, mbackends), + -static_cast(hipFileInvalidValue)); } -TEST_P(RocFileIoParam, RocFileIoHandlesInvalidFileHandle) +TEST_P(HipFileIoParam, HipFileIoHandlesInvalidFileHandle) { - auto invalid_handle{reinterpret_cast(0xdeadbeef)}; - ASSERT_EQ(rocFileIo(GetParam(), invalid_handle, bufptr, 0, 0, 0, mbackends), -rocFileHandleNotRegistered); + auto invalid_handle{reinterpret_cast(0xdeadbeef)}; + ASSERT_EQ(hipFileIo(GetParam(), invalid_handle, bufptr, 0, 0, 0, mbackends), -hipFileHandleNotRegistered); } -TEST_P(RocFileIoParam, RocFileIoHandlesSysRuntimeError) +TEST_P(HipFileIoParam, HipFileIoHandlesSysRuntimeError) { EXPECT_CALL(*mbackend, score).WillOnce(Return(1)); EXPECT_CALL(*mbackend, io).WillOnce(Throw(Sys::RuntimeError(EBADFD))); errno = 0; - ASSERT_EQ(rocFileIo(GetParam(), file_handle, bufptr, buflen, 0, 0, mbackends), -1); + ASSERT_EQ(hipFileIo(GetParam(), file_handle, bufptr, buflen, 0, 0, mbackends), -1); ASSERT_EQ(errno, EBADFD); } -TEST_P(RocFileIoParam, RocFileIoHandlesHipRuntimeError) +TEST_P(HipFileIoParam, HipFileIoHandlesHipRuntimeError) { EXPECT_CALL(*mbackend, score).WillOnce(Return(1)); EXPECT_CALL(*mbackend, io).WillOnce(Throw(Hip::RuntimeError(hipErrorUnknown))); - ASSERT_EQ(rocFileIo(GetParam(), file_handle, bufptr, buflen, 0, 0, mbackends), -hipErrorUnknown); + ASSERT_EQ(hipFileIo(GetParam(), file_handle, bufptr, buflen, 0, 0, mbackends), -hipErrorUnknown); } -TEST_P(RocFileIoParam, RocFileIoHandlesInvalidArgumentError) +TEST_P(HipFileIoParam, HipFileIoHandlesInvalidArgumentError) { EXPECT_CALL(*mbackend, score).WillOnce(Return(1)); EXPECT_CALL(*mbackend, io).WillOnce(Throw(std::invalid_argument(""))); - ASSERT_EQ(rocFileIo(GetParam(), file_handle, bufptr, buflen, 0, 0, mbackends), -rocFileInvalidValue); + ASSERT_EQ(hipFileIo(GetParam(), file_handle, bufptr, buflen, 0, 0, mbackends), -hipFileInvalidValue); } -INSTANTIATE_TEST_SUITE_P(RocFileIo, RocFileIoParam, Values(IoType::Read, IoType::Write)); +INSTANTIATE_TEST_SUITE_P(HipFileIo, HipFileIoParam, Values(IoType::Read, IoType::Write)); -struct RocFileIoBackendSelectionParam : public ::testing::TestWithParam { +struct HipFileIoBackendSelectionParam : public ::testing::TestWithParam { IoType io_type; - rocFileHandle_t handle; + hipFileHandle_t handle; void *buffer; size_t io_size; hoff_t file_offset; @@ -228,8 +227,8 @@ struct RocFileIoBackendSelectionParam : public ::testing::TestWithParam std::shared_ptr> mbe3; StrictMock mds; - RocFileIoBackendSelectionParam() - : io_type{GetParam()}, handle{reinterpret_cast(0xBADF00D)}, + HipFileIoBackendSelectionParam() + : io_type{GetParam()}, handle{reinterpret_cast(0xBADF00D)}, buffer{reinterpret_cast(0xDEADBEEF)}, io_size{1024}, file_offset{32}, buffer_offset{64}, flags{0}, mfile{std::make_shared>()}, mbuffer{std::make_shared>()}, mbe1{std::make_shared>()}, @@ -238,7 +237,7 @@ struct RocFileIoBackendSelectionParam : public ::testing::TestWithParam } }; -TEST_P(RocFileIoBackendSelectionParam, RocFileIoThrowsIfThereAreNoBackends) +TEST_P(HipFileIoBackendSelectionParam, HipFileIoThrowsIfThereAreNoBackends) { auto backends{std::vector>()}; @@ -248,19 +247,19 @@ TEST_P(RocFileIoBackendSelectionParam, RocFileIoThrowsIfThereAreNoBackends) switch (io_type) { case IoType::Read: - ASSERT_EQ(rocFileRead(handle, buffer, io_size, file_offset, buffer_offset), - -rocFileInternalError); + ASSERT_EQ(hipFileRead(handle, buffer, io_size, file_offset, buffer_offset), + -hipFileInternalError); break; case IoType::Write: - ASSERT_EQ(rocFileWrite(handle, buffer, io_size, file_offset, buffer_offset), - -rocFileInternalError); + ASSERT_EQ(hipFileWrite(handle, buffer, io_size, file_offset, buffer_offset), + -hipFileInternalError); break; default: FAIL() << "Unhandled IO Type"; } } -TEST_P(RocFileIoBackendSelectionParam, RocFileIoThrowsIfAllBackendsRejectTheIO) +TEST_P(HipFileIoBackendSelectionParam, HipFileIoThrowsIfAllBackendsRejectTheIO) { std::vector> backends{mbe1, mbe2, mbe3}; @@ -276,19 +275,19 @@ TEST_P(RocFileIoBackendSelectionParam, RocFileIoThrowsIfAllBackendsRejectTheIO) switch (io_type) { case IoType::Read: - ASSERT_EQ(rocFileRead(handle, buffer, io_size, file_offset, buffer_offset), - -rocFileInternalError); + ASSERT_EQ(hipFileRead(handle, buffer, io_size, file_offset, buffer_offset), + -hipFileInternalError); break; case IoType::Write: - ASSERT_EQ(rocFileWrite(handle, buffer, io_size, file_offset, buffer_offset), - -rocFileInternalError); + ASSERT_EQ(hipFileWrite(handle, buffer, io_size, file_offset, buffer_offset), + -hipFileInternalError); break; default: FAIL() << "Unhandled IO Type"; } } -TEST_P(RocFileIoBackendSelectionParam, RocFileIoIssuesIoToHighestScoringBackend) +TEST_P(HipFileIoBackendSelectionParam, HipFileIoIssuesIoToHighestScoringBackend) { std::vector> backends{mbe1, mbe2, mbe3}; @@ -307,20 +306,20 @@ TEST_P(RocFileIoBackendSelectionParam, RocFileIoIssuesIoToHighestScoringBackend) EXPECT_CALL(*mbe2, io(Eq(IoType::Read), Eq(mfile), Eq(mbuffer), io_size, file_offset, buffer_offset)) .WillOnce(Return(io_size)); - ASSERT_EQ(rocFileRead(handle, buffer, io_size, file_offset, buffer_offset), io_size); + ASSERT_EQ(hipFileRead(handle, buffer, io_size, file_offset, buffer_offset), io_size); break; case IoType::Write: EXPECT_CALL(*mbe2, io(Eq(IoType::Write), Eq(mfile), Eq(mbuffer), io_size, file_offset, buffer_offset)) .WillOnce(Return(io_size)); - ASSERT_EQ(rocFileWrite(handle, buffer, io_size, file_offset, buffer_offset), io_size); + ASSERT_EQ(hipFileWrite(handle, buffer, io_size, file_offset, buffer_offset), io_size); break; default: FAIL() << "Unhandled IO Type"; } } -INSTANTIATE_TEST_SUITE_P(RocFileIoBackendSelection, RocFileIoBackendSelectionParam, +INSTANTIATE_TEST_SUITE_P(HipFileIoBackendSelection, HipFileIoBackendSelectionParam, ::testing::Values(IoType::Read, IoType::Write)); HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/rocfile/test/rocfile-test.h b/hipfile/test/amd_detail/hipfile-test.h similarity index 61% rename from rocfile/test/rocfile-test.h rename to hipfile/test/amd_detail/hipfile-test.h index 9d8253b6..b6a72cf8 100644 --- a/rocfile/test/rocfile-test.h +++ b/hipfile/test/amd_detail/hipfile-test.h @@ -5,14 +5,13 @@ #pragma once -// Common rocFile test functionality +// Common hipFile test functionality +#include "hipfile.h" #include "magic-word.h" #include "mhip.h" #include "mmountinfo.h" #include "msys.h" -#include "rocfile-test.h" -#include "rocfile.h" #include #include @@ -24,88 +23,88 @@ // ERRORS AND ERROR HANDLING // *********************************************************************** -// Set a particular rocFile error -constexpr rocFileError_t -RocFileHipError(hipError_t err) +// Set a particular hipFile error +constexpr hipFileError_t +HipFileHipError(hipError_t err) { - return {rocFileHipDriverError, err}; + return {hipFileHipDriverError, err}; } // Set a particular HIP error -constexpr rocFileError_t -RocFileOpError(rocFileOpError_t err) +constexpr hipFileError_t +HipFileOpError(hipFileOpError_t err) { return {err, hipSuccess}; } -// == overload for rocFileError_t values +// == overload for hipFileError_t values inline bool -operator==(const rocFileError_t &lhs, const rocFileError_t &rhs) +operator==(const hipFileError_t &lhs, const hipFileError_t &rhs) { return lhs.err == rhs.err && lhs.hip_drv_err == rhs.hip_drv_err; } -// != overload for rocFileError_t values +// != overload for hipFileError_t values inline bool -operator!=(const rocFileError_t &lhs, const rocFileError_t &rhs) +operator!=(const hipFileError_t &lhs, const hipFileError_t &rhs) { return lhs.err != rhs.err || lhs.hip_drv_err != rhs.hip_drv_err; } -// << overload for rocFileError_t values +// << overload for hipFileError_t values // // Unused in the test code, but kept here for iostream debugging #ifndef NDEBUG #include inline std::ostream & -operator<<(std::ostream &os, const rocFileError_t &rfe) +operator<<(std::ostream &os, const hipFileError_t &rfe) { - return os << "rocFileError_t{ err: " << rfe.err << ", hip_drv_err: " << rfe.hip_drv_err << " }"; + return os << "hipFileError_t{ err: " << rfe.err << ", hip_drv_err: " << rfe.hip_drv_err << " }"; } #endif // Convenience "success" value -inline constexpr rocFileError_t ROCFILE_SUCCESS{rocFileSuccess, hipSuccess}; +inline constexpr hipFileError_t HIPFILE_SUCCESS{hipFileSuccess, hipSuccess}; // Convenience "invalid argument" value -inline constexpr rocFileError_t ROCFILE_INVALID_VALUE{rocFileInvalidValue, hipSuccess}; +inline constexpr hipFileError_t HIPFILE_INVALID_VALUE{hipFileInvalidValue, hipSuccess}; // *********************************************************************** // BASE ERROR CLASSES // *********************************************************************** // Base class for tests that open the driver -struct RocFileOpened : public ::testing::Test { +struct HipFileOpened : public ::testing::Test { - RocFileOpened() + HipFileOpened() { - assert(rocFileUseCount() == 0); - assert(rocFileDriverOpen() == ROCFILE_SUCCESS); + assert(hipFileUseCount() == 0); + assert(hipFileDriverOpen() == HIPFILE_SUCCESS); } - virtual ~RocFileOpened() override + virtual ~HipFileOpened() override { - while (rocFileUseCount()) { - assert(rocFileDriverClose() == ROCFILE_SUCCESS); + while (hipFileUseCount()) { + assert(hipFileDriverClose() == HIPFILE_SUCCESS); } - assert(rocFileUseCount() == 0); + assert(hipFileUseCount() == 0); } }; // Base class for tests that do NOT open the driver -struct RocFileUnopened : public ::testing::Test { +struct HipFileUnopened : public ::testing::Test { - RocFileUnopened() + HipFileUnopened() { - assert(rocFileUseCount() == 0); + assert(hipFileUseCount() == 0); } - virtual ~RocFileUnopened() override + virtual ~HipFileUnopened() override { - while (rocFileUseCount()) { - assert(rocFileDriverClose() == ROCFILE_SUCCESS); + while (hipFileUseCount()) { + assert(hipFileDriverClose() == HIPFILE_SUCCESS); } - assert(rocFileUseCount() == 0); + assert(hipFileUseCount() == 0); } }; @@ -114,7 +113,7 @@ struct RocFileUnopened : public ::testing::Test { // *********************************************************************** /// @brief Set up mocks for buffer registration -void expect_buffer_registration(rocFile::MHip &mhip, hipMemoryType memory_type); +void expect_buffer_registration(hipFile::MHip &mhip, hipMemoryType memory_type); // *********************************************************************** // FILE FUNCTIONALITY @@ -123,13 +122,13 @@ void expect_buffer_registration(rocFile::MHip &mhip, hipMemoryType memory_type); /// @brief Setup mocks for file registration /// /// Mock methods will return default values -void expect_file_registration(rocFile::MSys &msys, rocFile::MLibMountHelper &mlibmounthelper); +void expect_file_registration(hipFile::MSys &msys, hipFile::MLibMountHelper &mlibmounthelper); /// @brief Setup mocks for file registration /// /// Mock methods will return the specified values -void expect_file_registration(rocFile::MSys &msys, rocFile::MLibMountHelper &mlibmounthelper, - struct statx stxbuf, int fcntl_flags, rocFile::MountInfo mountinfo); +void expect_file_registration(hipFile::MSys &msys, hipFile::MLibMountHelper &mlibmounthelper, + struct statx stxbuf, int fcntl_flags, hipFile::MountInfo mountinfo); // *********************************************************************** // ENUM VALUE HELPERS diff --git a/rocfile/test/mbackend.h b/hipfile/test/amd_detail/mbackend.h similarity index 84% rename from rocfile/test/mbackend.h rename to hipfile/test/amd_detail/mbackend.h index d0594de8..ae3517ff 100644 --- a/rocfile/test/mbackend.h +++ b/hipfile/test/amd_detail/mbackend.h @@ -9,13 +9,13 @@ #include -namespace rocFile { +namespace hipFile { struct MBackend : Backend { MOCK_METHOD(int, score, (std::shared_ptr, std::shared_ptr, size_t, hoff_t, hoff_t), (const override)); MOCK_METHOD(ssize_t, io, - (rocFile::IoType type, std::shared_ptr, std::shared_ptr, size_t, hoff_t, + (hipFile::IoType type, std::shared_ptr, std::shared_ptr, size_t, hoff_t, hoff_t), (override)); }; diff --git a/rocfile/test/mbatch.h b/hipfile/test/amd_detail/mbatch.h similarity index 83% rename from rocfile/test/mbatch.h rename to hipfile/test/amd_detail/mbatch.h index 5b637524..c59ba908 100644 --- a/rocfile/test/mbatch.h +++ b/hipfile/test/amd_detail/mbatch.h @@ -13,12 +13,12 @@ * A place to create mocks for the batch module. */ -namespace rocFile { +namespace hipFile { class MBatchContext : public IBatchContext { public: MOCK_METHOD(unsigned, get_capacity, (), (const, noexcept, override)); - MOCK_METHOD(void, submit_operations, (const rocFileIOParams_t *params, const unsigned num_params), + MOCK_METHOD(void, submit_operations, (const hipFileIOParams_t *params, const unsigned num_params), (override)); }; diff --git a/rocfile/test/mbuffer.h b/hipfile/test/amd_detail/mbuffer.h similarity index 98% rename from rocfile/test/mbuffer.h rename to hipfile/test/amd_detail/mbuffer.h index b3308881..2ddf4ae0 100644 --- a/rocfile/test/mbuffer.h +++ b/hipfile/test/amd_detail/mbuffer.h @@ -13,7 +13,7 @@ * A place to create mocks for the buffer module. */ -namespace rocFile { +namespace hipFile { class MBuffer : public IBuffer { public: diff --git a/rocfile/test/mfile.h b/hipfile/test/amd_detail/mfile.h similarity index 70% rename from rocfile/test/mfile.h rename to hipfile/test/amd_detail/mfile.h index 37828379..c8461d9b 100644 --- a/rocfile/test/mfile.h +++ b/hipfile/test/amd_detail/mfile.h @@ -6,7 +6,7 @@ #pragma once #include "file.h" -#include "rocfile.h" +#include "hipfile.h" #include @@ -14,11 +14,11 @@ * A place to create mocks for the file module. */ -namespace rocFile { +namespace hipFile { class MFile : public IFile { public: - MOCK_METHOD(rocFileHandle_t, getHandle, (), (const override)); + MOCK_METHOD(hipFileHandle_t, getHandle, (), (const override)); MOCK_METHOD(int, getFd, (), (const override)); MOCK_METHOD(const struct statx &, getStatx, (), (const, noexcept, override)); MOCK_METHOD(int, getStatusFlags, (), (const override)); @@ -30,9 +30,9 @@ class MFileMap : public FileMap { MFileMap() { } - MOCK_METHOD(rocFileHandle_t, registerFile, (const UnregisteredFile &uf), (override)); - MOCK_METHOD(void, deregisterFile, (rocFileHandle_t fh), (override)); - MOCK_METHOD(std::shared_ptr, getFile, (rocFileHandle_t), (override)); + MOCK_METHOD(hipFileHandle_t, registerFile, (const UnregisteredFile &uf), (override)); + MOCK_METHOD(void, deregisterFile, (hipFileHandle_t fh), (override)); + MOCK_METHOD(std::shared_ptr, getFile, (hipFileHandle_t), (override)); MOCK_METHOD(void, clear, (), (override)); }; diff --git a/rocfile/test/mhip.h b/hipfile/test/amd_detail/mhip.h similarity index 98% rename from rocfile/test/mhip.h rename to hipfile/test/amd_detail/mhip.h index 78647a1e..f8132d5e 100644 --- a/rocfile/test/mhip.h +++ b/hipfile/test/amd_detail/mhip.h @@ -14,7 +14,7 @@ * * Mock implementations for Hip. Enables unit tests to mock HIP APIs. */ -namespace rocFile { +namespace hipFile { struct MHip : Hip { ContextOverride co; diff --git a/rocfile/test/mmountinfo.h b/hipfile/test/amd_detail/mmountinfo.h similarity index 98% rename from rocfile/test/mmountinfo.h rename to hipfile/test/amd_detail/mmountinfo.h index c1b8718b..45edec89 100644 --- a/rocfile/test/mmountinfo.h +++ b/hipfile/test/amd_detail/mmountinfo.h @@ -10,7 +10,7 @@ #include -namespace rocFile { +namespace hipFile { struct MLibMount : LibMount { ContextOverride co; diff --git a/rocfile/test/mountinfo.cpp b/hipfile/test/amd_detail/mountinfo.cpp similarity index 99% rename from rocfile/test/mountinfo.cpp rename to hipfile/test/amd_detail/mountinfo.cpp index 818ee171..c2b967a0 100644 --- a/rocfile/test/mountinfo.cpp +++ b/hipfile/test/amd_detail/mountinfo.cpp @@ -22,7 +22,7 @@ struct libmnt_context; struct libmnt_fs; struct libmnt_table; -using namespace rocFile; +using namespace hipFile; using namespace testing; HIPFILE_WARN_NO_GLOBAL_CTOR_OFF diff --git a/rocfile/test/mstate.h b/hipfile/test/amd_detail/mstate.h similarity index 74% rename from rocfile/test/mstate.h rename to hipfile/test/amd_detail/mstate.h index 86181d8a..63254022 100644 --- a/rocfile/test/mstate.h +++ b/hipfile/test/amd_detail/mstate.h @@ -17,7 +17,7 @@ * A place to create mocks for the DriverState singleton. */ -namespace rocFile { +namespace hipFile { class MDriverState : public DriverState { public: @@ -27,18 +27,18 @@ class MDriverState : public DriverState { { } - MOCK_METHOD(rocFileBatchHandle_t, createBatchContext, (unsigned capacity), (override)); - MOCK_METHOD(void, destroyBatchContext, (rocFileBatchHandle_t handle), (override)); - MOCK_METHOD(std::shared_ptr, getBatchContext, (rocFileBatchHandle_t handle), (override)); + MOCK_METHOD(hipFileBatchHandle_t, createBatchContext, (unsigned capacity), (override)); + MOCK_METHOD(void, destroyBatchContext, (hipFileBatchHandle_t handle), (override)); + MOCK_METHOD(std::shared_ptr, getBatchContext, (hipFileBatchHandle_t handle), (override)); MOCK_METHOD(void, registerBuffer, (const void *buf, size_t length, int flags), (override)); MOCK_METHOD(void, deregisterBuffer, (const void *buf), (override)); MOCK_METHOD(std::shared_ptr, getBuffer, (const void *buf), (override)); MOCK_METHOD(std::shared_ptr, getBuffer, (const void *buf, size_t length, int flags), (override)); - MOCK_METHOD(rocFileHandle_t, registerFile, (const UnregisteredFile &uf), (override)); - MOCK_METHOD(void, deregisterFile, (rocFileHandle_t fh), (override)); - MOCK_METHOD(std::shared_ptr, getFile, (rocFileHandle_t fh), (override)); + MOCK_METHOD(hipFileHandle_t, registerFile, (const UnregisteredFile &uf), (override)); + MOCK_METHOD(void, deregisterFile, (hipFileHandle_t fh), (override)); + MOCK_METHOD(std::shared_ptr, getFile, (hipFileHandle_t fh), (override)); MOCK_METHOD(file_buffer_pair, getFileAndBuffer, - (rocFileHandle_t fh, const void *buf, size_t length, int flags), (override)); + (hipFileHandle_t fh, const void *buf, size_t length, int flags), (override)); MOCK_METHOD(void, incrRefCount, (), (override)); MOCK_METHOD(void, decrRefCount, (), (override)); MOCK_METHOD(int64_t, getRefCount, (), (override, const)); diff --git a/rocfile/test/mstream.h b/hipfile/test/amd_detail/mstream.h similarity index 96% rename from rocfile/test/mstream.h rename to hipfile/test/amd_detail/mstream.h index 72a12016..34411b8b 100644 --- a/rocfile/test/mstream.h +++ b/hipfile/test/amd_detail/mstream.h @@ -6,7 +6,7 @@ #include "stream.h" -namespace rocFile { +namespace hipFile { class MStream : public IStream { public: diff --git a/rocfile/test/msys.h b/hipfile/test/amd_detail/msys.h similarity index 98% rename from rocfile/test/msys.h rename to hipfile/test/amd_detail/msys.h index 26d40ae9..3308e650 100644 --- a/rocfile/test/msys.h +++ b/hipfile/test/amd_detail/msys.h @@ -11,7 +11,7 @@ #include // Mock implementations for Sys. Enables unit tests to mock system calls. -namespace rocFile { +namespace hipFile { struct MSys : Sys { ContextOverride co; diff --git a/rocfile/test/state_mt.cpp b/hipfile/test/amd_detail/state_mt.cpp similarity index 98% rename from rocfile/test/state_mt.cpp rename to hipfile/test/amd_detail/state_mt.cpp index 95f7d9f7..e24e4e66 100644 --- a/rocfile/test/state_mt.cpp +++ b/hipfile/test/amd_detail/state_mt.cpp @@ -3,12 +3,12 @@ * SPDX-License-Identifier: MIT */ -// Multithreading stress test for rocFile's global state +// Multithreading stress test for hipFile's global state // // Just run the program. It takes no special arguments. #include "context.h" -#include "rocfile.h" +#include "hipfile.h" #include "state.h" #include @@ -27,7 +27,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using namespace std; @@ -75,7 +75,7 @@ thread_function(int id) auto *ds = Context::get(); - vector> files; + vector> files; vector buffers; vector hip_streams; diff --git a/rocfile/test/stream.cpp b/hipfile/test/amd_detail/stream.cpp similarity index 61% rename from rocfile/test/stream.cpp rename to hipfile/test/amd_detail/stream.cpp index 27a6c674..42959b7f 100644 --- a/rocfile/test/stream.cpp +++ b/hipfile/test/amd_detail/stream.cpp @@ -3,11 +3,11 @@ * SPDX-License-Identifier: MIT */ +#include "hipfile.h" +#include "hipfile-test.h" #include "hipfile-warnings.h" #include "mhip.h" #include "msys.h" -#include "rocfile.h" -#include "rocfile-test.h" #include "stream.h" #include @@ -18,7 +18,7 @@ #include #include -using namespace rocFile; +using namespace hipFile; using ::testing::StrictMock; @@ -27,16 +27,16 @@ using ::testing::StrictMock; HIPFILE_WARN_NO_GLOBAL_CTOR_OFF static auto -rocFileFlagsPowerSet() +hipFileFlagsPowerSet() { - return ::testing::Combine(::testing::Values(0, ROCFILE_STREAM_FIXED_BUF_OFFSET), - ::testing::Values(0, ROCFILE_STREAM_FIXED_FILE_OFFSET), - ::testing::Values(0, ROCFILE_STREAM_FIXED_FILE_SIZE), - ::testing::Values(0, ROCFILE_STREAM_PAGE_ALIGNED_INPUTS)); + return ::testing::Combine(::testing::Values(0, HIPFILE_STREAM_FIXED_BUF_OFFSET), + ::testing::Values(0, HIPFILE_STREAM_FIXED_FILE_OFFSET), + ::testing::Values(0, HIPFILE_STREAM_FIXED_FILE_SIZE), + ::testing::Values(0, HIPFILE_STREAM_PAGE_ALIGNED_INPUTS)); } -struct RocFileStream : public ::testing::Test { - RocFileStream() +struct HipFileStream : public ::testing::Test { + HipFileStream() { nonnull_stream = reinterpret_cast(1); } @@ -46,11 +46,11 @@ struct RocFileStream : public ::testing::Test { StreamMap stream_map; }; -struct RocFileStreamValidParams - : public RocFileStream, +struct HipFileStreamValidParams + : public HipFileStream, public ::testing::WithParamInterface> { protected: - RocFileStreamValidParams() : RocFileStream{} + HipFileStreamValidParams() : HipFileStream{} { auto params = GetParam(); flags = std::get<0>(params) | std::get<1>(params) | std::get<2>(params) | std::get<3>(params); @@ -58,52 +58,52 @@ struct RocFileStreamValidParams unsigned flags; }; -TEST_P(RocFileStreamValidParams, register_stream_valid_flags_internal) +TEST_P(HipFileStreamValidParams, register_stream_valid_flags_internal) { stream_map.registerStream(nonnull_stream, flags); auto stream = stream_map.getStream(nonnull_stream); ASSERT_EQ(stream->getHipStream(), nonnull_stream); } -INSTANTIATE_TEST_SUITE_P(StreamSuite, RocFileStreamValidParams, rocFileFlagsPowerSet()); +INSTANTIATE_TEST_SUITE_P(StreamSuite, HipFileStreamValidParams, hipFileFlagsPowerSet()); -TEST_F(RocFileStream, get_stream_with_unregistered_stream_works) +TEST_F(HipFileStream, get_stream_with_unregistered_stream_works) { auto stream = stream_map.getStream(nonnull_stream); ASSERT_EQ(nonnull_stream, stream->getHipStream()); } -TEST_F(RocFileStream, register_with_invalid_flags_throws) +TEST_F(HipFileStream, register_with_invalid_flags_throws) { - ASSERT_THROW(stream_map.registerStream(nonnull_stream, ROCFILE_STREAM_FLAGS_MASK + 1), + ASSERT_THROW(stream_map.registerStream(nonnull_stream, HIPFILE_STREAM_FLAGS_MASK + 1), std::invalid_argument); } -TEST_F(RocFileStream, register_twice_throws) +TEST_F(HipFileStream, register_twice_throws) { stream_map.registerStream(nonnull_stream, 0); ASSERT_THROW(stream_map.registerStream(nonnull_stream, 0), std::invalid_argument); } -TEST_F(RocFileStream, deregister_with_registered_stream_works) +TEST_F(HipFileStream, deregister_with_registered_stream_works) { stream_map.registerStream(nonnull_stream, 0); stream_map.deregisterStream(nonnull_stream); } -TEST_F(RocFileStream, deregister_twice_throws) +TEST_F(HipFileStream, deregister_twice_throws) { stream_map.registerStream(nonnull_stream, 0); stream_map.deregisterStream(nonnull_stream); ASSERT_THROW(stream_map.deregisterStream(nonnull_stream), std::invalid_argument); } -TEST_F(RocFileStream, deregister_with_unregistered_stream_throws) +TEST_F(HipFileStream, deregister_with_unregistered_stream_throws) { ASSERT_THROW(stream_map.deregisterStream(nonnull_stream), std::invalid_argument); } -TEST(RocFileStreamDestructor, destructor_with_streams_in_use_logs) +TEST(HipFileStreamDestructor, destructor_with_streams_in_use_logs) { StrictMock mhip; StrictMock msys; @@ -116,8 +116,8 @@ TEST(RocFileStreamDestructor, destructor_with_streams_in_use_logs) } } -struct RocFileStreamExternal : public RocFileOpened { - RocFileStreamExternal() +struct HipFileStreamExternal : public HipFileOpened { + HipFileStreamExternal() { nonnull_stream = reinterpret_cast(1); } @@ -126,15 +126,15 @@ struct RocFileStreamExternal : public RocFileOpened { hipStream_t nonnull_stream; }; -TEST_F(RocFileStreamExternal, register_and_deregister_with_valid_stream_works) +TEST_F(HipFileStreamExternal, register_and_deregister_with_valid_stream_works) { - ASSERT_EQ(rocFileStreamRegister(nonnull_stream, 0), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileStreamDeregister(nonnull_stream), ROCFILE_SUCCESS); + ASSERT_EQ(hipFileStreamRegister(nonnull_stream, 0), HIPFILE_SUCCESS); + ASSERT_EQ(hipFileStreamDeregister(nonnull_stream), HIPFILE_SUCCESS); } -TEST_F(RocFileStreamExternal, deregister_exception_returns_error) +TEST_F(HipFileStreamExternal, deregister_exception_returns_error) { - ASSERT_EQ(rocFileStreamDeregister(nullptr), RocFileOpError(rocFileInvalidValue)); + ASSERT_EQ(hipFileStreamDeregister(nullptr), HipFileOpError(hipFileInvalidValue)); } HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/shared/invalid-enum.h b/hipfile/test/common/invalid-enum.h similarity index 100% rename from shared/invalid-enum.h rename to hipfile/test/common/invalid-enum.h diff --git a/shared/test/magic-word.cpp b/hipfile/test/common/magic-word.cpp similarity index 100% rename from shared/test/magic-word.cpp rename to hipfile/test/common/magic-word.cpp diff --git a/shared/test/magic-word.h b/hipfile/test/common/magic-word.h similarity index 89% rename from shared/test/magic-word.h rename to hipfile/test/common/magic-word.h index 1532a2db..c94f008d 100644 --- a/shared/test/magic-word.h +++ b/hipfile/test/common/magic-word.h @@ -22,8 +22,8 @@ static const char *message = "Ah ah ah, you didn't say the magic word!\n" " | /\n" " \\ /\n" "\n" - "hipFile/rocFile tests should be run using ctest. ctest runs each test in\n" - "an isolated process, which prevents side effects from affecting subsequent\n" + "hipFile tests should be run using ctest. ctest runs each test in an\n" + "isolated process, which prevents side effects from affecting subsequent\n" "tests. Running the test binaries directly may result in test errors if\n" "running multiple tests.\n"; diff --git a/hipfile/test/test-common.h b/hipfile/test/common/test-common.h similarity index 100% rename from hipfile/test/test-common.h rename to hipfile/test/common/test-common.h diff --git a/shared/test-options.h b/hipfile/test/common/test-options.h similarity index 100% rename from shared/test-options.h rename to hipfile/test/common/test-options.h diff --git a/hipfile/test/test-shared-fixtures.h b/hipfile/test/common/test-shared-fixtures.h similarity index 100% rename from hipfile/test/test-shared-fixtures.h rename to hipfile/test/common/test-shared-fixtures.h diff --git a/hipfile/test/hipfile-rocfile.cpp b/hipfile/test/hipfile-rocfile.cpp deleted file mode 100644 index 78a46f68..00000000 --- a/hipfile/test/hipfile-rocfile.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ - -#include "hipfile.h" -#include "hipfile-rocfile.h" -#include "hipfile-warnings.h" -#include "invalid-enum.h" -#include "rocfile.h" -#include "test-common.h" - -#include -#include -#include -#include - -// Put tests inside the macros to suppress the global constructor -// warnings -HIPFILE_WARN_NO_GLOBAL_CTOR_OFF - -TEST(ToHipFile, hipFileOpError_t) -{ - ASSERT_THROW(toHipFileOpError(invalidEnum(hipFileSuccess - 1)), std::invalid_argument); - ASSERT_THROW(toHipFileOpError(invalidEnum(hipFileSuccess + 1)), std::invalid_argument); - - ASSERT_THROW(toHipFileOpError(invalidEnum(HIPFILE_BASE_ERR)), std::invalid_argument); - - ASSERT_THROW(toHipFileOpError(invalidEnum(HIPFILE_BASE_ERR + 21)), - std::invalid_argument); - ASSERT_THROW(toHipFileOpError(invalidEnum(HIPFILE_BASE_ERR + 32)), - std::invalid_argument); - -#define r2h(R, H) ASSERT_EQ(toHipFileOpError((R)), (H)) - r2h(rocFileSuccess, hipFileSuccess); - r2h(rocFileDriverNotInitialized, hipFileDriverNotInitialized); - r2h(rocFileDriverInvalidProps, hipFileDriverInvalidProps); - r2h(rocFileDriverUnsupportedLimit, hipFileDriverUnsupportedLimit); - r2h(rocFileDriverVersionMismatch, hipFileDriverVersionMismatch); - r2h(rocFileDriverVersionReadError, hipFileDriverVersionReadError); - r2h(rocFileDriverClosing, hipFileDriverClosing); - r2h(rocFilePlatformNotSupported, hipFilePlatformNotSupported); - r2h(rocFileIONotSupported, hipFileIONotSupported); - r2h(rocFileDeviceNotSupported, hipFileDeviceNotSupported); - r2h(rocFileDriverError, hipFileDriverError); - r2h(rocFileHipDriverError, hipFileHipDriverError); - r2h(rocFileHipPointerInvalid, hipFileHipPointerInvalid); - r2h(rocFileHipMemoryTypeInvalid, hipFileHipMemoryTypeInvalid); - r2h(rocFileHipPointerRangeError, hipFileHipPointerRangeError); - r2h(rocFileHipContextMismatch, hipFileHipContextMismatch); - r2h(rocFileInvalidMappingSize, hipFileInvalidMappingSize); - r2h(rocFileInvalidMappingRange, hipFileInvalidMappingRange); - r2h(rocFileInvalidFileType, hipFileInvalidFileType); - r2h(rocFileInvalidFileOpenFlag, hipFileInvalidFileOpenFlag); - r2h(rocFileDIONotSet, hipFileDIONotSet); - r2h(rocFileInvalidValue, hipFileInvalidValue); - r2h(rocFileMemoryAlreadyRegistered, hipFileMemoryAlreadyRegistered); - r2h(rocFileMemoryNotRegistered, hipFileMemoryNotRegistered); - r2h(rocFilePermissionDenied, hipFilePermissionDenied); - r2h(rocFileDriverAlreadyOpen, hipFileDriverAlreadyOpen); - r2h(rocFileHandleNotRegistered, hipFileHandleNotRegistered); - r2h(rocFileHandleAlreadyRegistered, hipFileHandleAlreadyRegistered); - r2h(rocFileDeviceNotFound, hipFileDeviceNotFound); - r2h(rocFileInternalError, hipFileInternalError); - r2h(rocFileGetNewFDFailed, hipFileGetNewFDFailed); - r2h(rocFileDriverSetupError, hipFileDriverSetupError); - r2h(rocFileIODisabled, hipFileIODisabled); - r2h(rocFileBatchSubmitFailed, hipFileBatchSubmitFailed); - r2h(rocFileGPUMemoryPinningFailed, hipFileGPUMemoryPinningFailed); - r2h(rocFileBatchFull, hipFileBatchFull); - r2h(rocFileAsyncNotSupported, hipFileAsyncNotSupported); - r2h(rocFileIOMaxError, hipFileIOMaxError); -#undef r2h - - ASSERT_THROW(toHipFileOpError(invalidEnum(hipFileIOMaxError + 1)), - std::invalid_argument); -} - -TEST(ToHipFile, hipFileError_t) -{ - ASSERT_THROW((void)toHipFileError( - rocFileError_t{invalidEnum(rocFileIOMaxError + 1), hipSuccess}), - std::invalid_argument); - - ASSERT_EQ(toHipFileError(rocFileError_t{rocFileSuccess, hipSuccess}), HIPFILE_SUCCESS); - ASSERT_EQ(toHipFileError(rocFileError_t{rocFileHipDriverError, hipErrorInvalidValue}), - HipFileDriverError(hipErrorInvalidValue)); - ASSERT_EQ(toHipFileError(rocFileError_t{rocFileDriverNotInitialized, hipSuccess}), - HipFileOpError(hipFileDriverNotInitialized)); -} - -TEST(ToHipFile, hipFileStatus_t) -{ - ASSERT_THROW(toHipFileStatus(invalidEnum(rocFileWaiting - 1)), std::invalid_argument); - -#define r2h(R, H) ASSERT_EQ(toHipFileStatus((R)), (H)) - r2h(rocFileWaiting, hipFileWaiting); - r2h(rocFilePending, hipFilePending); - r2h(rocFileInvalid, hipFileInvalid); - r2h(rocFileCanceled, hipFileCanceled); - r2h(rocFileComplete, hipFileComplete); - r2h(rocFileTimeout, hipFileTimeout); - r2h(rocFileFailed, hipFileFailed); -#undef r2h - - ASSERT_THROW(toHipFileStatus(invalidEnum(rocFileFailed + 1)), std::invalid_argument); -} - -TEST(ToHipFile, hipFileIOEvents_t) -{ - { - rocFileIOEvents_t rioe; - rioe.status = invalidEnum(rocFileWaiting - 1); - ASSERT_THROW(toHipFileIOEvents(rioe), std::invalid_argument); - } - - { - rocFileIOEvents_t rioe; - rioe.status = invalidEnum(rocFileFailed + 1); - ASSERT_THROW(toHipFileIOEvents(rioe), std::invalid_argument); - } - - { - rocFileIOEvents_t rioe; - rfill(static_cast(&rioe), sizeof(rioe)); - rioe.status = rocFileWaiting; - - auto hioe = toHipFileIOEvents(rioe); - - ASSERT_EQ(hioe.cookie, rioe.cookie); - ASSERT_EQ(hioe.status, hipFileWaiting); - ASSERT_EQ(hioe.ret, rioe.ret); - } -} - -TEST(ToRocFile, rocFileDescr_t) -{ - { - hipFileDescr_t hfd{}; - hfd.type = invalidEnum(hipFileHandleTypeOpaqueFD - 1); - ASSERT_THROW(toRocFileDescr(hfd), std::invalid_argument); - } - - { - hipFileDescr_t hfd{}; - hfd.type = hipFileHandleTypeOpaqueFD; - hfd.handle.fd = 0x1234; - hfd.fs_ops = reinterpret_cast(0xCAFEBABE); - - auto rfd = toRocFileDescr(hfd); - ASSERT_EQ(rfd.type, rocFileHandleTypeOpaqueFD); - ASSERT_EQ(rfd.handle.fd, hfd.handle.fd); - ASSERT_EQ(static_cast(rfd.fs_ops), static_cast(hfd.fs_ops)); - } - - { - hipFileDescr_t hfd{}; - hfd.type = hipFileHandleTypeOpaqueWin32; - hfd.handle.hFile = reinterpret_cast(0x5678); - hfd.fs_ops = reinterpret_cast(0xBADF00D); - - auto rfd = toRocFileDescr(hfd); - ASSERT_EQ(rfd.type, rocFileHandleTypeOpaqueWin32); - ASSERT_EQ(rfd.handle.hFile, hfd.handle.hFile); - ASSERT_EQ(static_cast(rfd.fs_ops), static_cast(hfd.fs_ops)); - } - - { - hipFileDescr_t hfd{}; - hfd.type = hipFileHandleTypeUserspaceFS; - hfd.handle.fd = 0x90AB; - hfd.fs_ops = reinterpret_cast(0xFACEFEED); - - auto rfd = toRocFileDescr(hfd); - ASSERT_EQ(rfd.type, rocFileHandleTypeUserspaceFS); - ASSERT_EQ(rfd.handle.fd, hfd.handle.fd); - ASSERT_EQ(static_cast(rfd.fs_ops), static_cast(hfd.fs_ops)); - } - - { - hipFileDescr_t hfd{}; - hfd.type = invalidEnum(hipFileHandleTypeUserspaceFS + 1); - ASSERT_THROW(toRocFileDescr(hfd), std::invalid_argument); - } -} - -TEST(ToRocFile, rocFileFileHandleType) -{ - ASSERT_THROW(toRocFileFileHandleType(invalidEnum(hipFileHandleTypeOpaqueFD - 1)), - std::invalid_argument); - -#define h2c(H, C) ASSERT_EQ(toRocFileFileHandleType((H)), (C)) - h2c(hipFileHandleTypeOpaqueFD, rocFileHandleTypeOpaqueFD); - h2c(hipFileHandleTypeOpaqueWin32, rocFileHandleTypeOpaqueWin32); - h2c(hipFileHandleTypeUserspaceFS, rocFileHandleTypeUserspaceFS); -#undef h2c - - ASSERT_THROW( - toRocFileFileHandleType(invalidEnum(hipFileHandleTypeUserspaceFS + 1)), - std::invalid_argument); -} - -TEST(ToRocFile, rocFileBatchMode) -{ - ASSERT_THROW(toRocFileBatchMode(invalidEnum(hipFileBatch - 1)), - std::invalid_argument); - - ASSERT_EQ(toRocFileBatchMode(hipFileBatch), rocFileBatch); - - ASSERT_THROW(toRocFileBatchMode(invalidEnum(hipFileBatch + 1)), - std::invalid_argument); -} - -TEST(ToRocFile, rocFileOpcode_t) -{ - ASSERT_THROW(toRocFileOpcode(invalidEnum(hipFileBatchRead - 1)), std::invalid_argument); - -#define h2c(H, C) ASSERT_EQ(toRocFileOpcode((H)), (C)) - h2c(hipFileBatchRead, rocFileBatchRead); - h2c(hipFileBatchWrite, rocFileBatchWrite); -#undef h2c - - ASSERT_THROW(toRocFileOpcode(invalidEnum(hipFileBatchWrite + 1)), std::invalid_argument); -} - -TEST(ToRocFile, rocFileIOParams_t) -{ - { - hipFileIOParams_t hiop{}; - hiop.mode = invalidEnum(hipFileBatch + 1); - hiop.opcode = hipFileBatchWrite; - - ASSERT_THROW(toRocFileIOParams(hiop), std::invalid_argument); - } - - { - hipFileIOParams_t hiop{}; - hiop.mode = hipFileBatch; - hiop.opcode = invalidEnum(hipFileBatchWrite + 1); - - ASSERT_THROW(toRocFileIOParams(hiop), std::invalid_argument); - } - - { - hipFileIOParams_t hiop; - - rfill(static_cast(&hiop), sizeof(hiop)); - - hiop.mode = hipFileBatch; - hiop.opcode = hipFileBatchWrite; - - auto ciop = toRocFileIOParams(hiop); - ASSERT_EQ(ciop.mode, rocFileBatch); - ASSERT_EQ(ciop.u.batch.devPtr_base, hiop.u.batch.devPtr_base); - ASSERT_EQ(ciop.u.batch.file_offset, hiop.u.batch.file_offset); - ASSERT_EQ(ciop.u.batch.devPtr_offset, hiop.u.batch.devPtr_offset); - ASSERT_EQ(ciop.u.batch.size, hiop.u.batch.size); - ASSERT_EQ(ciop.fh, ciop.fh); - ASSERT_EQ(ciop.opcode, rocFileBatchWrite); - ASSERT_EQ(ciop.cookie, hiop.cookie); - } -} - -HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/hipfile/test/test-hipfile-batch.cpp b/hipfile/test/legacy/test-hipfile-batch.cpp similarity index 100% rename from hipfile/test/test-hipfile-batch.cpp rename to hipfile/test/legacy/test-hipfile-batch.cpp diff --git a/hipfile/test/test-hipfile.cpp b/hipfile/test/legacy/test-hipfile.cpp similarity index 100% rename from hipfile/test/test-hipfile.cpp rename to hipfile/test/legacy/test-hipfile.cpp diff --git a/hipfile/test/main.cpp b/hipfile/test/main.cpp deleted file mode 100644 index 1c8b8000..00000000 --- a/hipfile/test/main.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ - -#include "hipfile-warnings.h" -#include "invalid-enum.h" - -#include -#include - -using namespace std; - -// Put tests inside the macros to suppress the global constructor -// warnings -HIPFILE_WARN_NO_GLOBAL_CTOR_OFF - -TEST(Helpers, invalidEnum) -{ - enum foo { - a = -7, - b = 12, - }; - ASSERT_EQ(invalidEnum(a - 1), -8); - ASSERT_EQ(invalidEnum(a + 1), -6); - ASSERT_EQ(invalidEnum(b - 1), 11); - ASSERT_EQ(invalidEnum(b + 1), 13); -} - -HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/hipfile/test/hipfile-cufile.cpp b/hipfile/test/nvidia_detail/cufile-api-compat.cpp similarity index 98% rename from hipfile/test/hipfile-cufile.cpp rename to hipfile/test/nvidia_detail/cufile-api-compat.cpp index 7649b1ee..af3b9f4e 100644 --- a/hipfile/test/hipfile-cufile.cpp +++ b/hipfile/test/nvidia_detail/cufile-api-compat.cpp @@ -14,10 +14,13 @@ #include #include -#ifdef __HIP_PLATFORM_NVIDIA__ #include #include -#endif + +/* These tests exist to ensure that the hipFile API stays compatible + * with the cuFile API. They check that things like struct members, + * enum values, etc. align with cufile.h. + */ // Put tests inside the macros to suppress the global constructor // warnings diff --git a/hipfile/test/system/driver.cpp b/hipfile/test/system/driver.cpp index 54a91604..d46b1e23 100644 --- a/hipfile/test/system/driver.cpp +++ b/hipfile/test/system/driver.cpp @@ -209,7 +209,11 @@ TEST_F(DriverNoInit, hipFileBatchIOSubmit) hipFileBatchHandle_t handle{}; hipFileIOParams_t param{}; +#ifdef __HIP_PLATFORM_AMD__ + ASSERT_EQ(hipFileBatchIOSubmit(handle, 1, ¶m, 0), HipFileOpError(hipFileInvalidValue)); +#else ASSERT_EQ(hipFileBatchIOSubmit(handle, 1, ¶m, 0), HipFileOpError(hipFileInternalError)); +#endif } TEST_F(DriverNoInit, hipFileBatchIOGetStatusNullArgs) diff --git a/rocfile/CMakeLists.txt b/rocfile/CMakeLists.txt deleted file mode 100644 index 63e75826..00000000 --- a/rocfile/CMakeLists.txt +++ /dev/null @@ -1,19 +0,0 @@ -# Copyright (c) Advanced Micro Devices, Inc. All rights reserved. -# -# SPDX-License-Identifier: MIT - -cmake_minimum_required(VERSION 3.17) - -project("rocfile" DESCRIPTION "rocFile library" LANGUAGES CXX) - -# Set the path to the include directory for later use -set(ROCFILE_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include") -set(ROCFILE_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/src") -set(ROCFILE_TEST_PATH "${CMAKE_CURRENT_SOURCE_DIR}/test") - -add_subdirectory(src) - -# Add the testing directory -if(BUILD_TESTING) - add_subdirectory(test) -endif() diff --git a/rocfile/include/rocfile.h b/rocfile/include/rocfile.h deleted file mode 100644 index 6241d1b1..00000000 --- a/rocfile/include/rocfile.h +++ /dev/null @@ -1,998 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ - -#pragma once - -#include -#include -#include -#include -#include -#include - -#if defined(__GNUC__) -#define ROCFILE_API __attribute__((visibility("default"))) -#else -#define ROCFILE_API -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -// *********************************************************************** -// DOXYGEN SETUP -// *********************************************************************** - -// Without the `file`/`defgroup` directives, Doxgyen will not emit -// documentation for anything aside from structs in a C header. -// -// *ALL* Doxygen comment blocks should have an `ingroup` directive so they -// group properly in the output. - -/** - * @file - * - * @mainpage rocFile API Reference - * - * @section contents Contents - * - @ref core - * - @ref error - * - @ref driver - * - @ref rdma - * - @ref file - * - @ref batch - * - @ref async - */ - -/*! - * @defgroup core Core Functionality - * - * @defgroup error Errors and Error Handling - * - * @defgroup driver GPU IO Driver API - * - * @defgroup rdma Userspace RDMA API - * - * @defgroup file File Handle API - * - * @defgroup batch Batch API - * - * @defgroup async Async API - */ - -// *********************************************************************** -// LIBRARY VERSION NUMBERS -// *********************************************************************** - -/*! - * @brief rocFile major version number - * @ingroup core - */ -#define ROCFILE_VERSION_MAJOR 0 -/*! - * @brief rocFile minor version number - * @ingroup core - */ -#define ROCFILE_VERSION_MINOR 2 -/*! - * @brief rocFile patch version number - * @ingroup core - */ -#define ROCFILE_VERSION_PATCH 0 - -// *********************************************************************** -// ERROR HANDLING -// *********************************************************************** - -/*! - * @brief The base value for rocFile error codes - * @ingroup error - */ -#define ROCFILE_BASE_ERR 5000 - -/* clang-format off */ -/*! - * @brief rocFile function return codes - * @ingroup error - * - * An error code of -1 indicates a that a C or POSIX error has occurred and - * errno is likely to have been set. - * - * @note ROCFILE_BASE_ERR + 21 and 32 are intentionally omitted. - */ -typedef enum rocFileOpError { - rocFileSuccess = 0, //!< rocFile success - rocFileDriverNotInitialized = ROCFILE_BASE_ERR + 1, //!< GPU IO driver is not loaded - rocFileDriverInvalidProps = ROCFILE_BASE_ERR + 2, //!< Invalid GPU IO driver property provided - rocFileDriverUnsupportedLimit = ROCFILE_BASE_ERR + 3, //!< GPU IO Driver property value is unsupported - rocFileDriverVersionMismatch = ROCFILE_BASE_ERR + 4, //!< rocFile version does not match GPU IO driver version - rocFileDriverVersionReadError = ROCFILE_BASE_ERR + 5, //!< Unable to read the GPU IO driver version - rocFileDriverClosing = ROCFILE_BASE_ERR + 6, //!< GPU IO driver is closing and not accepting new requests - rocFilePlatformNotSupported = ROCFILE_BASE_ERR + 7, //!< rocFile is not supported on the current platform - rocFileIONotSupported = ROCFILE_BASE_ERR + 8, //!< rocFile is not supported on the selected file - rocFileDeviceNotSupported = ROCFILE_BASE_ERR + 9, //!< The selected GPU does not support rocFile - rocFileDriverError = ROCFILE_BASE_ERR + 10, //!< GPU IO driver error - rocFileHipDriverError = ROCFILE_BASE_ERR + 11, //!< GPU driver error: Inspect the hipError_t value for additional information - rocFileHipPointerInvalid = ROCFILE_BASE_ERR + 12, //!< Invalid GPU pointer - rocFileHipMemoryTypeInvalid = ROCFILE_BASE_ERR + 13, //!< Memory type backing pointer is incompatible with rocFile - rocFileHipPointerRangeError = ROCFILE_BASE_ERR + 14, //!< Pointer range exceeds allocated memory region - rocFileHipContextMismatch = ROCFILE_BASE_ERR + 15, //!< GPU driver context mismatch - rocFileInvalidMappingSize = ROCFILE_BASE_ERR + 16, //!< Accessing memory beyond pinned memory buffer - rocFileInvalidMappingRange = ROCFILE_BASE_ERR + 17, //!< Accessing memory beyond mapped memory region - rocFileInvalidFileType = ROCFILE_BASE_ERR + 18, //!< Unsupported file type - rocFileInvalidFileOpenFlag = ROCFILE_BASE_ERR + 19, //!< Unsupported file open flags - rocFileDIONotSet = ROCFILE_BASE_ERR + 20, //!< O_DIRECT flag not set - /* Value 5021 intentionally unused */ - rocFileInvalidValue = ROCFILE_BASE_ERR + 22, //!< One or more arguments have an invalid value - rocFileMemoryAlreadyRegistered = ROCFILE_BASE_ERR + 23, //!< Device pointer is already registered - rocFileMemoryNotRegistered = ROCFILE_BASE_ERR + 24, //!< Device pointer is not registered - rocFilePermissionDenied = ROCFILE_BASE_ERR + 25, //!< Permission error on device or file access - rocFileDriverAlreadyOpen = ROCFILE_BASE_ERR + 26, //!< GPU IO driver is already open - rocFileHandleNotRegistered = ROCFILE_BASE_ERR + 27, //!< File handle for GPU IO is not registered - rocFileHandleAlreadyRegistered = ROCFILE_BASE_ERR + 28, //!< File handle for GPU IO is already registered - rocFileDeviceNotFound = ROCFILE_BASE_ERR + 29, //!< Selected device not found - rocFileInternalError = ROCFILE_BASE_ERR + 30, //!< Internal GPU IO library error - rocFileGetNewFDFailed = ROCFILE_BASE_ERR + 31, //!< Unable to obtain a new file descriptor - /* Value 5032 intentionally unused */ - rocFileDriverSetupError = ROCFILE_BASE_ERR + 33, //!< GPU IO Driver initialization error - rocFileIODisabled = ROCFILE_BASE_ERR + 34, //!< GPU IO config file prohibits GPU IO on specified file - rocFileBatchSubmitFailed = ROCFILE_BASE_ERR + 35, //!< Failed to submit request for batch operation - rocFileGPUMemoryPinningFailed = ROCFILE_BASE_ERR + 36, //!< Failed to allocated pinned device memory - rocFileBatchFull = ROCFILE_BASE_ERR + 37, //!< Batch operation queue is full - rocFileAsyncNotSupported = ROCFILE_BASE_ERR + 38, //!< rocFile async IO is not supported - rocFileIOMaxError = ROCFILE_BASE_ERR + 39, //!< Internal flag to mark largest rocFile error code -} rocFileOpError_t; -/* clang-format on */ - -/*! - * @brief Return a descriptive string for a rocFile error - * @ingroup error - * - * @param [in] status Return code provided by rocFile - * - * @return Description of the error encountered - */ -ROCFILE_API -const char *rocFileOpStatusError(rocFileOpError_t status); - -// Ignoring return values from rocFile APIs is discouraged. -// On C++17 and C23 and up, we can make that emit a warning. -#if __cplusplus >= 201703L || __STDC_VERSION__ >= 202311L -#define __ROCFILE_NODISCARD [[nodiscard]] -#else -#define __ROCFILE_NODISCARD -#endif - -/*! - * @brief Error status returned from rocFile API calls - * @ingroup error - * - * @note This struct has the `[[nodiscard]]` attribute in C++ >= 17 and - * C >= 23 so unhandled return values will generate warnings - */ -typedef struct __ROCFILE_NODISCARD rocFileError { - rocFileOpError_t err; //!< Errors related to rocFile or the GPU IO driver - hipError_t hip_drv_err; //!< Errors related to the GPU driver -} rocFileError_t; - -/*! - * @brief Determine if an error code is a rocFile error - * @ingroup error - * @hideinitializer - * - * Signature - * @code - * bool IS_ROCFILE_ERR(rocFileOpError err) - * @endcode - * - * @return true/false - */ -#define IS_ROCFILE_ERR(err) (abs((int)err) > ROCFILE_BASE_ERR) - -/*! - * @brief Get an error string for a rocFile error - * @ingroup error - * @hideinitializer - * - * Signature - * @code - * const char *ROCFILE_ERRSTR(rocFileOpError err) - * @endcode - * - * @return A string description of a rocFile error - */ -#define ROCFILE_ERRSTR(err) rocFileOpStatusError((rocFileOpError_t)abs(err)) - -/*! - * @brief Determine if an error is a rocFile driver error - * @ingroup error - * @hideinitializer - * - * Signature - * @code - * bool IS_HIP_DRV_ERR(rocFileError_t err) - * @endcode - * - * @return true/false - */ -#ifndef IS_HIP_DRV_ERR -#define IS_HIP_DRV_ERR(err) ((err).err == rocFileHipDriverError) -#endif - -/*! - * @brief Get the driver error from a rocFileError_t - * @ingroup error - * @hideinitializer - * - * Signature - * @code - * hipError_t HIP_DRV_ERR(rocFileError_t err) - * @endcode - * - * @return The hipError_t component of err - */ -#ifndef HIP_DRV_ERR -#define HIP_DRV_ERR(err) ((err).hip_drv_err) -#endif - -// *********************************************************************** -// GPU IO DRIVER API -// *********************************************************************** - -/* See this section in hipfile.h for a discussion about the - * following enums. - */ - -/*! - * @brief Filesystems/storage protocols supported by GPU IO on this system - * @ingroup driver - * - * @note Value 10 is reserved for YRCloudFile - */ -typedef enum rocFileDriverStatusFlags { - rocFileLustreSupported = 0, //!< Lustre is supported (UNSUPPORTED in rocFile) - rocFileWekaFSSupported = 1, //!< Weka is supported (UNSUPPORTED in rocFile) - rocFileNFSSupported = 2, //!< NFS is supported - rocFileGPFSSupported = 3, //!< GPFS/IBM Storage Scale is supported (UNSUPPORTED in rocFile) - rocFileNVMeSupported = 4, //!< Local NVMe is supported - rocFileNVMeoFSupported = 5, //!< NVMeoF is supported - rocFileSCSISupported = 6, //!< SCSI is supported (UNSUPPORTED in rocFile) - rocFileScaleFluxCSDSupported = 7, //!< ScaleFlux CSD is supported (UNSUPPORTED in rocFile) - rocFileNVMeshSupported = 8, //!< NVMesh is supported (UNSUPPORTED in rocFile) - rocFileBeeGFSSupported = 9, //!< BeeGFS is supported (UNSUPPORTED in rocFile) - /* 10 is reserved for YRCloudFile */ - rocFileNVMeP2PSsupported = 11, //!< NVMeP2P is supported (UNSUPPORTED in rocFile) - rocFileScatefsSupported = 12, //!< ScateFS is supported (UNSUPPORTED in rocFile) -} rocFileDriverStatusFlags_t; - -/*! - * @brief Control flags for passing to the GPU IO driver - * @ingroup driver - */ -typedef enum rocFileDriverControlFlags { - rocFileUsePollMode = 0, //!< Enable polling for IO completion - rocFileAllowCompatMode = 1, //!< Allow GPU IO to fall back to POSIX IO -} rocFileDriverControlFlags_t; - -/*! - * @brief GPU IO Transport & Features supported by the system - * @ingroup driver - */ -typedef enum rocFileFeatureFlags { - rocFileDynRoutingSupported = 0, //!< RDMA dynamic routing is supported - rocFileBatchIOSupported = 1, //!< Batch operations are supported - rocFileStreamsSupported = 2, //!< Streams are supported - rocFileParallelIOSupported = 3, //!< Parallel IO is supported -} rocFileFeatureFlags_t; - -/*! - * @brief GPU IO configuration - * @ingroup driver - */ -typedef struct rocFileDriverProps { - /*! - * @brief GPU IO Driver Configuration - */ - struct { - unsigned major_version; //!< Major version of the GPU IO driver - unsigned minor_version; //!< Minor version of the GPU IO driver - - uint64_t poll_thresh_size; //!< Maximum IO size (in KiB) for which polling is used when poll mode is - //!< enabled - uint64_t max_direct_io_size; //!< Maximum IO size (in KiB) used by the GPU IO driver - - unsigned driver_status_flags; //!< Bitfield that maps to rocFileDriverStatusFlags_t - unsigned driver_control_flags; //!< Bitfield that maps to rocFileDriverControlFlags_t - } nvfs; - - unsigned feature_flags; //!< Bitfield that maps to rocFileFeatureFlags_t - - uint64_t - max_device_cache_size; //!< Maximum amount of GPU memory (in KiB) that can be used for bounce buffers - uint64_t per_buffer_cache_size; //!< Amount of GPU memory (in KiB) allocated for each bounce buffer - uint64_t max_device_pinned_mem_size; //!< Maximum amount of GPU memory (in KiB) that can be pinned - - unsigned max_batch_io_count; //!< Maximum number of batch operations that can be submitted at once - unsigned max_batch_io_timeout_msecs; //!< Timeout (in msec) for a batch operation to complete -} rocFileDriverProps_t; - -// *********************************************************************** -// RDMA API -// *********************************************************************** - -/* - * NOTE: !! AIS UNSUPPORTED !! (Not related to NVMeoRDMA) - */ - -/*! - * @brief Userspace RDMA configuration - * @ingroup rdma - */ -typedef struct rocFileRDMAInfo { - int version; //!< Version of the RDMA API to use - int desc_len; //!< Length of the description string - const char *desc_str; //!< Describes the configuration of the RDMA operation -} rocFileRDMAInfo_t; - -/*! - * @defgroup rdma_flags RDMA Characteristic Flags - * @ingroup rdma - * - * @brief Bitwise flags for RDMA characteristics - * @{ - */ - -/// Flag for if the RDMA operation is registered -#define ROCFILE_RDMA_REGISTER 1 - -/// Flag for if the RDMA operation has relaxed ordering -#define ROCFILE_RDMA_RELAXED_ORDERING (1 << 1) - -/*! @} */ - -// *********************************************************************** -// FILE HANDLE API -// *********************************************************************** - -/*! - * @brief IO operations for RDMA filesystems - * @ingroup file - */ -typedef struct rocFileFSOps { - /*! - * Type of remote FS used. If NULL, use fstat to discover. - */ - const char *(*fs_type)(void *handle); - /*! - * Get a list of host RDMA addresses. If NULL, use any address. - */ - int (*getRDMADeviceList)(void *handle, struct sockaddr **hostaddrs); - /*! - * Get the assigned priority of a RDMA device. If -1, there is no preference. - */ - int (*getRDMADevicePriority)(void *handle, char *, size_t, hoff_t, struct sockaddr *hostaddr); - /*! - * Read from the remote filesystem. If NULL, use the Linux VFS. - */ - ssize_t (*read)(void *handle, char *, size_t, hoff_t, rocFileRDMAInfo_t *); - /*! - * Write to the remote filesystem. If NULL, use the Linux VFS. - */ - ssize_t (*write)(void *handle, const char *, size_t, hoff_t, rocFileRDMAInfo_t *); -} rocFileFSOps_t; - -/*! - * @brief Type of file handle being used - * @ingroup file - */ -typedef enum rocFileFileHandleType { - rocFileHandleTypeOpaqueFD = 1, //!< POSIX file descriptor - rocFileHandleTypeOpaqueWin32 = 2, //!< Windows HANDLE file handle - rocFileHandleTypeUserspaceFS = 3, //!< Userspace RDMA filesystem -} rocFileFileHandleType_t; - -/*! - * @brief Top-level structure for performing GPU IO - * @ingroup file - * - * rocFileHandleTypeOpaqueFD -> handle.fd non-negative, fs_ops ignored - * rocFileHandleTypeOpaqueWin32 -> handle.hFile non-NULL, fs_ops ignored - * rocFileHandleTypeUserspaceFS -> handle.fd non-negative, fs_ops non-NULL - */ -typedef struct rocFileDescr { - rocFileFileHandleType_t type; //!< Type of file handle being used - union { - int fd; //!< POSIX file descriptor - void *hFile; //!< Win32 HANDLE file handle - } handle; //!< Union containing the OS-specific file handle - const rocFileFSOps_t *fs_ops; //!< Userspace RDMA filesystem operations -} rocFileDescr_t; - -/*! - * Opaque file handle used by the GPU IO driver/library - * @ingroup file - */ -typedef void *rocFileHandle_t; - -/*! - * @brief Registers an open file for GPU IO - * @ingroup file - * - * @note If the library has not already been initialized, the first call to - * `rocFileHandleRegister()` will initialize the library and increment - * the reference count (if it succeeds). - * - * @param [out] fh Opaque file handle for GPU IO operations - * @param [in] descr Parameters for opening the file - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileHandleRegister(rocFileHandle_t *fh, rocFileDescr_t *descr); - -/*! - * @brief Deregisters a file from GPU IO - * @ingroup file - * - * @param [in] fh Opaque file handle for GPU IO operations - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileHandleDeregister(rocFileHandle_t fh); - -/*! - * @brief Registers a GPU memory region to be used with GPU IO - * @ingroup file - * - * The memory region should be allocated by the user before being passed to the API call - * - * @note If the library has not already been initialized, the first call to - * `rocFileBufRegister()` will initialize the library and increment - * the reference count. - * - * @param [in] buffer_base Base address of the GPU buffer - * @param [in] length Size of the allocated buffer in bytes - * @param [in] flags Control flags for this buffer - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileBufRegister(const void *buffer_base, size_t length, int flags); - -/*! - * @brief Deregisters a GPU memory region from being used with GPU IO - * @ingroup file - * - * @param [in] buffer_base Base address of the GPU buffer - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileBufDeregister(const void *buffer_base); - -/*! - * @brief Synchronously read data from a file into a GPU buffer - * @ingroup file - * - * @param [in] fh Opaque file handle for GPU IO operations - * @param [in] buffer_base Base address of the GPU buffer - * @param [in] size Number of bytes that should be read - * @param [in] file_offset Offset into the file that should be read from - * @param [in] buffer_offset Offset of the GPU buffer that that the data should be written to - * - * @return if >= 0: Number of bytes read - * @return if -1: System error (check `errno` for the specific error) - * @return else: Negative value of the related rocFileOpError_t - */ -ROCFILE_API -ssize_t rocFileRead(rocFileHandle_t fh, void *buffer_base, size_t size, hoff_t file_offset, - hoff_t buffer_offset); - -/*! - * @brief Synchronously write data from a GPU buffer to a file - * @ingroup file - * - * @param [in] fh Opaque file handle for GPU IO operations - * @param [in] buffer_base Base address of the GPU buffer - * @param [in] size Number of bytes that should be written - * @param [in] file_offset Offset into the file that should be written to - * @param [in] buffer_offset Offset of the GPU buffer that the data should be read from - * - * @return if >= 0: Number of bytes written - * @return if -1: System error (check `errno` for the specific error) - * @return else: Negative value of the related rocFileOpError_t - */ -ROCFILE_API -ssize_t rocFileWrite(rocFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset, - hoff_t buffer_offset); - -// *********************************************************************** -// GPU IO DRIVER API -// *********************************************************************** - -/*! - * @brief Initialize the GPU IO driver for this process - * @ingroup driver - * - * Each call to `rocFileDriverOpen()` increments the library's reference - * count. If a call to `rocFileDriverOpen()` results in the reference count - * transitioning from zero to one, the library's state will be initialized. - * - * Calling `rocFileDriverOpen()` is optional. The first call to - * `rocFileBufRegister()` or `rocFileHandleRegister()` will trigger - * library initialization and increment the library's reference count. - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileDriverOpen(void); - -/*! - * @brief Close the GPU IO driver for this process - * @ingroup driver - * - * Each call to `rocFileDriverClose()` decrements the library's reference - * count. If a call to `rocFileDriverClose()` results in the reference count - * transitioning from one to zero, the library's state will be destroyed. - * - * Explicitly closing the library is not required; the library's state will be - * destroyed automatically at program exit. - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileDriverClose(void); - -/*! - * @brief Obtain the current reference count for the library - * @ingroup driver - * - * @see rocFileDriverOpen() - * @see rocFileDriverClose() - * - * @return The library's reference count - */ -ROCFILE_API -int64_t rocFileUseCount(void); - -/*! - * @brief Get a list of GPU IO driver properties - * @ingroup driver - * - * @param [out] props See `rocFileDriverProps_t` for what properties are reported - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileDriverGetProperties(rocFileDriverProps_t *props); - -/*! - * @brief Enable/disable polling mode for GPU IO - * @ingroup driver - * - * @param [in] poll `true` to enable polling, `false` to disable - * @param [in] poll_threshold_size Maximum IO size (in KiB) for which polling is - * used when enabled - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileDriverSetPollMode(bool poll, size_t poll_threshold_size); - -/*! - * @brief Set the maximum IO chunk size - * @ingroup driver - * - * @param [in] max_direct_io_size Maximum IO chunk size (in KiB) for each IO request - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileDriverSetMaxDirectIOSize(size_t max_direct_io_size); - -/*! - * @brief Set the maximum amount of GPU memory that can be used for bounce buffers - * @ingroup driver - * - * @param [in] max_cache_size Maximum GPU memory (in KiB) that can be reserved for bounce buffers - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileDriverSetMaxCacheSize(size_t max_cache_size); - -/*! - * @brief Set the maximum amount of GPU memory that can be pinned - * @ingroup driver - * - * @param [in] max_pinned_size Maximum GPU memory (in KiB) that can be pinned - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileDriverSetMaxPinnedMemSize(size_t max_pinned_size); - -// *********************************************************************** -// BATCH API -// *********************************************************************** - -/*! - * @brief The direction of data movement in a batch IO request - * @ingroup batch - */ -typedef enum rocFileOpcode { - rocFileBatchRead = 0, //!< Batch IO read operation - rocFileBatchWrite = 1, //!< Batch IO write operation -} rocFileOpcode_t; - -/*! - * @brief The status of a batch IO operation - * @ingroup batch - */ -typedef enum rocFileStatus { - rocFileWaiting = 1 << 0, //!< Batch IO request pending acceptance - rocFilePending = 1 << 1, //!< Batch IO request accepted and queued - rocFileInvalid = 1 << 2, //!< Batch IO request was rejected for being invalid or could not be queued - rocFileCanceled = 1 << 3, //!< Batch IO request was canceled - rocFileComplete = 1 << 4, //!< Batch IO request completed - rocFileTimeout = 1 << 5, //!< Batch IO request timed out - rocFileFailed = 1 << 6, //!< Batch IO request failed -} rocFileStatus_t; - -/*! - * @brief Mode of a batch IO operation - * @ingroup batch - */ -typedef enum rocFileBatchMode { - rocFileBatch = 1, //!< Normal batch IO operation -} rocFileBatchMode_t; - -/*! - * @brief Input parameters for a batch IO request - * @ingroup batch - */ -typedef struct rocFileIOParams { - rocFileBatchMode_t mode; //!< Mode of the batch IO request - union { - struct { - void *devPtr_base; //!< Base address of the GPU buffer where data should be read/written - int64_t file_offset; //!< Offset into the file that should be read/written - int64_t devPtr_offset; //!< Offset of the GPU buffer that should be read/written - size_t size; //!< Number of bytes to read or write - } batch; //!< Parameters for the read/write batch request - } u; //!< Wrapping union for batch IO parameters - rocFileHandle_t fh; //!< Registered rocFile handle for the target file - rocFileOpcode_t opcode; //!< Direction data is moving for the batch request - void *cookie; //!< Optionally used to track IO operations (e.g. self-reference pointer) -} rocFileIOParams_t; - -/*! - * @brief Status of a batch IO operation - * @ingroup batch - */ -typedef struct rocFileIOEvents { - void *cookie; //!< Optionally used to track IO operations (e.g. pointer to corresponding rocFileIOParams) - rocFileStatus_t status; //!< Status of the batch IO operation - size_t ret; //!< Number of bytes transferred or POSIX error code if negative -} rocFileIOEvents_t; - -/*! - * @brief Opaque batch operations handle - * @ingroup batch - */ -typedef void *rocFileBatchHandle_t; - -/*! - * @brief Prepare the system to perform a batch IO operation - * @ingroup batch - * - * @param [out] batch_idp Opaque handle for batch operations - * @param [in] max_nr Maximum number of requests that can be submitted to this batch handle - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileBatchIOSetUp(rocFileBatchHandle_t *batch_idp, unsigned max_nr); - -/*! - * @brief Enqueue a batch of IO requests for the GPU to complete asynchronously - * @ingroup batch - * - * @param [in] batch_idp Opaque handle for batch operations - * @param [in] nr Number of batch IO requests to submit - * @param [in] iocbp An array of `nr` batch IO requests to submit to the GPU. - * Data will be read into or written from the buffer specified in - * each request. - * @param [in] flags Control Flags for the batch IO. Currently unused. - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileBatchIOSubmit(rocFileBatchHandle_t batch_idp, unsigned nr, rocFileIOParams_t *iocbp, - unsigned flags); - -/*! - * @brief Poll for the status of completed batch IO operations - * @ingroup batch - * - * @param [in] batch_idp Opaque handle for batch operations. - * @param [in] min_nr Minimum number of batch operation statuses that should be returned. - * If `timeout` is exceeded, fewer statuses may be returned. - * @param [in,out] nr Maximum number of batch operation statuses that can be returned. - * This is parameter is modified to return the number of statuses returned in `iocbp`. - * - * @param [out] iocbp An array containing up to `nr` statuses from the overall batch operation - * @param [in] timeout Maximum amount of time this function should poll for status updates - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileBatchIOGetStatus(rocFileBatchHandle_t batch_idp, unsigned min_nr, unsigned *nr, - rocFileIOEvents_t *iocbp, struct timespec *timeout); - -/*! - * @brief Cancels all pending batch IO operations - * @ingroup batch - * - * @param [in] batch_idp Opaque handle for batch operations - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileBatchIOCancel(rocFileBatchHandle_t batch_idp); - -/*! - * @brief Destroys the batch IO handle and frees the associated resources - * @ingroup batch - * - * @param [in] batch_idp Opaque handle for batch operations - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileBatchIODestroy(rocFileBatchHandle_t batch_idp); - -// *********************************************************************** -// ASYNC API -// *********************************************************************** - -/*! - * @defgroup stream_flags Stream registration flags - * @ingroup async - * - * @brief Flags to configure async GPU IO behaviour at stream registration - * @{ - */ - -/// Buffer offset is fixed at time of submission -#define ROCFILE_STREAM_FIXED_BUF_OFFSET 1 - -/// File offset is fixed at time of submission -#define ROCFILE_STREAM_FIXED_FILE_OFFSET (1 << 1) - -/// File size is fixed at time of submission -#define ROCFILE_STREAM_FIXED_FILE_SIZE (1 << 2) - -/// Offsets and size are 4k aligned -#define ROCFILE_STREAM_PAGE_ALIGNED_INPUTS (1 << 3) - -/// Mask for selecting flag bits -#define ROCFILE_STREAM_FLAGS_MASK 0xf -/*! @} */ - -/*! - * @brief Perform an asynchronous read from a stream - * @ingroup async - * - * @param [in] fh Opaque file handle for GPU IO operations - * @param [in] buffer_base Base address of the GPU buffer - * @param [in] size_p Number of bytes that should be read - * @param [in] file_offset_p Offset into the file that should be read from - * @param [in] buffer_offset_p Offset of the GPU buffer that that the data should be written to - * @param [out] bytes_read_p Number of bytes read - * @param [in] stream The hipStream to enqueue this async IO request. - * If NULL, this request will be synchronous. - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileReadAsync(rocFileHandle_t fh, void *buffer_base, size_t *size_p, hoff_t *file_offset_p, - hoff_t *buffer_offset_p, ssize_t *bytes_read_p, hipStream_t stream); - -/*! - * @brief Perform an asynchronous write to a stream - * @ingroup async - * - * @param [in] fh Opaque file handle for GPU IO operations - * @param [in] buffer_base Base address of the GPU buffer - * @param [in] size_p Number of bytes that should be written - * @param [in] file_offset_p Offset into the file that should be written to - * @param [in] buffer_offset_p Offset of the GPU buffer that that the data should be read from - * @param [out] bytes_written_p Number of bytes written - * @param [in] stream The hipStream to enqueue this async IO request. - * If NULL, this request will be synchronous. - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileWriteAsync(rocFileHandle_t fh, void *buffer_base, size_t *size_p, hoff_t *file_offset_p, - hoff_t *buffer_offset_p, ssize_t *bytes_written_p, hipStream_t stream); - -/*! - * @brief Register a stream to be used by for asynchronous GPU IO - * @ingroup async - * - * @param [in] stream The stream used for for async IO requests - * @param [in] flags Flags that can optimize stream processing if parameters - * are known/are aligned at time of request submission - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileStreamRegister(hipStream_t stream, unsigned flags); - -/*! - * @brief Deregister a stream and free the associated resources - * @ingroup async - * - * @param [in] stream The stream used for async IO requests - * - * @return A rocFile error - */ -ROCFILE_API -rocFileError_t rocFileStreamDeregister(hipStream_t stream); - -// *********************************************************************** -// CORE API -// *********************************************************************** - -/*! - * @brief Get the rocFile version - * @ingroup core - * - * @param [out] major The major version - * @param [out] minor The minor version - * @param [out] patch The patch version - * - * @note Parameters can be set to NULL to ignore that part of the version - * - * @return rocFileSuccess - */ -ROCFILE_API -rocFileError_t rocFileGetVersion(unsigned *major, unsigned *minor, unsigned *patch); - -// *********************************************************************** -// PROPERTIES API -// *********************************************************************** - -/*! - * @brief size_t configuration parameters - * @ingroup core - */ -typedef enum rocFileSizeTConfigParameter_t { - rocFileParamProfileStats, //!< - rocFileParamExecutionMaxIOQueueDepth, //!< - rocFileParamExecutionMaxIOThreads, //!< - rocFileParamExecutionMinIOThresholdSizeKB, //!< - rocFileParamExecutionMaxRequestParallelism, //!< - rocFileParamPropertiesMaxDirectIOSizeKB, //!< - rocFileParamPropertiesMaxDeviceCacheSizeKB, //!< - rocFileParamPropertiesPerBufferCacheSizeKB, //!< - rocFileParamPropertiesMaxDevicePinnedMemSizeKB, //!< - rocFileParamPropertiesIOBatchsize, //!< - rocFileParamPollthresholdSizeKB, //!< - rocFileParamPropertiesBatchIOTimeoutMs, //!< -} rocFileSizeTConfigParameter_t; - -/*! - * @brief Boolean configuration parameters - * @ingroup core - */ -typedef enum rocFileBoolConfigParameter_t { - rocFileParamPropertiesUsePollMode, //!< - rocFileParamPropertiesAllowCompatMode, //!< - rocFileParamForceCompatMode, //!< - rocFileParamFsMiscApiCheckAggressive, //!< - rocFileParamExecutionParallelIO, //!< - rocFileParamProfileNvtx, //!< - rocFileParamPropertiesAllowSystemMemory, //!< - rocFileParamUsePcip2pdma, //!< - rocFileParamPreferIOUring, //!< - rocFileParamForceOdirectMode, //!< - rocFileParamSkipTopologyDetection, //!< - rocFileParamStreamMemopsBypass, //!< -} rocFileBoolConfigParameter_t; - -/*! - * @brief String configuration parameters - * @ingroup core - */ -typedef enum rocFileStringConfigParameter_t { - rocFileParamLoggingLevel, //!< - rocFileParamEnvLogfilePath, //!< - rocFileParamLogDir, //!< -} rocFileStringConfigParameter_t; - -/*! - * @brief Get the value of a size_t configuration parameter - * @ingroup core - * - * @param param The configuration parameter - * @param value The location to store the value of the configuration parameter - * - * @return rocFileSuccess - */ -ROCFILE_API -rocFileError_t rocFileGetParameterSizeT(rocFileSizeTConfigParameter_t param, size_t *value); - -/*! - * @brief Get the value of a Boolean configuration parameter - * @ingroup core - * - * @param param The configuration parameter - * @param value The location to store the value of the configuration parameter - * - * @return rocFileSuccess - */ -ROCFILE_API -rocFileError_t rocFileGetParameterBool(rocFileBoolConfigParameter_t param, bool *value); - -/*! - * @brief Get the value of a string configuration parameter - * @ingroup core - * - * @param param The configuration parameter - * @param desc_str The location to store the value of the configuration parameter - * @param len The length of the desc_str parameter - * - * @return rocFileSuccess - */ -ROCFILE_API -rocFileError_t rocFileGetParameterString(rocFileStringConfigParameter_t param, char *desc_str, int len); - -/*! - * @brief Set the value of a size_t configuration parameter - * @ingroup core - * - * @param param The configuration parameter - * @param value The value of the configuration parameter - * - * @return rocFileSuccess - */ -ROCFILE_API -rocFileError_t rocFileSetParameterSizeT(rocFileSizeTConfigParameter_t param, size_t value); - -/*! - * @brief Set the value of a Boolean configuration parameter - * @ingroup core - * - * @param param The configuration parameter - * @param value The value of the configuration parameter - * - * @return rocFileSuccess - */ -ROCFILE_API -rocFileError_t rocFileSetParameterBool(rocFileBoolConfigParameter_t param, bool value); - -/*! - * @brief Set the value of a string configuration parameter - * @ingroup core - * - * @param param The configuration parameter - * @param desc_str The value of the configuration parameter - * - * @return rocFileSuccess - */ -ROCFILE_API -rocFileError_t rocFileSetParameterString(rocFileStringConfigParameter_t param, const char *desc_str); - -// Not a part of the public API -#undef __ROCFILE_NODISCARD - -#ifdef __cplusplus -} -#endif diff --git a/rocfile/src/CMakeLists.txt b/rocfile/src/CMakeLists.txt deleted file mode 100644 index 42ff398b..00000000 --- a/rocfile/src/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (c) Advanced Micro Devices, Inc. All rights reserved. -# -# SPDX-License-Identifier: MIT - -set(ROCFILE_SOURCES - async.cpp - backend/asyncop-fallback.cpp - backend/fallback.cpp - backend/fastpath.cpp - batch/batch.cpp - buffer.cpp - context.cpp - file.cpp - hip.cpp - mountinfo.cpp - rocfile.cpp - rocfile-private.cpp - state.cpp - stream.cpp - sys.cpp -) - -# Will create rocfile_(static|shared) -ais_add_libraries( - NAME rocfile - DETAIL amd - SRCS ${ROCFILE_SOURCES} - LIBINCL ${ROCFILE_INCLUDE_PATH} - SYSINCLS ${ROCFILE_SOURCE_PATH} - LIBS mount -) diff --git a/rocfile/src/rocfile.cpp b/rocfile/src/rocfile.cpp deleted file mode 100644 index 6d1f41e8..00000000 --- a/rocfile/src/rocfile.cpp +++ /dev/null @@ -1,633 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ - -#include "backend.h" -#include "batch/batch.h" -#include "buffer.h" -#include "context.h" -#include "file.h" -#include "hip.h" -#include "hipfile-types.h" -#include "hipfile-warnings.h" -#include "io.h" -#include "rocfile.h" -#include "rocfile-private.h" -#include "state.h" -#include "sys.h" - -#include -#include -#include -#include -#include - -using namespace rocFile; -using namespace std; - -const char * -rocFileOpStatusError(rocFileOpError_t status) -{ - switch (status) { - case rocFileSuccess: - return "rocFile success"; - case rocFileDriverNotInitialized: - return "GPU IO driver is not loaded"; - case rocFileDriverInvalidProps: - return "Invalid GPU IO driver property provided"; - case rocFileDriverUnsupportedLimit: - return "GPU IO Driver property value is unsupported"; - case rocFileDriverVersionMismatch: - return "rocFile version does not match GPU IO driver version"; - case rocFileDriverVersionReadError: - return "Unable to read the GPU IO driver version"; - case rocFileDriverClosing: - return "GPU IO driver is closing and not accepting new requests"; - case rocFilePlatformNotSupported: - return "rocFile is not supported on the current platform"; - case rocFileIONotSupported: - return "rocFile is not supported on the selected file"; - case rocFileDeviceNotSupported: - return "The selected GPU does not support rocFile"; - case rocFileDriverError: - return "GPU IO driver error"; - case rocFileHipDriverError: - return "GPU driver error: Inspect hip_drv_err for additional information"; - case rocFileHipPointerInvalid: - return "Invalid GPU pointer"; - case rocFileHipMemoryTypeInvalid: - return "Memory type backing pointer is incompatible with rocFile"; - case rocFileHipPointerRangeError: - return "Pointer range exceeds allocated memory region"; - case rocFileHipContextMismatch: - return "GPU driver context mismatch"; - case rocFileInvalidMappingSize: - return "Accessing memory beyond pinned memory buffer"; - case rocFileInvalidMappingRange: - return "Accessing memory beyond mapped memory region"; - case rocFileInvalidFileType: - return "Unsupported file type"; - case rocFileInvalidFileOpenFlag: - return "Unsupported file open flags"; - case rocFileDIONotSet: - return "O_DIRECT flag not set"; - case rocFileInvalidValue: - return "One or more arguments have an invalid value"; - case rocFileMemoryAlreadyRegistered: - return "Device pointer is already registered"; - case rocFileMemoryNotRegistered: - return "Device pointer is not registered"; - case rocFilePermissionDenied: - return "Permission error on device or file access"; - case rocFileDriverAlreadyOpen: - return "GPU IO driver is already open"; - case rocFileHandleNotRegistered: - return "File handle for GPU IO is not registered"; - case rocFileHandleAlreadyRegistered: - return "File handle for GPU IO is already registered"; - case rocFileDeviceNotFound: - return "Selected device not found"; - case rocFileInternalError: - return "Internal GPU IO library error"; - case rocFileGetNewFDFailed: - return "Unable to obtain a new file descriptor"; - case rocFileDriverSetupError: - return "GPU IO Driver initialization error"; - case rocFileIODisabled: - return "GPU IO config file prohibits GPU IO on specified file"; - case rocFileBatchSubmitFailed: - return "Failed to submit request for batch operation"; - case rocFileGPUMemoryPinningFailed: - return "Failed to allocated pinned device memory"; - case rocFileBatchFull: - return "Batch operation queue is full"; - case rocFileAsyncNotSupported: - return "rocFile async IO is not supported"; - case rocFileIOMaxError: - return "Internal flag to mark largest rocFile error code"; - default: - return "Unknown rocFile error"; - } -} - -/// Catch C++ exceptions from the rocFile code and convert -/// them into error values that can be returned from public -/// C API calls. -static inline rocFileError_t -handle_exception() noexcept -try { - throw; -} -catch (rocFileError_t e) { - return e; -} -catch (const Hip::RuntimeError &e) { - return {rocFileHipDriverError, e.error}; -} -catch (...) { - return {rocFileInternalError, hipSuccess}; -} - -rocFileError_t -rocFileHandleRegister(rocFileHandle_t *fh, rocFileDescr_t *descr) -try { - if (fh == nullptr || descr == nullptr) { - return {rocFileInvalidValue, hipSuccess}; - } - - switch (descr->type) { - case rocFileHandleTypeOpaqueFD: { - UnregisteredFile uf{descr->handle.fd}; - *fh = Context::get()->registerFile(uf); - return {rocFileSuccess, hipSuccess}; - } - case rocFileHandleTypeOpaqueWin32: - case rocFileHandleTypeUserspaceFS: - default: - return {rocFileIONotSupported, hipSuccess}; - } -} -catch (const FileAlreadyRegistered &) { - return {rocFileHandleAlreadyRegistered, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileHandleDeregister(rocFileHandle_t fh) -try { - if (fh == nullptr) { - return {rocFileInvalidValue, hipSuccess}; - } - - Context::get()->deregisterFile(fh); - return {rocFileSuccess, hipSuccess}; -} -catch (const DriverNotInitialized &) { - return {rocFileDriverNotInitialized, hipSuccess}; -} -catch (const FileOperationsOutstanding &) { - return {rocFileInternalError, hipSuccess}; -} -catch (const FileNotRegistered &) { - return {rocFileHandleNotRegistered, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileBufRegister(const void *buffer_base, size_t length, int flags) -try { - Context::get()->registerBuffer(buffer_base, length, flags); - return {rocFileSuccess, hipSuccess}; -} -catch (const BufferAlreadyRegistered &) { - return {rocFileMemoryAlreadyRegistered, hipSuccess}; -} -catch (const InvalidMemoryType &) { - return {rocFileHipMemoryTypeInvalid, hipSuccess}; -} -catch (const InvalidPointerRange &) { - return {rocFileHipPointerRangeError, hipSuccess}; -} -catch (const Hip::RuntimeError &e) { - if (e.error == hipErrorInvalidValue) { - return {rocFileInvalidValue, hipSuccess}; - } - return handle_exception(); -} -catch (const std::invalid_argument &) { - return {rocFileInvalidValue, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileBufDeregister(const void *buffer_base) -try { - Context::get()->deregisterBuffer(buffer_base); - return {rocFileSuccess, hipSuccess}; -} -catch (const DriverNotInitialized &) { - return {rocFileDriverNotInitialized, hipSuccess}; -} -catch (const BufferNotRegistered &) { - return {rocFileMemoryNotRegistered, hipSuccess}; -} -catch (const BufferOperationsOutstanding &) { - return {rocFileInternalError, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -/// @brief Get the cached list of backends obtained from DriverState -static const vector> & -getCachedBackends() -{ - HIPFILE_WARN_NO_EXIT_DTOR_OFF - static const auto backends{Context::get()->getBackends()}; - HIPFILE_WARN_NO_EXIT_DTOR_ON - return backends; -} - -ssize_t -rocFileIo(IoType type, rocFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset, - hoff_t buffer_offset, const vector> &backends) -try { - auto [file, buffer] = Context::get()->getFileAndBuffer(fh, buffer_base, size, 0); - int score{-1}; - std::shared_ptr backend{}; - - for (const auto &_backend : backends) { - auto _score = _backend->score(file, buffer, size, file_offset, buffer_offset); - if (score < _score) { - score = _score; - backend = _backend; - } - } - - if (!backend) { - if (backends.size() == 0) { - throw std::runtime_error("No available backends for IO request"); - } - else { - throw std::runtime_error("All backends refused IO request"); - } - } - - return backend->io(type, file, buffer, size, file_offset, buffer_offset); -} -catch (const DriverNotInitialized &) { - return -rocFileDriverNotInitialized; -} -catch (rocFileError_t e) { - return -e.err; -} -catch (const InvalidMemoryType &) { - return -rocFileHipMemoryTypeInvalid; -} -catch (const std::invalid_argument &) { - return -rocFileInvalidValue; -} -catch (const FileNotRegistered &) { - return -rocFileHandleNotRegistered; -} -catch (const Hip::RuntimeError &e) { - return -e.error; -} -catch (const Sys::RuntimeError &e) { - errno = e.error; - return -1; -} -catch (const std::system_error &e) { - errno = e.code().value(); - return -1; -} -catch (...) { - return -rocFileInternalError; -} - -ssize_t -rocFileRead(rocFileHandle_t fh, void *buffer_base, size_t size, hoff_t file_offset, hoff_t buffer_offset) -{ - return rocFileIo(IoType::Read, fh, buffer_base, size, file_offset, buffer_offset, getCachedBackends()); -} - -ssize_t -rocFileWrite(rocFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset, - hoff_t buffer_offset) -{ - return rocFileIo(IoType::Write, fh, buffer_base, size, file_offset, buffer_offset, getCachedBackends()); -} - -rocFileError_t -rocFileDriverOpen() -try { - Context::get()->incrRefCount(); - - return {rocFileSuccess, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileDriverClose() -try { - if (Context::get()->getRefCount() > 0) { - Context::get()->decrRefCount(); - return {rocFileSuccess, hipSuccess}; - } - else { - return {rocFileDriverNotInitialized, hipSuccess}; - } -} -catch (...) { - return handle_exception(); -} - -int64_t -rocFileUseCount() -try { - return Context::get()->getRefCount(); -} -catch (...) { - return -1; -} - -rocFileError_t -rocFileDriverGetProperties(rocFileDriverProps_t *props) -try { - (void)props; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileDriverSetPollMode(bool poll, size_t poll_threshold_size) -try { - (void)poll; - (void)poll_threshold_size; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileDriverSetMaxDirectIOSize(size_t max_direct_io_size) -try { - (void)max_direct_io_size; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileDriverSetMaxCacheSize(size_t max_cache_size) -try { - (void)max_cache_size; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileDriverSetMaxPinnedMemSize(size_t max_pinned_size) -try { - (void)max_pinned_size; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileBatchIOSetUp(rocFileBatchHandle_t *batch_idp, unsigned max_nr) -try { - if (batch_idp == nullptr) { - return {rocFileInvalidValue, hipSuccess}; - } - - *batch_idp = Context::get()->createBatchContext(max_nr); - - return {rocFileSuccess, hipSuccess}; -} -catch (const std::invalid_argument &) { - return {rocFileInvalidValue, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileBatchIOSubmit(rocFileBatchHandle_t batch_idp, unsigned nr, rocFileIOParams_t *iocbp, unsigned flags) -try { - (void)flags; // Unused at this time. - - std::shared_ptr batch_context = Context::get()->getBatchContext(batch_idp); - batch_context->submit_operations(iocbp, nr); - - return {rocFileSuccess, hipSuccess}; -} -catch (const std::invalid_argument &) { - return {rocFileInvalidValue, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileBatchIOGetStatus(rocFileBatchHandle_t batch_idp, unsigned min_nr, unsigned *nr, - rocFileIOEvents_t *iocbp, struct timespec *timeout) -try { - (void)batch_idp; - (void)min_nr; - (void)nr; - (void)iocbp; - (void)timeout; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileBatchIOCancel(rocFileBatchHandle_t batch_idp) -try { - (void)batch_idp; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileBatchIODestroy(rocFileBatchHandle_t batch_idp) -try { - (void)batch_idp; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileReadAsync(rocFileHandle_t fh, void *buffer_base, size_t *size_p, hoff_t *file_offset_p, - hoff_t *buffer_offset_p, ssize_t *bytes_read_p, hipStream_t stream) -try { - if (Context::get()->getRefCount() == 0) { - return {rocFileDriverNotInitialized, hipSuccess}; - } - - (void)fh; - (void)buffer_base; - (void)size_p; - (void)file_offset_p; - (void)buffer_offset_p; - (void)bytes_read_p; - (void)stream; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileWriteAsync(rocFileHandle_t fh, void *buffer_base, size_t *size_p, hoff_t *file_offset_p, - hoff_t *buffer_offset_p, ssize_t *bytes_written_p, hipStream_t stream) -try { - if (Context::get()->getRefCount() == 0) { - return {rocFileDriverNotInitialized, hipSuccess}; - } - - (void)fh; - (void)buffer_base; - (void)size_p; - (void)file_offset_p; - (void)buffer_offset_p; - (void)bytes_written_p; - (void)stream; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileStreamRegister(hipStream_t stream, unsigned flags) -try { - Context::get()->registerStream(stream, flags); - return {rocFileSuccess, hipSuccess}; -} -catch (std::invalid_argument &) { - return {rocFileInvalidValue, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileStreamDeregister(hipStream_t stream) -try { - Context::get()->deregisterStream(stream); - return {rocFileSuccess, hipSuccess}; -} -catch (std::invalid_argument &) { - return {rocFileInvalidValue, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileGetVersion(unsigned *major, unsigned *minor, unsigned *patch) -try { - // NULL parameters are ignored - if (major != nullptr) { - *major = ROCFILE_VERSION_MAJOR; - } - if (minor != nullptr) { - *minor = ROCFILE_VERSION_MINOR; - } - if (patch != nullptr) { - *patch = ROCFILE_VERSION_PATCH; - } - - return {rocFileSuccess, hipSuccess}; -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileGetParameterSizeT(rocFileSizeTConfigParameter_t param, size_t *value) -try { - (void)param; - (void)value; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileGetParameterBool(rocFileBoolConfigParameter_t param, bool *value) -try { - (void)param; - (void)value; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileGetParameterString(rocFileStringConfigParameter_t param, char *desc_str, int len) -try { - (void)param; - (void)desc_str; - (void)len; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileSetParameterSizeT(rocFileSizeTConfigParameter_t param, size_t value) -try { - (void)param; - (void)value; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileSetParameterBool(rocFileBoolConfigParameter_t param, bool value) -try { - (void)param; - (void)value; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} - -rocFileError_t -rocFileSetParameterString(rocFileStringConfigParameter_t param, const char *desc_str) -try { - (void)param; - (void)desc_str; - - throw std::runtime_error("Not Implemented"); -} -catch (...) { - return handle_exception(); -} diff --git a/rocfile/test/driver.cpp b/rocfile/test/driver.cpp deleted file mode 100644 index e35c5f74..00000000 --- a/rocfile/test/driver.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ - -#include "hipfile-warnings.h" -#include "mhip.h" -#include "mmountinfo.h" -#include "msys.h" -#include "rocfile.h" -#include "rocfile-test.h" -#include "sys.h" - -#include -#include -#include -#include -#include -#include - -using namespace rocFile; -using namespace testing; - -// Put tests inside the macros to suppress the global constructor -// warnings -HIPFILE_WARN_NO_GLOBAL_CTOR_OFF - -struct RocFileDriverAdmin : public RocFileUnopened {}; - -// Ensure that rocFileOpen() and rocFileClose() increment and -// decrement the reference count -TEST_F(RocFileDriverAdmin, OpenClose) -{ - const int64_t N = 10; - - ASSERT_EQ(rocFileUseCount(), 0); - - for (int64_t i = 1; i <= N; i++) { - ASSERT_EQ(rocFileDriverOpen(), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), i); - } - - for (int64_t i = N; i >= 1; i--) { - ASSERT_EQ(rocFileDriverClose(), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), i - 1); - } - - ASSERT_EQ(rocFileUseCount(), 0); -} - -// Ensure rocFileHandleRegister() initializes the driver -// and DOES bump the reference count -TEST_F(RocFileDriverAdmin, HandleRegisterInitsDriver) -{ - StrictMock msys{}; - StrictMock mlibmounthelper{}; - - rocFileHandle_t handle{}; - rocFileDescr_t descr{}; - - descr.handle.fd = 1234; - descr.type = rocFileHandleTypeOpaqueFD; - descr.fs_ops = nullptr; - - ASSERT_EQ(rocFileUseCount(), 0); - expect_file_registration(msys, mlibmounthelper); - ASSERT_EQ(rocFileHandleRegister(&handle, &descr), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 1); -} - -// Ensure rocFileHandleRegister() handles a file descriptor -// of zero (technically a legal POSIX value) and DOES bump -// the reference count -TEST_F(RocFileDriverAdmin, HandleRegisterGoodFD) -{ - StrictMock msys{}; - StrictMock mlibmounthelper{}; - - rocFileHandle_t handle{}; - rocFileDescr_t descr{}; - - descr.handle.fd = 0; - descr.type = rocFileHandleTypeOpaqueFD; - descr.fs_ops = nullptr; - - expect_file_registration(msys, mlibmounthelper); - - ASSERT_EQ(rocFileUseCount(), 0); - ASSERT_EQ(rocFileHandleRegister(&handle, &descr), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 1); - ASSERT_EQ(rocFileHandleDeregister(handle), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 1); -} - -// Ensure rocFileHandleRegister() fails when passed a negative file -// descriptor and does NOT bump the reference count -TEST_F(RocFileDriverAdmin, HandleRegisterBadFD) -{ - StrictMock msys{}; - StrictMock mlibmounthelper{}; - - rocFileHandle_t handle{}; - rocFileDescr_t descr{}; - - descr.handle.fd = -1; - descr.type = rocFileHandleTypeOpaqueFD; - - EXPECT_CALL(msys, statx).WillOnce(Throw(Sys::RuntimeError(EBADF))); - - ASSERT_EQ(rocFileUseCount(), 0); - ASSERT_NE(rocFileHandleRegister(&handle, &descr), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 0); -} - -// Ensure rocFileHandleDeregister() fails when passed a NULL or -// unregistered pointer and does NOT bump the driver reference count -TEST_F(RocFileDriverAdmin, HandleDeregisterDoesNotInitDriver) -{ - StrictMock msys{}; - StrictMock mlibmounthelper{}; - - // Check NULL - ASSERT_EQ(rocFileUseCount(), 0); - ASSERT_NE(rocFileHandleDeregister(nullptr), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 0); - - // Check unregistered handle - rocFileHandle_t handle{}; - - ASSERT_EQ(rocFileUseCount(), 0); - ASSERT_NE(rocFileHandleDeregister(handle), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 0); -} - -// Ensure that closing the driver will also close any open handles. This -// is checked by trying to re-register a handle, which should fail if -// the handle were still open. -TEST_F(RocFileDriverAdmin, CloseDeregistersFile) -{ - StrictMock msys{}; - StrictMock mlibmounthelper{}; - - rocFileHandle_t handle{}; - rocFileDescr_t descr{}; - - descr.handle.fd = 1234; - descr.type = rocFileHandleTypeOpaqueFD; - descr.fs_ops = nullptr; - - ASSERT_EQ(rocFileUseCount(), 0); - expect_file_registration(msys, mlibmounthelper); - ASSERT_EQ(rocFileHandleRegister(&handle, &descr), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 1); - ASSERT_EQ(rocFileDriverClose(), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 0); - expect_file_registration(msys, mlibmounthelper); - ASSERT_EQ(rocFileHandleRegister(&handle, &descr), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 1); -} - -// Ensure that registering a buffer increments the driver reference -// count -TEST_F(RocFileDriverAdmin, BufRegisterInitsDriver) -{ - StrictMock mhip; - - expect_buffer_registration(mhip, hipMemoryTypeDevice); - - ASSERT_EQ(rocFileUseCount(), 0); - ASSERT_EQ(rocFileBufRegister(reinterpret_cast(0x1), 0, 0), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 1); -} - -// Ensure that buffer deregistration does not increment the driver -// reference count -TEST_F(RocFileDriverAdmin, BufDeregisterDoesNotInitDriver) -{ - ASSERT_EQ(rocFileUseCount(), 0); - ASSERT_EQ(rocFileBufDeregister(nullptr), RocFileOpError(rocFileDriverNotInitialized)); - ASSERT_EQ(rocFileUseCount(), 0); -} - -// Ensure that closing the driver also closes open buffers. This is -// checked by attempting to re-register a buffer, which should fail -// if it's already registered. -TEST_F(RocFileDriverAdmin, CloseDeregistersBuffer) -{ - StrictMock mhip; - - ASSERT_EQ(rocFileUseCount(), 0); - expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(reinterpret_cast(0x1), 0, 0), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 1); - - ASSERT_EQ(rocFileDriverClose(), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 0); - - expect_buffer_registration(mhip, hipMemoryTypeDevice); - ASSERT_EQ(rocFileBufRegister(reinterpret_cast(0x1), 0, 0), ROCFILE_SUCCESS); - ASSERT_EQ(rocFileUseCount(), 1); -} - -// Ensure rocFileReadAsync(): -// * Returns rocFileDriverNotInitialized when called w/o a driver init -// * Does NOT initialize the driver and returns a reference count of 0 -TEST_F(RocFileDriverAdmin, ReadAsyncDoesNotInitDriver) -{ - ASSERT_EQ(rocFileReadAsync(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr), - RocFileOpError(rocFileDriverNotInitialized)); - ASSERT_EQ(rocFileUseCount(), 0); -} - -// Ensure rocFileWriteAsync(): -// * Returns rocFileDriverNotInitialized when called w/o a driver init -// * Does NOT initialize the driver and returns a reference count of 0 -TEST_F(RocFileDriverAdmin, WriteAsyncDoesNotInitDriverDriver) -{ - ASSERT_EQ(rocFileWriteAsync(nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr), - RocFileOpError(rocFileDriverNotInitialized)); - ASSERT_EQ(rocFileUseCount(), 0); -} - -// Ensure rocFileRead(): -// * Returns rocFileDriverNotInitialized when called w/o a driver init -// (the weird negative sign is a quirk of returning a ssize_t) -// * Does NOT initialize the driver and returns a reference count of 0 -TEST_F(RocFileDriverAdmin, ReadDoesNotInitDriver) -{ - ASSERT_EQ(rocFileRead(nullptr, nullptr, 0, 0, 0), -rocFileDriverNotInitialized); - ASSERT_EQ(rocFileUseCount(), 0); -} - -// Ensure rocFileWrite(): -// * Returns rocFileDriverNotInitialized when called w/o a driver init -// (the weird negative sign is a quirk of returning a ssize_t) -// * Does NOT initialize the driver and returns a reference count of 0 -TEST_F(RocFileDriverAdmin, WriteDoesNotInitDriver) -{ - ASSERT_EQ(rocFileWrite(nullptr, nullptr, 0, 0, 0), -rocFileDriverNotInitialized); - ASSERT_EQ(rocFileUseCount(), 0); -} - -HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/rocfile/test/misc.cpp b/rocfile/test/misc.cpp deleted file mode 100644 index 4571e65e..00000000 --- a/rocfile/test/misc.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ - -#include "context.h" -#include "hipfile-warnings.h" -#include "rocfile.h" -#include "rocfile-test.h" - -#include -#include -#include - -using namespace rocFile; - -// Put tests inside the macros to suppress the global constructor -// warnings -HIPFILE_WARN_NO_GLOBAL_CTOR_OFF - -struct RocFileVersioning : public RocFileUnopened {}; - -TEST_F(RocFileVersioning, Get) -{ - unsigned major = UINT_MAX; - unsigned minor = UINT_MAX; - unsigned patch = UINT_MAX; - - // Check for correct values - ASSERT_EQ(rocFileGetVersion(&major, &minor, &patch), ROCFILE_SUCCESS); - ASSERT_EQ(major, ROCFILE_VERSION_MAJOR); - ASSERT_EQ(minor, ROCFILE_VERSION_MINOR); - ASSERT_EQ(patch, ROCFILE_VERSION_PATCH); - - // NULL pointers should NOT produce errors - ASSERT_EQ(rocFileGetVersion(nullptr, nullptr, nullptr), ROCFILE_SUCCESS); -} - -HIPFILE_WARN_NO_GLOBAL_CTOR_ON diff --git a/shared/hipfile-types.h b/shared/hipfile-types.h deleted file mode 100644 index 9d7cf75b..00000000 --- a/shared/hipfile-types.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved. - * - * SPDX-License-Identifier: MIT - */ -#pragma once - -#include - -// *********************************************************************** -// PLATFORM-INDEPENDENT TYPES -// *********************************************************************** - -/*! - * @brief Platform-independent offset type - * @ingroup core - */ -#ifndef _WIN32 -typedef off_t hoff_t; -#else -typedef __int64 hoff_t; -#endif diff --git a/util/format-source.sh b/util/format-source.sh index 1c4c35aa..b1077738 100755 --- a/util/format-source.sh +++ b/util/format-source.sh @@ -9,7 +9,6 @@ COMMAND="clang-format" DIRS=( "hipfile" - "rocfile" ) if [ $# -eq 1 ]; then diff --git a/util/llvm-coverage.sh b/util/llvm-coverage.sh index f7fed53d..f5c1d2e6 100755 --- a/util/llvm-coverage.sh +++ b/util/llvm-coverage.sh @@ -48,5 +48,5 @@ if [ ! -s "$COV_FILES" ]; then fi llvm-profdata merge -output="$BUILD_DIR"/coverage.profdata --input-files="$COV_FILES" -llvm-cov report "$COLOR_ARG" -instr-profile="$BUILD_DIR"/coverage.profdata -object="$BUILD_DIR"/rocfile/src/librocfile.so -object="$BUILD_DIR"/hipfile/src/amd_detail/libhipfile.so >"$BUILD_DIR"/coverage-report.txt -llvm-cov show "$COLOR_ARG" -instr-profile="$BUILD_DIR"/coverage.profdata -object="$BUILD_DIR"/rocfile/src/librocfile.so -object="$BUILD_DIR"/hipfile/src/amd_detail/libhipfile.so >"$BUILD_DIR"/coverage-lines.txt +llvm-cov report "$COLOR_ARG" -instr-profile="$BUILD_DIR"/coverage.profdata -object="$BUILD_DIR"/hipfile/src/amd_detail/libhipfile.so >"$BUILD_DIR"/coverage-report.txt +llvm-cov show "$COLOR_ARG" -instr-profile="$BUILD_DIR"/coverage.profdata -object="$BUILD_DIR"/hipfile/src/amd_detail/libhipfile.so >"$BUILD_DIR"/coverage-lines.txt