2017-11-09 22:35:29 +05:30
|
|
|
/*
|
2019-05-20 18:46:23 +03:00
|
|
|
Copyright (c) 2015-present Advanced Micro Devices, Inc. All rights reserved.
|
2017-11-09 22:35:29 +05:30
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "hip/hip_runtime.h"
|
2018-08-08 22:28:13 +05:30
|
|
|
//#include "hip/hip_runtime_api.h"
|
2017-11-09 22:35:29 +05:30
|
|
|
#include <iostream>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <vector>
|
2018-08-08 22:28:13 +05:30
|
|
|
//#include <hip/hip_hcc.h>
|
2017-11-09 22:35:29 +05:30
|
|
|
|
2018-08-08 22:28:13 +05:30
|
|
|
#define fileName "tex2dKernel.code"
|
2017-11-09 22:35:29 +05:30
|
|
|
|
|
|
|
|
texture<float, 2, hipReadModeElementType> tex;
|
2017-11-15 18:23:28 +05:30
|
|
|
bool testResult = false;
|
2017-11-09 22:35:29 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
#define HIP_CHECK(cmd) \
|
|
|
|
|
{ \
|
|
|
|
|
hipError_t status = cmd; \
|
|
|
|
|
if (status != hipSuccess) { \
|
|
|
|
|
std::cout << "error: #" << status << " (" << hipGetErrorString(status) \
|
|
|
|
|
<< ") at line:" << __LINE__ << ": " << #cmd << std::endl; \
|
|
|
|
|
abort(); \
|
|
|
|
|
} \
|
|
|
|
|
}
|
2017-11-09 22:35:29 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
bool runTest(int argc, char** argv) {
|
2017-11-09 22:35:29 +05:30
|
|
|
unsigned int width = 256;
|
|
|
|
|
unsigned int height = 256;
|
|
|
|
|
unsigned int size = width * height * sizeof(float);
|
2018-03-12 11:29:03 +05:30
|
|
|
float* hData = (float*)malloc(size);
|
2017-11-09 22:35:29 +05:30
|
|
|
memset(hData, 0, size);
|
|
|
|
|
for (int i = 0; i < height; i++) {
|
|
|
|
|
for (int j = 0; j < width; j++) {
|
2018-03-12 11:29:03 +05:30
|
|
|
hData[i * width + j] = i * width + j;
|
2017-11-09 22:35:29 +05:30
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hipModule_t Module;
|
|
|
|
|
HIP_CHECK(hipModuleLoad(&Module, fileName));
|
|
|
|
|
|
|
|
|
|
hipArray* array;
|
2018-03-12 11:29:03 +05:30
|
|
|
HIP_ARRAY_DESCRIPTOR desc;
|
|
|
|
|
desc.format = HIP_AD_FORMAT_FLOAT;
|
|
|
|
|
desc.numChannels = 1;
|
|
|
|
|
desc.width = width;
|
|
|
|
|
desc.height = height;
|
2017-11-09 22:35:29 +05:30
|
|
|
hipArrayCreate(&array, &desc);
|
|
|
|
|
|
|
|
|
|
hip_Memcpy2D copyParam;
|
2018-03-12 11:29:03 +05:30
|
|
|
memset(©Param, 0, sizeof(copyParam));
|
|
|
|
|
copyParam.dstMemoryType = hipMemoryTypeArray;
|
|
|
|
|
copyParam.dstArray = array;
|
|
|
|
|
copyParam.srcMemoryType = hipMemoryTypeHost;
|
|
|
|
|
copyParam.srcHost = hData;
|
|
|
|
|
copyParam.srcPitch = width * sizeof(float);
|
2019-05-22 18:31:39 +03:00
|
|
|
copyParam.WidthInBytes = copyParam.srcPitch;
|
|
|
|
|
copyParam.Height = height;
|
2017-11-21 12:36:24 +05:30
|
|
|
hipMemcpyParam2D(©Param);
|
2018-03-12 11:29:03 +05:30
|
|
|
|
2017-11-19 22:10:46 +05:30
|
|
|
textureReference* texref;
|
|
|
|
|
hipModuleGetTexRef(&texref, Module, "tex");
|
|
|
|
|
hipTexRefSetAddressMode(texref, 0, hipAddressModeWrap);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipTexRefSetAddressMode(texref, 1, hipAddressModeWrap);
|
|
|
|
|
hipTexRefSetFilterMode(texref, hipFilterModePoint);
|
2017-11-19 22:10:46 +05:30
|
|
|
hipTexRefSetFlags(texref, 0);
|
2018-03-12 11:29:03 +05:30
|
|
|
hipTexRefSetFormat(texref, HIP_AD_FORMAT_FLOAT, 1);
|
2017-11-19 22:10:46 +05:30
|
|
|
hipTexRefSetArray(texref, array, HIP_TRSA_OVERRIDE_FORMAT);
|
2017-11-09 22:35:29 +05:30
|
|
|
|
|
|
|
|
float* dData = NULL;
|
2018-03-12 11:29:03 +05:30
|
|
|
hipMalloc((void**)&dData, size);
|
2017-11-09 22:35:29 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
struct {
|
|
|
|
|
void* _Ad;
|
|
|
|
|
unsigned int _Bd;
|
|
|
|
|
unsigned int _Cd;
|
|
|
|
|
} args;
|
2018-08-08 22:28:13 +05:30
|
|
|
args._Ad = (void*) dData;
|
2017-11-09 22:35:29 +05:30
|
|
|
args._Bd = width;
|
2018-03-12 11:29:03 +05:30
|
|
|
args._Cd = height;
|
2017-11-09 22:35:29 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
size_t sizeTemp = sizeof(args);
|
2017-11-09 22:35:29 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args, HIP_LAUNCH_PARAM_BUFFER_SIZE,
|
|
|
|
|
&sizeTemp, HIP_LAUNCH_PARAM_END};
|
2017-11-09 22:35:29 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
hipFunction_t Function;
|
|
|
|
|
HIP_CHECK(hipModuleGetFunction(&Function, Module, "tex2dKernel"));
|
2017-11-09 22:35:29 +05:30
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
int temp1 = width / 16;
|
|
|
|
|
int temp2 = height / 16;
|
|
|
|
|
HIP_CHECK(
|
|
|
|
|
hipModuleLaunchKernel(Function, 16, 16, 1, temp1, temp2, 1, 0, 0, NULL, (void**)&config));
|
2017-11-09 22:35:29 +05:30
|
|
|
hipDeviceSynchronize();
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
float* hOutputData = (float*)malloc(size);
|
|
|
|
|
memset(hOutputData, 0, size);
|
2017-11-09 22:35:29 +05:30
|
|
|
hipMemcpy(hOutputData, dData, size, hipMemcpyDeviceToHost);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < height; i++) {
|
|
|
|
|
for (int j = 0; j < width; j++) {
|
2018-03-12 11:29:03 +05:30
|
|
|
if (hData[i * width + j] != hOutputData[i * width + j]) {
|
|
|
|
|
printf("Difference [ %d %d ]:%f ----%f\n", i, j, hData[i * width + j],
|
|
|
|
|
hOutputData[i * width + j]);
|
2017-11-09 22:35:29 +05:30
|
|
|
testResult = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
hipFree(dData);
|
|
|
|
|
hipFreeArray(array);
|
2017-11-15 18:23:28 +05:30
|
|
|
return true;
|
2017-11-09 22:35:29 +05:30
|
|
|
}
|
|
|
|
|
|
2018-03-12 11:29:03 +05:30
|
|
|
int main(int argc, char** argv) {
|
2017-11-09 22:35:29 +05:30
|
|
|
hipInit(0);
|
2017-11-15 18:23:28 +05:30
|
|
|
testResult = runTest(argc, argv);
|
2017-11-09 22:35:29 +05:30
|
|
|
printf("%s ...\n", testResult ? "PASSED" : "FAILED");
|
|
|
|
|
exit(testResult ? EXIT_SUCCESS : EXIT_FAILURE);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|