2016-08-31 13:56:07 -05:00
|
|
|
/*
|
2017-03-17 13:11:34 -05:00
|
|
|
Copyright (c) 2015-2017 Advanced Micro Devices, Inc. All rights reserved.
|
2016-10-15 23:05:04 +05:30
|
|
|
|
2016-08-31 13:56:07 -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:
|
2016-10-15 23:05:04 +05:30
|
|
|
|
2016-08-31 13:56:07 -05:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
2016-10-15 23:05:04 +05:30
|
|
|
|
|
|
|
|
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
|
2016-08-31 13:56:07 -05:00
|
|
|
THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-10-04 22:21:10 +05:30
|
|
|
#include "hip/hip_runtime.h"
|
|
|
|
|
#include "hip/hip_runtime_api.h"
|
2016-08-31 13:56:07 -05:00
|
|
|
#include<iostream>
|
|
|
|
|
#include<fstream>
|
|
|
|
|
#include<vector>
|
|
|
|
|
|
|
|
|
|
#define LEN 64
|
|
|
|
|
#define SIZE LEN<<2
|
|
|
|
|
|
2016-09-04 21:25:14 +05:30
|
|
|
#define fileName "vcpy_kernel.code"
|
2016-09-04 16:26:16 +05:30
|
|
|
#define kernel_name "hello_world"
|
2016-08-31 13:56:07 -05:00
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
|
float *A, *B;
|
|
|
|
|
hipDeviceptr_t Ad, Bd;
|
|
|
|
|
A = new float[LEN];
|
|
|
|
|
B = new float[LEN];
|
|
|
|
|
|
|
|
|
|
for(uint32_t i=0;i<LEN;i++){
|
|
|
|
|
A[i] = i*1.0f;
|
|
|
|
|
B[i] = 0.0f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hipInit(0);
|
2016-09-04 20:37:29 +05:30
|
|
|
hipDevice_t device;
|
|
|
|
|
hipCtx_t context;
|
|
|
|
|
hipDeviceGet(&device, 0);
|
|
|
|
|
hipCtxCreate(&context, 0, device);
|
2016-08-31 13:56:07 -05:00
|
|
|
|
|
|
|
|
hipMalloc((void**)&Ad, SIZE);
|
|
|
|
|
hipMalloc((void**)&Bd, SIZE);
|
|
|
|
|
|
|
|
|
|
hipMemcpyHtoD(Ad, A, SIZE);
|
|
|
|
|
hipMemcpyHtoD(Bd, B, SIZE);
|
|
|
|
|
hipModule_t Module;
|
|
|
|
|
hipFunction_t Function;
|
|
|
|
|
hipModuleLoad(&Module, fileName);
|
|
|
|
|
hipModuleGetFunction(&Function, Module, kernel_name);
|
|
|
|
|
|
2016-09-01 10:39:14 -05:00
|
|
|
#ifdef __HIP_PLATFORM_HCC__
|
2016-09-02 13:17:17 -05:00
|
|
|
uint32_t len = LEN;
|
|
|
|
|
uint32_t one = 1;
|
2016-08-31 13:56:07 -05:00
|
|
|
|
2016-10-14 23:19:25 -05:00
|
|
|
struct {
|
|
|
|
|
uint32_t _hidden[6];
|
|
|
|
|
void * _Ad;
|
|
|
|
|
void * _Bd;
|
|
|
|
|
} args;
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<6; i++) {
|
|
|
|
|
args._hidden[i] = 0;
|
|
|
|
|
}
|
|
|
|
|
args._Ad = Ad;
|
|
|
|
|
args._Bd = Bd;
|
|
|
|
|
|
2016-09-01 10:39:14 -05:00
|
|
|
#endif
|
2016-08-31 13:56:07 -05:00
|
|
|
|
2016-09-01 10:39:14 -05:00
|
|
|
#ifdef __HIP_PLATFORM_NVCC__
|
2016-10-14 23:19:25 -05:00
|
|
|
struct {
|
|
|
|
|
uint32_t _hidden[1];
|
|
|
|
|
void * _Ad;
|
|
|
|
|
void * _Bd;
|
|
|
|
|
} args;
|
|
|
|
|
|
|
|
|
|
args._hidden[0] = 0;
|
|
|
|
|
args._Ad = Ad;
|
|
|
|
|
args._Bd = Bd;
|
2016-09-01 10:39:14 -05:00
|
|
|
#endif
|
2016-08-31 13:56:07 -05:00
|
|
|
|
|
|
|
|
|
2016-10-14 23:19:25 -05:00
|
|
|
size_t size = sizeof(args);
|
2016-08-31 13:56:07 -05:00
|
|
|
|
|
|
|
|
void *config[] = {
|
2016-10-14 23:19:25 -05:00
|
|
|
HIP_LAUNCH_PARAM_BUFFER_POINTER, &args,
|
2016-08-31 13:56:07 -05:00
|
|
|
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
|
|
|
|
|
HIP_LAUNCH_PARAM_END
|
|
|
|
|
};
|
|
|
|
|
|
2017-03-17 13:11:34 -05:00
|
|
|
hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, 0, NULL, (void**)&config);
|
2016-08-31 13:56:07 -05:00
|
|
|
|
|
|
|
|
hipMemcpyDtoH(B, Bd, SIZE);
|
2016-10-14 23:19:25 -05:00
|
|
|
int mismatchCount = 0;
|
|
|
|
|
for(uint32_t i=0;i<LEN;i++){
|
|
|
|
|
if (A[i] != B[i]) {
|
|
|
|
|
mismatchCount++;
|
|
|
|
|
std::cout<<"error: mismatch " << A[i]<<" != "<<B[i]<<std::endl;
|
|
|
|
|
}
|
2016-08-31 13:56:07 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-14 23:19:25 -05:00
|
|
|
if (mismatchCount == 0) {
|
|
|
|
|
std::cout << "PASSED!\n";
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "FAILED!\n";
|
|
|
|
|
};
|
|
|
|
|
|
2016-09-04 20:37:29 +05:30
|
|
|
hipCtxDestroy(context);
|
2016-08-31 13:56:07 -05:00
|
|
|
return 0;
|
|
|
|
|
}
|