Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EXSWHTEC-224 - Test cases ID clean up and documentation for Graph Management #95

Open
wants to merge 141 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 133 commits
Commits
Show all changes
141 commits
Select commit Hold shift + click to select a range
cea96af
SWDEV-355313 - Move catch tests and samples
gargrahul Oct 26, 2022
909e7e4
SWDEV-355313 - Add README
gargrahul Nov 7, 2022
094b9af
SWDEV-355313 - Update amd-staging branch
gargrahul Nov 28, 2022
32ce47c
EXSWHTEC-189 - Instate the usage of HIP_CHECK_ERROR
music-dino Nov 30, 2022
96fb815
EXSWHTEC-189 - Implement positive tests equivalent to hipMemcpy tests
music-dino Dec 1, 2022
070bb7c
EXSWHTEC-174 - Add Doxygen configuration and common header with group…
milos-mozetic Dec 1, 2022
9daa6d0
SWDEV-355313 - Update README
gargrahul Dec 2, 2022
a9169f7
EXSWHTEC-198: Implement tests for hipStreamGetCaptureInfo, hipStreamG…
nives-vukovic Dec 2, 2022
16d2130
EXSWHTEC-198: Modify doxygen comments
nives-vukovic Dec 2, 2022
003bba5
EXSWHTEC-192 - Implement basic positive test cases for int
music-dino Dec 2, 2022
e8339be
EXSWHTEC-192 - Implement new and update existing tests for the hipGra…
music-dino Dec 2, 2022
51f39ed
EXSWHTEC-192 - Implement positive and negative tests for hipGraphMemc…
music-dino Dec 3, 2022
9282142
EXSWHTEC-192 - Implement positive and negative tests for hipGraphExec…
music-dino Dec 3, 2022
4b56ed6
EXSWHTEC-192 - Refactor positive and negative tests
music-dino Dec 3, 2022
47e617f
EXSWHTEC-192 - Implement positive and negative tests for hipGraphAddM…
music-dino Dec 3, 2022
eab7ffd
EXSWHTEC-192 - Implement positive and negative tests for hipGraphMemc…
music-dino Dec 3, 2022
5bd77cc
EXSWHTEC-192 - Implement positive and negative tests for hipGraphExec…
music-dino Dec 3, 2022
f1ea13c
EXSWHTEC-192 - Implement additional negative parameter tests for all …
music-dino Dec 4, 2022
93a33b4
EXSWHTEC-192 - Implement additional common negative tests for node ad…
music-dino Dec 4, 2022
e0b1be9
EXSWHTEC-193 - Implement positive and negative tests for hipGraphAddM…
music-dino Dec 4, 2022
7cb1675
EXSWHTEC-193 - Implement positive and negative tests for hipGraphMems…
music-dino Dec 4, 2022
6290f8f
EXSWHTEC-193 - Implement positive and negative tests for hipGraphExec…
music-dino Dec 4, 2022
aab5793
Implement negative tests for hipGraphMemsetNodeGetParams
music-dino Dec 4, 2022
a9fad2d
EXSWHTEC-169 - Implement additional tests for Kernel Graph Node APIs
mirza-halilcevic Dec 5, 2022
01ffaef
EXSWHTEC-191 - Implement additional tests for Host Graph Node APIs
mirza-halilcevic Dec 5, 2022
54c1354
EXSWHTEC-170 - Implement tests for Kernel Graph Node Attribute APIs
mirza-halilcevic Dec 5, 2022
cf7e1f0
EXSWHTEC-191 - Disable failing test sections on AMD.
mirza-halilcevic Dec 5, 2022
961cee8
EXSWHTEC-170 - Disable failing test sections on AMD.
mirza-halilcevic Dec 5, 2022
6bc73b9
EXSWHTEC-192 - Coerce the code to compile and not return invalid symb…
music-dino Dec 5, 2022
8f62a86
EXSWHTEC-198: Make minor test modification
nives-vukovic Dec 5, 2022
45a5c51
Merge remote-tracking branch 'origin/doxygen_configuration' into hipG…
music-dino Dec 5, 2022
2a205ed
EXSWHTEC-200 - Add support for TEMPLATE_TEST_CASE preprocessing
milos-mozetic Dec 5, 2022
da726ce
EXSWHTEC-198: Fix identation issues
nives-vukovic Dec 5, 2022
aaadbc0
EXSWHTEC-193 - Add doxygen annotations
music-dino Dec 5, 2022
ae9fe5f
EXSWHTEC-145: Implement tests for hipStreamBeginCapture and hipStream…
nives-vukovic Nov 30, 2022
e240e9f
EXSWHTEC-145: Implement tests for hipStreamUpdateCaptureDependencies,…
nives-vukovic Nov 30, 2022
310d6c1
EXSWHTEC-145: Fix doxygen comments and identation issues
nives-vukovic Dec 5, 2022
512c2e4
Merge remote-tracking branch 'origin/doxygen_configuration' into hipG…
music-dino Dec 5, 2022
0b6e840
Merge remote-tracking branch 'origin/doxygen_configuration' into hipG…
music-dino Dec 5, 2022
14810d3
EXSWHTEC-192 - Add doxygen annotations
music-dino Dec 5, 2022
c49043e
SWDEV-355313 - Update latest code
gargrahul Dec 6, 2022
3b03df1
EXSWHTEC-193 - Add a dynamic section in positive test for memset for …
music-dino Dec 6, 2022
dad66d7
Implement common negative tests for node addition APIs
music-dino Dec 6, 2022
57bc654
Merge branch 'graph_test_common' into hipGraphMemsetNode_tests
music-dino Dec 6, 2022
e945d92
Merge branch 'graph_test_common' into hipGraphMemcpyNodeToFromSymbol_…
music-dino Dec 6, 2022
b93c7a8
EXSWHTEC-192 - Update code to use new graph_tests_common.hh
music-dino Dec 6, 2022
de804fb
Merge remote-tracking branch 'origin/graph_test_common' into hipGraph…
music-dino Dec 6, 2022
c113b0a
EXSWHTEC-189 - Reorganize code for hipGraphAddMemcpyNode1D
music-dino Dec 6, 2022
85bf509
EXSWHTEC-189 - Reorganize code for hipGraphMemcpyNodeSetParams
music-dino Dec 6, 2022
2b17028
EXSWHTEC-189 - Reorganize code and implement new test case for hipGra…
music-dino Dec 6, 2022
d8d49de
Merge remote-tracking branch 'origin/doxygen_configuration' into hipG…
music-dino Dec 6, 2022
ddbc714
EXSWHTEC-189 - Add doxygen annotations
music-dino Dec 6, 2022
e459a98
Disable sections that fail due to defects
music-dino Dec 6, 2022
ed31247
Merge branch 'graph_test_common' into hipGraphMemcpyNodeToFromSymbol_…
music-dino Dec 6, 2022
67ce4c9
Merge branch 'graph_test_common' into hipGraphMemcpyNode1D_tests
music-dino Dec 6, 2022
c95176c
Merge branch 'graph_test_common' into hipGraphMemsetNode_tests
music-dino Dec 6, 2022
9dc43ec
EXSWHTEC-193 - Disable test that fail due to defects
music-dino Dec 6, 2022
616870e
EXWHTEC-189 - Disable tests that fail due to defects
music-dino Dec 7, 2022
98fdac0
EXSWHTEC-94 - Add resource guards and utils for 2D/3D allocations and…
nives-vukovic Dec 7, 2022
0c3128d
EXSWHTEC-194 - Implement tests for User Object Graph APIs
mirza-halilcevic Dec 7, 2022
d62fa5d
EXSWHTEC-192 - Disable tests that fail due to defects
music-dino Dec 7, 2022
d8f732b
EXSWHTEC-198: Refactor and disable tests that fail on AMD
nives-vukovic Dec 8, 2022
7339f3a
Merge remote-tracking branch 'origin/develop' into hipStreamCaptureIn…
nives-vukovic Dec 8, 2022
eb9c799
EXSWHTEC-173 - Implement tests for Graph Node dependencies APIs
nives-vukovic Dec 8, 2022
32c3815
EXSWHTEC-145: Refactor and fix minor issues
nives-vukovic Dec 8, 2022
e368574
Merge remote-tracking branch 'origin/develop' into hipStreamCapture_t…
nives-vukovic Dec 8, 2022
96c8fbf
EXSWHTEC-145: Disable tests that fail on AMD
nives-vukovic Dec 8, 2022
f3b7a6c
EXSWHTEC-171 - Implement positive and negative unit tests for the fol…
marko-veniger Dec 8, 2022
80a2ac9
EXSWHTEC-172 - Implement unit tests for Graph launching and execution
marko-veniger Dec 8, 2022
12e34b9
Merge remote-tracking branch 'origin/develop' into utils
nives-vukovic Dec 9, 2022
15614ba
EXSWHTEC-94 - Extend stream guard and add guards for multiple events …
nives-vukovic Dec 9, 2022
c011cb2
Merge remote-tracking branch 'origin/utils' into hipStreamCaptureInfo…
nives-vukovic Dec 9, 2022
593a6a5
EXSWHTEC-198 - Code formatting
nives-vukovic Dec 9, 2022
210746f
Merge remote-tracking branch 'origin/utils' into hipStreamCapture_tests
nives-vukovic Dec 9, 2022
e896db6
EXSWHTEC-145 - Code formatting
nives-vukovic Dec 9, 2022
49bb4e5
EXSWHTEC-178 - Implement tests for Event Graph Node APIs
nives-vukovic Dec 9, 2022
e9ff120
Merge remote-tracking branch 'origin/doxygen_configuration' into hipG…
mirza-halilcevic Dec 9, 2022
4025135
EXSWHTEC-178 - Code formatting
nives-vukovic Dec 9, 2022
ba017da
EXSWHTEC-178 - Code formatting of hipGraphEventWaitNodeSetEvent
nives-vukovic Dec 9, 2022
11dc060
EXSWHTEC-178 - Add positive parameters test for hipGraphAddEventRecor…
nives-vukovic Dec 9, 2022
4b83f8e
EXSWHTEC-217 - Implement new and update existing tests for the
mirza-halilcevic Dec 9, 2022
ae12bbd
EXSWHTEC-217 - Disable tests with defects on AMD.
mirza-halilcevic Dec 9, 2022
116406b
EXSWHTEC-169 - Fix formatting.
mirza-halilcevic Dec 9, 2022
fd8a294
Merge remote-tracking branch 'origin/develop' into hipGraphKernelNode…
mirza-halilcevic Dec 9, 2022
e1a8a68
Merge remote-tracking branch 'origin/develop' into hipGraphKernelNode…
mirza-halilcevic Dec 9, 2022
0972551
Merge remote-tracking branch 'origin/doxygen_configuration' into hipG…
mirza-halilcevic Dec 9, 2022
6985c27
Merge remote-tracking branch 'origin/develop' into hipGraphHostNode_t…
mirza-halilcevic Dec 9, 2022
8a670b0
EXSWHTEC-178 - Remove unnecessary code and fix memory leaks
nives-vukovic Dec 11, 2022
3dc0015
Merge branch 'utils' into hipGraphDependencies_tests
nives-vukovic Dec 11, 2022
669dc78
EXSWHTEC-173 - Add old version of each changed test file
nives-vukovic Dec 11, 2022
cc3c63e
EXSWHTEC-173 - Refactor code by using templates from added graph_depe…
nives-vukovic Dec 12, 2022
fd9a15d
EXSWHTEC-173 - Format files and add doxygen comments
nives-vukovic Dec 12, 2022
4113308
EXSWHTEC-173 - Disable tests that fail on AMD
nives-vukovic Dec 12, 2022
e19ad34
EXSWHTEC-173 - Disable additional test for AMD
nives-vukovic Dec 12, 2022
55b528b
EXSWHTEC-173 - Fix minor issues in tests
nives-vukovic Dec 13, 2022
f1c2732
Merge remote-tracking branch 'origin/develop' into hipGraphDependenci…
nives-vukovic Dec 13, 2022
f169a60
EXSWHTEC-145 - Change defect IDs
nives-vukovic Dec 13, 2022
2db594f
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 13, 2022
1977515
EXSWHTEC-200 - Resolve conflicts in missed conflicted files
milos-mozetic Dec 13, 2022
6101837
EXSWHTEC-198 - Update defect IDs
nives-vukovic Dec 13, 2022
4d48b5f
Merge remote-tracking branch 'origin/doxygen_configuration' into hipS…
nives-vukovic Dec 13, 2022
dd2db08
Merge remote-tracking branch 'origin/doxygen_configuration' into hipS…
nives-vukovic Dec 13, 2022
cb06a9f
Merge remote-tracking branch 'origin/develop' into hipEventNode_tests
nives-vukovic Dec 14, 2022
259be27
EXSWHTEC-200 - Add newline at the end of the file
milos-mozetic Dec 14, 2022
e0daf30
EXSWHTEC-200 - Extend the PREDEFINED list to define all macro names t…
milos-mozetic Dec 14, 2022
c8eb213
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 16, 2022
16d46ee
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 16, 2022
e19598f
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 16, 2022
14833bc
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 21, 2022
38b0f1f
Merge branch 'doxygen_configuration' of github.com:mirza-halilcevic/h…
milos-mozetic Dec 21, 2022
0d84c74
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 21, 2022
f281947
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Dec 21, 2022
40f7a6c
Merge branch 'doxygen_configuration' of github.com:mirza-halilcevic/h…
milos-mozetic Dec 21, 2022
68f293f
Merge branch 'doxygen_configuration' of github.com:mirza-halilcevic/h…
milos-mozetic Dec 21, 2022
151889e
Merge branch 'doxygen_configuration' of github.com:mirza-halilcevic/h…
milos-mozetic Dec 21, 2022
b67e855
Merge branch 'hipGraphKernelNode_tests' of github.com:mirza-halilcevi…
milos-mozetic Dec 21, 2022
0d4b905
Merge branch 'hipGraphKernelNodeSetGetAttribute_tests' of github.com:…
milos-mozetic Dec 21, 2022
e826b9c
Merge branch 'hipGraphHostNode_tests' of github.com:mirza-halilcevic/…
milos-mozetic Dec 21, 2022
564f187
Merge branch 'hipStreamCaptureInfo_tests' of github.com:mirza-halilce…
milos-mozetic Dec 21, 2022
b940c69
Merge branch 'hipStreamCapture_tests' of github.com:mirza-halilcevic/…
milos-mozetic Dec 21, 2022
b82853c
Merge branch 'hipGraphMemsetNode_tests' of github.com:mirza-halilcevi…
milos-mozetic Dec 21, 2022
c18b2e8
Merge branch 'hipGraphMemcpyNodeToFromSymbol_tests' of github.com:mir…
milos-mozetic Dec 21, 2022
96010fb
Merge branch 'hipGraphMemcpyNode1D_tests' of github.com:mirza-halilce…
milos-mozetic Dec 21, 2022
5280b19
Merge branch 'hipUserObject_tests' of github.com:mirza-halilcevic/hip…
milos-mozetic Dec 21, 2022
620338f
Merge branch 'hipGraphCreationAndDestruction_tests' of github.com:mir…
milos-mozetic Dec 21, 2022
ff923ca
Merge branch 'hipGraphLaunchingAndExecution_tests' of github.com:mirz…
milos-mozetic Dec 21, 2022
e7bba3d
Merge branch 'hipEventNode_tests' of github.com:mirza-halilcevic/hip-…
milos-mozetic Dec 21, 2022
872a9ab
Merge branch 'hipGraphMemcpyNode_tests' of github.com:mirza-halilcevi…
milos-mozetic Dec 21, 2022
64084c3
Merge branch 'hipGraphDependencies_tests' of github.com:mirza-halilce…
milos-mozetic Dec 21, 2022
3b96c84
EXSWHTEC-224 - Test cases ID clean up and documentation for Graph Man…
milos-mozetic Dec 23, 2022
73674a4
Merge branch 'develop' into doxygen_graph_management_documentation
milos-mozetic Dec 23, 2022
734da4b
EXSWHTEC-224 - Add warning message for hipGraphUpload
milos-mozetic Dec 23, 2022
5d15818
Merge branch 'doxygen_graph_management_documentation' of github.com:m…
milos-mozetic Dec 23, 2022
42c8185
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Jun 22, 2023
bd81e7b
Merge branch 'develop' of github.com:mirza-halilcevic/hip-tests into …
milos-mozetic Jul 10, 2023
b8d9669
Merge remote-tracking branch 'origin/develop' into doxygen_graph_mana…
nives-vukovic Feb 8, 2024
588ba5d
EXSWHTEC-224 - Cleanup of doxygen comments
nives-vukovic Feb 8, 2024
66314b6
EXSWHTEC-224 - Further cleanup of doxygen comments
nives-vukovic Feb 8, 2024
dda18c6
EXSWHTEC-224 - Cleanup of GraphDestroy doxygen comments
nives-vukovic Feb 8, 2024
e1531b6
EXSWHTEC-224 - Cleanup of Graph doxygen comments
nives-vukovic Feb 8, 2024
2304d7f
Merge branch 'develop' into doxygen_graph_management_documentation
mirza-halilcevic Feb 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,540 changes: 2,540 additions & 0 deletions catch/DoxyfileTests

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion catch/hipTestMain/config/config_amd_linux_common.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
"Unit_hipInit_Negative",
"Unit_hipMemset_Negative_OutOfBoundsPtr",
"Unit_hipDeviceReset_Positive_Basic",
"Unit_hipDeviceReset_Positive_Threaded"
"Unit_hipDeviceReset_Positive_Threaded",
"Note: Following four tests disabled due to defect - EXSWHTEC-203",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint16_t",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint32_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint16_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint32_t",
"Note: Test disabled due to defect - EXSWHTEC-207",
"Unit_hipGraphExecMemsetNodeSetParams_Negative_Updating_Non1D_Node",
"Unit_hipGraphMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipGraphAddMemcpyNode_Negative_Parameters"
]
}
14 changes: 13 additions & 1 deletion catch/hipTestMain/config/config_amd_windows_common.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@
"Note: needs to be enabled when streamPerThread issues are fixed",
"Unit_hipStreamSynchronize_NullStreamAndStreamPerThread",
"Note: intermittent Seg fault failure ",
"Unit_hipGraphAddEventRecordNode_Functional_WithoutFlags"
"Unit_hipGraphAddEventRecordNode_Functional_WithoutFlags",
"Note: Following four tests disabled due to defect - EXSWHTEC-203",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint16_t",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint32_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint16_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint32_t",
"Note: Test disabled due to defect - EXSWHTEC-207",
"Unit_hipGraphExecMemsetNodeSetParams_Negative_Updating_Non1D_Node",
"Unit_hipGraphMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipGraphAddMemcpyNode_Negative_Parameters"
]
}
37 changes: 37 additions & 0 deletions catch/include/hip_test_defgroups.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright (c) 2021 - 2022 Advanced Micro Devices, Inc. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

