2016-10-11 12:09:58 -05:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2015-2016 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-01-27 09:20:14 -06:00
|
|
|
/* HIT_START
|
2017-02-22 19:16:35 -06:00
|
|
|
* BUILD: %t %s
|
2017-01-27 09:20:14 -06:00
|
|
|
* RUN: %t
|
|
|
|
|
* HIT_END
|
|
|
|
|
*/
|
|
|
|
|
|
2016-10-11 12:09:58 -05:00
|
|
|
#include<hip/hip_runtime.h>
|
|
|
|
|
#include<hip/hip_runtime_api.h>
|
2017-01-27 09:20:14 -06:00
|
|
|
#include"test_common.h"
|
2016-10-11 12:09:58 -05:00
|
|
|
#include<iostream>
|
|
|
|
|
|
|
|
|
|
#define NUM 1024
|
|
|
|
|
#define SIZE 1024*4
|
|
|
|
|
|
2016-10-11 13:50:31 -05:00
|
|
|
#ifdef __HIP_PLATFORM_HCC__
|
2017-02-22 19:16:35 -06:00
|
|
|
__attribute__((address_space(1))) int globalIn[NUM];
|
|
|
|
|
__attribute__((address_space(1))) int globalOut[NUM];
|
2016-10-11 13:50:31 -05:00
|
|
|
#endif
|
2016-10-11 12:09:58 -05:00
|
|
|
|
2016-10-11 13:50:31 -05:00
|
|
|
#ifdef __HIP_PLATFORM_NVCC__
|
2017-02-22 19:16:35 -06:00
|
|
|
__device__ int globalIn[NUM];
|
|
|
|
|
__device__ int globalOut[NUM];
|
2016-10-11 13:50:31 -05:00
|
|
|
#endif
|
2016-10-11 12:09:58 -05:00
|
|
|
|
|
|
|
|
__global__ void Assign(hipLaunchParm lp, int* Out)
|
|
|
|
|
{
|
|
|
|
|
int tid = hipThreadIdx_x + hipBlockIdx_x * hipBlockDim_x;
|
2017-02-22 19:16:35 -06:00
|
|
|
Out[tid] = globalIn[tid];
|
|
|
|
|
globalOut[tid] = globalIn[tid];
|
2016-10-11 12:09:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
2017-02-22 19:16:35 -06:00
|
|
|
int *A, *Am, *B, *Ad, *C, *Cm;
|
2016-10-11 12:09:58 -05:00
|
|
|
A = new int[NUM];
|
|
|
|
|
B = new int[NUM];
|
2017-02-22 19:16:35 -06:00
|
|
|
C = new int[NUM];
|
2016-10-11 13:29:46 -05:00
|
|
|
for(unsigned i=0;i<NUM;i++) {
|
2016-10-11 12:09:58 -05:00
|
|
|
A[i] = -1*i;
|
|
|
|
|
B[i] = 0;
|
2017-02-22 19:16:35 -06:00
|
|
|
C[i] = 0;
|
2016-10-11 12:09:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipMalloc((void**)&Ad, SIZE);
|
2017-02-01 17:54:59 -06:00
|
|
|
hipHostMalloc((void**)&Am, SIZE);
|
2017-02-22 19:16:35 -06:00
|
|
|
hipHostMalloc((void**)&Cm, SIZE);
|
2017-02-01 17:54:59 -06:00
|
|
|
for(unsigned i=0;i<NUM;i++) {
|
|
|
|
|
Am[i] = -1*i;
|
2017-02-22 19:16:35 -06:00
|
|
|
Cm[i] = 0;
|
2017-02-01 17:54:59 -06:00
|
|
|
}
|
2016-10-11 13:29:46 -05:00
|
|
|
|
|
|
|
|
hipStream_t stream;
|
|
|
|
|
hipStreamCreate(&stream);
|
2017-02-22 19:16:35 -06:00
|
|
|
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), Am, SIZE, 0, hipMemcpyHostToDevice, stream);
|
2016-10-11 13:29:46 -05:00
|
|
|
hipStreamSynchronize(stream);
|
|
|
|
|
hipLaunchKernel(Assign, dim3(1,1,1), dim3(NUM,1,1), 0, 0, Ad);
|
|
|
|
|
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
|
2017-02-22 19:16:35 -06:00
|
|
|
hipMemcpyFromSymbolAsync(Cm, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost, stream);
|
|
|
|
|
hipStreamSynchronize(stream);
|
2016-10-11 13:29:46 -05:00
|
|
|
for(unsigned i=0;i<NUM;i++) {
|
2017-02-22 19:16:35 -06:00
|
|
|
assert(Am[i] == B[i]);
|
|
|
|
|
assert(Am[i] == Cm[i]);
|
2016-10-11 13:29:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(unsigned i=0;i<NUM;i++) {
|
|
|
|
|
A[i] = -2*i;
|
|
|
|
|
B[i] = 0;
|
|
|
|
|
}
|
2016-10-13 10:31:56 -05:00
|
|
|
|
2017-02-22 19:16:35 -06:00
|
|
|
hipMemcpyToSymbol(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice);
|
2016-10-11 12:09:58 -05:00
|
|
|
hipLaunchKernel(Assign, dim3(1,1,1), dim3(NUM,1,1), 0, 0, Ad);
|
|
|
|
|
hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost);
|
|
|
|
|
for(unsigned i=0;i<NUM;i++) {
|
|
|
|
|
assert(A[i] == B[i]);
|
|
|
|
|
}
|
2017-02-22 19:16:35 -06:00
|
|
|
|
2017-01-27 09:20:14 -06:00
|
|
|
passed();
|
2016-10-11 12:09:58 -05:00
|
|
|
}
|