2016-03-25 05:49:33 -05:00
|
|
|
/*
|
2017-02-03 10:53:36 -06:00
|
|
|
Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved.
|
2016-03-25 05:49:33 -05:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INNCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANNY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-03-25 06:41:49 -05:00
|
|
|
/*
|
|
|
|
|
* Test for checking the functionality of
|
|
|
|
|
* hipError_t hipDeviceSynchronize();
|
2018-03-12 11:29:03 +05:30
|
|
|
*/
|
2016-03-25 06:41:49 -05:00
|
|
|
|
2016-09-23 16:15:31 +05:30
|
|
|
/* HIT_START
|
2017-02-03 10:53:36 -06:00
|
|
|
* BUILD: %t %s ../../test_common.cpp
|
2016-09-23 16:15:31 +05:30
|
|
|
* RUN: %t
|
|
|
|
|
* HIT_END
|
|
|
|
|
*/
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
#include "test_common.h"
|
2016-03-25 05:49:33 -05:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
#define _SIZE sizeof(int) * 1024 * 1024
|
2016-03-25 06:41:49 -05:00
|
|
|
#define NUM_STREAMS 2
|
2016-03-25 05:49:33 -05:00
|
|
|
|
2018-10-17 12:01:44 +05:30
|
|
|
__global__ void Iter(int* Ad, int num) {
|
2017-11-19 01:54:12 +00:00
|
|
|
int tx = threadIdx.x + blockIdx.x * blockDim.x;
|
2018-03-12 11:29:03 +05:30
|
|
|
// Kernel loop designed to execute very slowly... ... ... so we can test timing-related
|
|
|
|
|
// behavior below
|
|
|
|
|
if (tx == 0) {
|
|
|
|
|
for (int i = 0; i < num; i++) {
|
2016-03-25 06:41:49 -05:00
|
|
|
Ad[tx] += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-03-25 05:49:33 -05:00
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
int main() {
|
|
|
|
|
int* A[NUM_STREAMS];
|
|
|
|
|
int* Ad[NUM_STREAMS];
|
2016-03-25 05:49:33 -05:00
|
|
|
hipStream_t stream[NUM_STREAMS];
|
2018-03-12 11:29:03 +05:30
|
|
|
for (int i = 0; i < NUM_STREAMS; i++) {
|
2016-03-25 06:41:49 -05:00
|
|
|
HIPCHECK(hipHostMalloc((void**)&A[i], _SIZE, hipHostMallocDefault));
|
2016-03-25 05:49:33 -05:00
|
|
|
A[i][0] = 1;
|
|
|
|
|
HIPCHECK(hipMalloc((void**)&Ad[i], _SIZE));
|
|
|
|
|
HIPCHECK(hipStreamCreate(&stream[i]));
|
|
|
|
|
}
|
2018-03-12 11:29:03 +05:30
|
|
|
for (int i = 0; i < NUM_STREAMS; i++) {
|
2016-03-25 05:49:33 -05:00
|
|
|
HIPCHECK(hipMemcpyAsync(Ad[i], A[i], _SIZE, hipMemcpyHostToDevice, stream[i]));
|
2016-03-25 06:41:49 -05:00
|
|
|
}
|
2018-03-12 11:29:03 +05:30
|
|
|
for (int i = 0; i < NUM_STREAMS; i++) {
|
2018-10-17 12:01:44 +05:30
|
|
|
hipLaunchKernelGGL(HIP_KERNEL_NAME(Iter), dim3(1), dim3(1), 0, stream[i], Ad[i], 1 << 30);
|
2016-03-25 06:41:49 -05:00
|
|
|
}
|
2018-03-12 11:29:03 +05:30
|
|
|
for (int i = 0; i < NUM_STREAMS; i++) {
|
2016-03-25 05:49:33 -05:00
|
|
|
HIPCHECK(hipMemcpyAsync(A[i], Ad[i], _SIZE, hipMemcpyDeviceToHost, stream[i]));
|
|
|
|
|
}
|
2016-11-10 10:53:10 -06:00
|
|
|
|
2017-02-03 10:53:36 -06:00
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
// This first check but relies on the kernel running for so long that the D2H async memcopy has
|
|
|
|
|
// not started yet. This will be true in an optimal asynchronous implementation. Conservative
|
|
|
|
|
// implementations which synchronize the hipMemcpyAsync will fail, ie if
|
|
|
|
|
// HIP_LAUNCH_BLOCKING=true
|
|
|
|
|
HIPASSERT(1 << 30 != A[NUM_STREAMS - 1][0] - 1);
|
2016-03-25 06:41:49 -05:00
|
|
|
HIPCHECK(hipDeviceSynchronize());
|
2018-03-12 11:29:03 +05:30
|
|
|
HIPASSERT(1 << 30 == A[NUM_STREAMS - 1][0] - 1);
|
2016-03-25 06:41:49 -05:00
|
|
|
passed();
|
2016-03-25 05:49:33 -05:00
|
|
|
}
|