// Test groups are named based on the group names from hip_api_runtime.h, with adding "Test" suffix

/**
* @defgroup CallbackTest Callback Activity APIs
* @{
* This section describes tests for the callback/Activity of HIP runtime API.
* @}
*/

/**
* @defgroup GraphTest Graph Management
* @{
* This section describes tests for the graph management types & functions of HIP runtime API.
* @}
*/
316 changes: 316 additions & 0 deletions catch/include/memcpy1d_tests_common.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,316 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

#pragma once

#include <functional>

#include <hip/hip_runtime_api.h>
#include <hip_test_common.hh>
#include <resource_guards.hh>
#include <utils.hh>

static inline unsigned int GenerateLinearAllocationFlagCombinations(
const LinearAllocs allocation_type) {
switch (allocation_type) {
case LinearAllocs::hipHostMalloc:
return GENERATE(hipHostMallocDefault, hipHostMallocPortable, hipHostMallocMapped,
hipHostMallocWriteCombined);
case LinearAllocs::mallocAndRegister:
case LinearAllocs::hipMallocManaged:
case LinearAllocs::malloc:
case LinearAllocs::hipMalloc:
return 0u;
default:
assert("Invalid LinearAllocs enumerator");
throw std::invalid_argument("Invalid LinearAllocs enumerator");
}
}

template <bool should_synchronize, typename F>
void MemcpyDeviceToHostShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
using LA = LinearAllocs;
const auto allocation_size = GENERATE(kPageSize / 2, kPageSize, kPageSize * 2);
const auto host_allocation_type = GENERATE(LA::malloc, LA::hipHostMalloc);
const auto host_allocation_flags = GenerateLinearAllocationFlagCombinations(host_allocation_type);

LinearAllocGuard<int> host_allocation(host_allocation_type, allocation_size,
host_allocation_flags);
LinearAllocGuard<int> device_allocation(LA::hipMalloc, allocation_size);

const auto element_count = allocation_size / sizeof(*device_allocation.ptr());
constexpr auto thread_count = 1024;
const auto block_count = element_count / thread_count + 1;
constexpr int expected_value = 42;
VectorSet<<<block_count, thread_count, 0, kernel_stream>>>(device_allocation.ptr(),
expected_value, element_count);
HIP_CHECK(hipGetLastError());

HIP_CHECK(memcpy_func(host_allocation.host_ptr(), device_allocation.ptr(), allocation_size));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}

ArrayFindIfNot(host_allocation.host_ptr(), expected_value, element_count);
}

template <bool should_synchronize, typename F>
void MemcpyHostToDeviceShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
using LA = LinearAllocs;
const auto allocation_size = GENERATE(kPageSize / 2, kPageSize, kPageSize * 2);
const auto host_allocation_type = GENERATE(LA::malloc, LA::hipHostMalloc);
const auto host_allocation_flags = GenerateLinearAllocationFlagCombinations(host_allocation_type);

LinearAllocGuard<int> src_host_allocation(host_allocation_type, allocation_size,
host_allocation_flags);
LinearAllocGuard<int> dst_host_allocation(LA::hipHostMalloc, allocation_size);
LinearAllocGuard<int> device_allocation(LA::hipMalloc, allocation_size);

const auto element_count = allocation_size / sizeof(*device_allocation.ptr());
constexpr int fill_value = 42;
std::fill_n(src_host_allocation.host_ptr(), element_count, fill_value);
std::fill_n(dst_host_allocation.host_ptr(), element_count, 0);

HIP_CHECK(memcpy_func(device_allocation.ptr(), src_host_allocation.host_ptr(), allocation_size));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}

HIP_CHECK(hipMemcpy(dst_host_allocation.host_ptr(), device_allocation.ptr(), allocation_size,
hipMemcpyDeviceToHost));

ArrayFindIfNot(dst_host_allocation.host_ptr(), fill_value, element_count);
}

template <bool should_synchronize, typename F>
void MemcpyHostToHostShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
using LA = LinearAllocs;
const auto allocation_size = GENERATE(kPageSize / 2, kPageSize, kPageSize * 2);
const auto src_allocation_type = GENERATE(LA::malloc, LA::hipHostMalloc);
const auto dst_allocation_type = GENERATE(LA::malloc, LA::hipHostMalloc);
const auto src_allocation_flags = GenerateLinearAllocationFlagCombinations(src_allocation_type);
const auto dst_allocation_flags = GenerateLinearAllocationFlagCombinations(dst_allocation_type);

LinearAllocGuard<int> src_allocation(src_allocation_type, allocation_size, src_allocation_flags);
LinearAllocGuard<int> dst_allocation(dst_allocation_type, allocation_size, dst_allocation_flags);

const auto element_count = allocation_size / sizeof(*src_allocation.host_ptr());
constexpr auto expected_value = 42;
std::fill_n(src_allocation.host_ptr(), element_count, expected_value);

HIP_CHECK(memcpy_func(dst_allocation.host_ptr(), src_allocation.host_ptr(), allocation_size));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}

ArrayFindIfNot(dst_allocation.host_ptr(), expected_value, element_count);
}

template <bool should_synchronize, bool enable_peer_access, typename F>
void MemcpyDeviceToDeviceShell(F memcpy_func, const hipStream_t kernel_stream = nullptr) {
const auto allocation_size = GENERATE(kPageSize / 2, kPageSize, kPageSize * 2);
const auto device_count = HipTest::getDeviceCount();
const auto src_device = GENERATE_COPY(range(0, device_count));
const auto dst_device = GENERATE_COPY(range(0, device_count));
INFO("Src device: " << src_device << ", Dst device: " << dst_device);

HIP_CHECK(hipSetDevice(src_device));
if constexpr (enable_peer_access) {
if (src_device == dst_device) {
return;
}
int can_access_peer = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&can_access_peer, src_device, dst_device));
if (!can_access_peer) {
INFO("Peer access cannot be enabled between devices " << src_device << " " << dst_device);
REQUIRE(can_access_peer);
}
HIP_CHECK(hipDeviceEnablePeerAccess(dst_device, 0));
}

LinearAllocGuard<int> src_allocation(LinearAllocs::hipMalloc, allocation_size);
LinearAllocGuard<int> result(LinearAllocs::hipHostMalloc, allocation_size, hipHostMallocPortable);
HIP_CHECK(hipSetDevice(dst_device));
LinearAllocGuard<int> dst_allocation(LinearAllocs::hipMalloc, allocation_size);

const auto element_count = allocation_size / sizeof(*src_allocation.ptr());
constexpr auto thread_count = 1024;
const auto block_count = element_count / thread_count + 1;
constexpr int expected_value = 42;
HIP_CHECK(hipSetDevice(src_device));
VectorSet<<<block_count, thread_count, 0, kernel_stream>>>(src_allocation.ptr(), expected_value,
element_count);
HIP_CHECK(hipGetLastError());

HIP_CHECK(memcpy_func(dst_allocation.ptr(), src_allocation.ptr(), allocation_size));
if constexpr (should_synchronize) {
HIP_CHECK(hipStreamSynchronize(kernel_stream));
}

HIP_CHECK(
hipMemcpy(result.host_ptr(), dst_allocation.ptr(), allocation_size, hipMemcpyDeviceToHost));
if constexpr (enable_peer_access) {
// If we've gotten this far, EnablePeerAccess must have succeeded, so we
// only need to check this condition
HIP_CHECK(hipDeviceDisablePeerAccess(dst_device));
}

ArrayFindIfNot(result.host_ptr(), expected_value, element_count);
}

template <bool should_synchronize, typename F> void MemcpyWithDirectionCommonTests(F memcpy_func) {
using namespace std::placeholders;
SECTION("Device to host") {
MemcpyDeviceToHostShell<should_synchronize>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyDeviceToHost));
}

SECTION("Device to host with default kind") {
MemcpyDeviceToHostShell<should_synchronize>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyDefault));
}

SECTION("Host to device") {
MemcpyHostToDeviceShell<should_synchronize>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyHostToDevice));
}

SECTION("Host to device with default kind") {
MemcpyHostToDeviceShell<should_synchronize>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyDefault));
}

SECTION("Host to host") {
MemcpyHostToHostShell<should_synchronize>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyHostToHost));
}

SECTION("Host to host with default kind") {
MemcpyHostToHostShell<should_synchronize>(std::bind(memcpy_func, _1, _2, _3, hipMemcpyDefault));
}

SECTION("Device to device") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<should_synchronize, true>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyDeviceToDevice));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<should_synchronize, false>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyDeviceToDevice));
}
}

SECTION("Device to device with default kind") {
SECTION("Peer access enabled") {
MemcpyDeviceToDeviceShell<should_synchronize, true>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyDefault));
}
SECTION("Peer access disabled") {
MemcpyDeviceToDeviceShell<should_synchronize, false>(
std::bind(memcpy_func, _1, _2, _3, hipMemcpyDefault));
}
}
}

// Synchronization behavior checks
template <typename F>
void MemcpySyncBehaviorCheck(F memcpy_func, const bool should_sync,
const hipStream_t kernel_stream) {
LaunchDelayKernel(std::chrono::milliseconds{100}, kernel_stream);
HIP_CHECK(memcpy_func());
if (should_sync) {
HIP_CHECK(hipStreamQuery(kernel_stream));
} else {
HIP_CHECK_ERROR(hipStreamQuery(kernel_stream), hipErrorNotReady);
}
}

template <typename F>
void MemcpyHtoDSyncBehavior(F memcpy_func, const bool should_sync,
const hipStream_t kernel_stream = nullptr) {
using LA = LinearAllocs;
const auto host_alloc_type = GENERATE(LA::malloc, LA::hipHostMalloc);
LinearAllocGuard<int> host_alloc(host_alloc_type, kPageSize);
LinearAllocGuard<int> device_alloc(LA::hipMalloc, kPageSize);
MemcpySyncBehaviorCheck(std::bind(memcpy_func, device_alloc.ptr(), host_alloc.ptr(), kPageSize),
should_sync, kernel_stream);
}

template <typename F>
void MemcpyDtoHPageableSyncBehavior(F memcpy_func, const bool should_sync,
const hipStream_t kernel_stream = nullptr) {
LinearAllocGuard<int> host_alloc(LinearAllocs::malloc, kPageSize);
LinearAllocGuard<int> device_alloc(LinearAllocs::hipMalloc, kPageSize);
MemcpySyncBehaviorCheck(std::bind(memcpy_func, host_alloc.ptr(), device_alloc.ptr(), kPageSize),
should_sync, kernel_stream);
}

template <typename F>
void MemcpyDtoHPinnedSyncBehavior(F memcpy_func, const bool should_sync,
const hipStream_t kernel_stream = nullptr) {
LinearAllocGuard<int> host_alloc(LinearAllocs::hipHostMalloc, kPageSize);
LinearAllocGuard<int> device_alloc(LinearAllocs::hipMalloc, kPageSize);
MemcpySyncBehaviorCheck(std::bind(memcpy_func, host_alloc.ptr(), device_alloc.ptr(), kPageSize),
should_sync, kernel_stream);
}

template <typename F>
void MemcpyDtoDSyncBehavior(F memcpy_func, const bool should_sync,
const hipStream_t kernel_stream = nullptr) {
LinearAllocGuard<int> src_alloc(LinearAllocs::hipMalloc, kPageSize);
LinearAllocGuard<int> dst_alloc(LinearAllocs::hipMalloc, kPageSize);
MemcpySyncBehaviorCheck(std::bind(memcpy_func, dst_alloc.ptr(), src_alloc.ptr(), kPageSize),
should_sync, kernel_stream);
}

template <typename F>
void MemcpyHtoHSyncBehavior(F memcpy_func, const bool should_sync,
const hipStream_t kernel_stream = nullptr) {
using LA = LinearAllocs;
const auto src_alloc_type = GENERATE(LA::malloc, LA::hipHostMalloc);
const auto dst_alloc_type = GENERATE(LA::malloc, LA::hipHostMalloc);

LinearAllocGuard<int> src_alloc(src_alloc_type, kPageSize);
LinearAllocGuard<int> dst_alloc(dst_alloc_type, kPageSize);
MemcpySyncBehaviorCheck(std::bind(memcpy_func, dst_alloc.ptr(), src_alloc.ptr(), kPageSize),
should_sync, kernel_stream);
}

// Common negative tests
template <typename F> void MemcpyCommonNegativeTests(F f, void* dst, void* src, size_t count) {
SECTION("dst == nullptr") { HIP_CHECK_ERROR(f(nullptr, src, count), hipErrorInvalidValue); }
SECTION("src == nullptr") { HIP_CHECK_ERROR(f(dst, nullptr, count), hipErrorInvalidValue); }
}

template <typename F>
void MemcpyWithDirectionCommonNegativeTests(F f, void* dst, void* src, size_t count,
hipMemcpyKind kind) {
using namespace std::placeholders;
MemcpyCommonNegativeTests(std::bind(f, _1, _2, _3, kind), dst, src, count);

// Disabled on AMD due to defect - EXSWHTEC-128
#if HT_NVIDIA
SECTION("Invalid MemcpyKind") {
HIP_CHECK_ERROR(f(dst, src, count, static_cast<hipMemcpyKind>(-1)),
hipErrorInvalidMemcpyDirection);
}
#endif
}
Loading