Merge branch 'master' into amd-master-next
Conflicts: CMakeLists.txt tests/src/texture/simpleTexture2DLayered.cpp tests/src/texture/simpleTexture3D.cpp Change-Id: I4aa4754d391b5f37ddf15fa0bcfc84d9da020119
This commit is contained in:
@@ -34,42 +34,52 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA
|
||||
|
||||
using namespace std;
|
||||
|
||||
const string directed_dir = "directed_tests" + string(PATH_SEPERATOR_STR) + "hipEnvVar";
|
||||
const string dir = "." + string(PATH_SEPERATOR_STR) + "hipEnvVar";
|
||||
const string directed_dir = string(".") + PATH_SEPERATOR_STR + "directed_tests" + PATH_SEPERATOR_STR + "hipEnvVar";
|
||||
const string dir = string(".") + PATH_SEPERATOR_STR + "hipEnvVar";
|
||||
|
||||
int getDeviceNumber() {
|
||||
char buff[512];
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
FILE* in = popen((directed_dir + " -c").c_str(), "r");
|
||||
if(fgets(buff, 512, in) == NULL){
|
||||
pclose(in);
|
||||
//Check at same level
|
||||
in = popen((dir + " -c").c_str(), "r");
|
||||
int readHipEnvVar(string flags, char* buff){
|
||||
|
||||
std::cout << "\nFinding hipEnvVar in " << directed_dir << "...\n";
|
||||
FILE* directed_in = popen((directed_dir + flags).c_str(), "r");
|
||||
|
||||
if(fgets(buff, 512, directed_in) == NULL){
|
||||
std::cout << "Finding hipEnvVar in " << dir << "...\n";
|
||||
FILE* in = popen((dir + flags).c_str(), "r");
|
||||
if(fgets(buff, 512, in) == NULL){
|
||||
pclose(directed_in);
|
||||
pclose(in);
|
||||
return 1;
|
||||
}
|
||||
pclose(in);
|
||||
}
|
||||
std::cout << "hipEnvVar Found!\n";
|
||||
pclose(directed_in);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getDeviceNumber(bool print_err=true) {
|
||||
char buff[512];
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
|
||||
if (readHipEnvVar(string(" -c"), buff)){
|
||||
strncpy(buff, "1", 512);
|
||||
if (print_err){
|
||||
std::cerr << "The system cannot find hipEnvVar, using 1 as number of devices\n";
|
||||
}
|
||||
}
|
||||
if (print_err) {
|
||||
std::cout << buff;
|
||||
}
|
||||
cout << buff;
|
||||
pclose(in);
|
||||
return atoi(buff);
|
||||
}
|
||||
|
||||
// Query the current device ID remotely to hipEnvVar
|
||||
void getDevicePCIBusNumRemote(int deviceID, char* pciBusID) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
FILE* in = popen((directed_dir + " -d " + std::to_string(deviceID)).c_str(), "r");
|
||||
if(fgets(pciBusID, 100, in) == NULL){
|
||||
pclose(in);
|
||||
//Check at same level
|
||||
in = popen((dir + " -d").c_str(), "r");
|
||||
if(fgets(pciBusID, 100, in) == NULL){
|
||||
pclose(in);
|
||||
return;
|
||||
}
|
||||
if (readHipEnvVar((" -d " + std::to_string(deviceID)), pciBusID)){
|
||||
std::cerr << "The system cannot find hipEnvVar\n";
|
||||
}
|
||||
cout << pciBusID;
|
||||
pclose(in);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,15 +88,15 @@ void getDevicePCIBusNum(int deviceID, char* pciBusID) {
|
||||
hipDevice_t deviceT;
|
||||
hipDeviceGet(&deviceT, deviceID);
|
||||
|
||||
memset(pciBusID, 0, 100);
|
||||
hipDeviceGetPCIBusId(pciBusID, 100, deviceT);
|
||||
memset(pciBusID, 0, 512);
|
||||
hipDeviceGetPCIBusId(pciBusID, 512, deviceT);
|
||||
}
|
||||
|
||||
int main() {
|
||||
unsetenv(HIP_VISIBLE_DEVICES_STR);
|
||||
unsetenv(CUDA_VISIBLE_DEVICES_STR);
|
||||
std::vector<std::string> devPCINum;
|
||||
char pciBusID[100];
|
||||
char pciBusID[512];
|
||||
// collect the device pci bus ID for all devices
|
||||
int totalDeviceNum = getDeviceNumber();
|
||||
std::cout << "The total number of available devices is " << totalDeviceNum << std::endl
|
||||
@@ -116,27 +126,27 @@ int main() {
|
||||
// check when set an invalid device number
|
||||
setenv("HIP_VISIBLE_DEVICES", "1000,0,1", 1);
|
||||
setenv("CUDA_VISIBLE_DEVICES", "1000,0,1", 1);
|
||||
assert(getDeviceNumber() == 0);
|
||||
assert(getDeviceNumber(false) == 0);
|
||||
|
||||
if (totalDeviceNum > 2) {
|
||||
setenv("HIP_VISIBLE_DEVICES", "0,1,1000,2", 1);
|
||||
setenv("CUDA_VISIBLE_DEVICES", "0,1,1000,2", 1);
|
||||
assert(getDeviceNumber() == 2);
|
||||
assert(getDeviceNumber(false) == 2);
|
||||
|
||||
setenv("HIP_VISIBLE_DEVICES", "0,1,2", 1);
|
||||
setenv("CUDA_VISIBLE_DEVICES", "0,1,2", 1);
|
||||
assert(getDeviceNumber() == 3);
|
||||
assert(getDeviceNumber(false) == 3);
|
||||
// test if CUDA_VISIBLE_DEVICES will be accepted by the runtime
|
||||
unsetenv(HIP_VISIBLE_DEVICES_STR);
|
||||
unsetenv(CUDA_VISIBLE_DEVICES_STR);
|
||||
setenv("CUDA_VISIBLE_DEVICES", "0,1,2", 1);
|
||||
assert(getDeviceNumber() == 3);
|
||||
assert(getDeviceNumber(false) == 3);
|
||||
}
|
||||
|
||||
setenv("HIP_VISIBLE_DEVICES", "-100,0,1", 1);
|
||||
setenv("CUDA_VISIBLE_DEVICES", "-100,0,1", 1);
|
||||
assert(getDeviceNumber() == 0);
|
||||
assert(getDeviceNumber(false) == 0);
|
||||
|
||||
std::cout << "PASSED" << std::endl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
Copyright (c) 2015 - present 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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp LINK_OPTIONS hiprtc EXCLUDE_HIP_PLATFORM nvcc
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <test_common.h>
|
||||
|
||||
#define HIPRTC_GET_TYPE_NAME
|
||||
#include <hip/hiprtc.h>
|
||||
#include <hip/hip_runtime.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
static constexpr auto gpu_program{
|
||||
R"(
|
||||
#include <hip/hip_runtime.h>
|
||||
|
||||
namespace N1 { struct S1_t { int i; double d; }; }
|
||||
template<typename T>
|
||||
__global__ void f3(int *result) { *result = sizeof(T); }
|
||||
)"};
|
||||
|
||||
// note: this structure is also defined in GPU code string. Should ideally
|
||||
// be in a header file included by both GPU code string and by CPU code.
|
||||
namespace N1 { struct S1_t { int i; double d; }; };
|
||||
|
||||
template <typename T>
|
||||
std::string getKernelNameForType(void)
|
||||
{
|
||||
std::string type_name;
|
||||
hiprtcGetTypeName<T>(&type_name);
|
||||
return std::string{"f3<"} + type_name + '>';
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
hiprtcProgram prog;
|
||||
hiprtcCreateProgram(&prog, gpu_program, "gpu_program.cu", 0, nullptr,
|
||||
nullptr);
|
||||
|
||||
vector<string> name_vec;
|
||||
vector<int> expected_result;
|
||||
|
||||
name_vec.push_back(getKernelNameForType<int>());
|
||||
expected_result.push_back(sizeof(int));
|
||||
name_vec.push_back(getKernelNameForType<double>());
|
||||
expected_result.push_back(sizeof(double));
|
||||
name_vec.push_back(getKernelNameForType<N1::S1_t>());
|
||||
expected_result.push_back(sizeof(N1::S1_t));
|
||||
|
||||
for (auto&& x : name_vec) hiprtcAddNameExpression(prog, x.c_str());
|
||||
|
||||
hipDeviceProp_t props;
|
||||
int device = 0;
|
||||
hipGetDeviceProperties(&props, device);
|
||||
std::string gfxName = "gfx" + std::to_string(props.gcnArch);
|
||||
std::string sarg = "--gpu-architecture=" + gfxName;
|
||||
const char* options[] = {
|
||||
sarg.c_str()
|
||||
};
|
||||
|
||||
hiprtcResult compileResult = hiprtcCompileProgram(prog, 1, options);
|
||||
|
||||
size_t logSize;
|
||||
hiprtcGetProgramLogSize(prog, &logSize);
|
||||
|
||||
if (logSize) {
|
||||
string log(logSize, '\0');
|
||||
hiprtcGetProgramLog(prog, &log[0]);
|
||||
|
||||
cout << log << '\n';
|
||||
}
|
||||
|
||||
if (compileResult != HIPRTC_SUCCESS) { failed("Compilation failed."); }
|
||||
|
||||
size_t codeSize;
|
||||
hiprtcGetCodeSize(prog, &codeSize);
|
||||
|
||||
vector<char> code(codeSize);
|
||||
hiprtcGetCode(prog, code.data());
|
||||
|
||||
hipModule_t module;
|
||||
hipModuleLoadDataEx(&module, code.data(), 0, nullptr, nullptr);
|
||||
|
||||
hipDeviceptr_t dResult;
|
||||
int hResult = 0;
|
||||
hipMalloc(&dResult, sizeof(hResult));
|
||||
hipMemcpyHtoD(dResult, &hResult, sizeof(hResult));
|
||||
|
||||
for (size_t i = 0; i < name_vec.size(); ++i) {
|
||||
const char *name;
|
||||
hiprtcGetLoweredName(prog, name_vec[i].c_str(), &name);
|
||||
|
||||
hipFunction_t kernel;
|
||||
hipModuleGetFunction(&kernel, module, name);
|
||||
|
||||
struct { hipDeviceptr_t a_; } args{dResult};
|
||||
|
||||
auto size = sizeof(args);
|
||||
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args,
|
||||
HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
|
||||
hipModuleLaunchKernel(kernel,
|
||||
1, 1, 1,
|
||||
1, 1, 1,
|
||||
0, nullptr,
|
||||
nullptr, config);
|
||||
|
||||
hipMemcpyDtoH(&hResult, dResult, sizeof(hResult));
|
||||
|
||||
if (expected_result[i] != hResult) { failed("Validation failed."); }
|
||||
}
|
||||
|
||||
hipFree(dResult);
|
||||
hipModuleUnload(module);
|
||||
|
||||
hiprtcDestroyProgram(&prog);
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/*
|
||||
Copyright (c) 2015-present 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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
#define WIDTH 4
|
||||
|
||||
#define NUM (WIDTH * WIDTH)
|
||||
|
||||
#define THREADS_PER_BLOCK_X 4
|
||||
#define THREADS_PER_BLOCK_Y 4
|
||||
#define THREADS_PER_BLOCK_Z 1
|
||||
|
||||
// Device (Kernel) function, it must be void
|
||||
template <typename T>
|
||||
__global__ void matrixTranspose(T* out, T* in, const int width) {
|
||||
int x = hipBlockDim_x * hipBlockIdx_x + hipThreadIdx_x;
|
||||
T val = in[x];
|
||||
for (int i = 0; i < width; i++) {
|
||||
for (int j = 0; j < width; j++) out[i * width + j] = __shfl(val, j * width + i);
|
||||
}
|
||||
}
|
||||
|
||||
// CPU implementation of matrix transpose
|
||||
template <typename T>
|
||||
void matrixTransposeCPUReference(T* output, T* input, const unsigned int width) {
|
||||
for (unsigned int j = 0; j < width; j++) {
|
||||
for (unsigned int i = 0; i < width; i++) {
|
||||
output[i * width + j] = input[j * width + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void runTest() {
|
||||
T* Matrix;
|
||||
T* TransposeMatrix;
|
||||
T* cpuTransposeMatrix;
|
||||
|
||||
T* gpuMatrix;
|
||||
T* gpuTransposeMatrix;
|
||||
|
||||
hipDeviceProp_t devProp;
|
||||
hipGetDeviceProperties(&devProp, 0);
|
||||
|
||||
int i;
|
||||
int errors;
|
||||
|
||||
Matrix = (T*)malloc(NUM * sizeof(T));
|
||||
TransposeMatrix = (T*)malloc(NUM * sizeof(T));
|
||||
cpuTransposeMatrix = (T*)malloc(NUM * sizeof(T));
|
||||
|
||||
// initialize the input data
|
||||
for (i = 0; i < NUM; i++) {
|
||||
Matrix[i] = (T)i * 10l;
|
||||
}
|
||||
|
||||
// allocate the memory on the device side
|
||||
hipMalloc((void**)&gpuMatrix, NUM * sizeof(T));
|
||||
hipMalloc((void**)&gpuTransposeMatrix, NUM * sizeof(T));
|
||||
|
||||
// Memory transfer from host to device
|
||||
hipMemcpy(gpuMatrix, Matrix, NUM * sizeof(T), hipMemcpyHostToDevice);
|
||||
|
||||
// Lauching kernel from host
|
||||
hipLaunchKernelGGL(matrixTranspose<T>, dim3(1), dim3(THREADS_PER_BLOCK_X * THREADS_PER_BLOCK_Y), 0, 0,
|
||||
gpuTransposeMatrix, gpuMatrix, WIDTH);
|
||||
|
||||
// Memory transfer from device to host
|
||||
hipMemcpy(TransposeMatrix, gpuTransposeMatrix, NUM * sizeof(T), hipMemcpyDeviceToHost);
|
||||
|
||||
// CPU MatrixTranspose computation
|
||||
matrixTransposeCPUReference(cpuTransposeMatrix, Matrix, WIDTH);
|
||||
|
||||
// verify the results
|
||||
errors = 0;
|
||||
double eps = 1.0E-6;
|
||||
for (i = 0; i < NUM; i++) {
|
||||
if (TransposeMatrix[i] != cpuTransposeMatrix[i]) {
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
||||
// free the resources on device side
|
||||
hipFree(gpuMatrix);
|
||||
hipFree(gpuTransposeMatrix);
|
||||
|
||||
// free the resources on host side
|
||||
free(Matrix);
|
||||
free(TransposeMatrix);
|
||||
free(cpuTransposeMatrix);
|
||||
|
||||
if (errors != 0) {
|
||||
failed("Mismatch present");
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
runTest<int>();
|
||||
runTest<float>();
|
||||
runTest<long>();
|
||||
runTest<long long>();
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
Copyright (c) 2015-present 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.
|
||||
*/
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include "test_common.h"
|
||||
|
||||
template <typename T>
|
||||
__global__ void shflDownSum(T* a, int size) {
|
||||
T val = a[threadIdx.x];
|
||||
for (int i = size / 2; i > 0; i /= 2) {
|
||||
val += __shfl_down(val, i, size);
|
||||
}
|
||||
a[threadIdx.x] = val;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
__global__ void shflUpSum(T* a, int size) {
|
||||
T val = a[threadIdx.x];
|
||||
for (int i = size / 2; i > 0; i /= 2) {
|
||||
val += __shfl_up(val, i, size);
|
||||
}
|
||||
a[threadIdx.x] = val;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void runTestShflUp() {
|
||||
const int size = 32;
|
||||
T a[size];
|
||||
T cpuSum = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
a[i] = i;
|
||||
cpuSum += a[i];
|
||||
}
|
||||
T* d_a;
|
||||
hipMalloc(&d_a, sizeof(T) * size);
|
||||
hipMemcpy(d_a, &a, sizeof(T) * size, hipMemcpyDefault);
|
||||
hipLaunchKernelGGL(shflUpSum<T>, 1, size, 0, 0, d_a, size);
|
||||
hipMemcpy(&a, d_a, sizeof(T) * size, hipMemcpyDefault);
|
||||
if (a[size - 1] != cpuSum) {
|
||||
hipFree(d_a);
|
||||
failed("Shfl Up Sum did not match.");
|
||||
}
|
||||
hipFree(d_a);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void runTestShflDown() {
|
||||
const int size = 32;
|
||||
T a[size];
|
||||
T cpuSum = 0;
|
||||
for (int i = 0; i < size; i++) {
|
||||
a[i] = i;
|
||||
cpuSum += a[i];
|
||||
}
|
||||
T* d_a;
|
||||
hipMalloc(&d_a, sizeof(T) * size);
|
||||
hipMemcpy(d_a, &a, sizeof(T) * size, hipMemcpyDefault);
|
||||
hipLaunchKernelGGL(shflDownSum<T>, 1, size, 0, 0, d_a, size);
|
||||
hipMemcpy(&a, d_a, sizeof(T) * size, hipMemcpyDefault);
|
||||
if (a[0] != cpuSum) {
|
||||
hipFree(d_a);
|
||||
failed("Shfl Up Sum did not match.");
|
||||
}
|
||||
hipFree(d_a);
|
||||
}
|
||||
int main() {
|
||||
runTestShflUp<int>();
|
||||
runTestShflUp<float>();
|
||||
runTestShflUp<long>();
|
||||
runTestShflUp<long long>();
|
||||
|
||||
runTestShflDown<int>();
|
||||
runTestShflDown<float>();
|
||||
runTestShflDown<long>();
|
||||
runTestShflDown<long long>();
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
Copyright (c) 2015 - present 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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
template <typename T>
|
||||
void runTest(int width,int height,int depth, hipChannelFormatKind formatKind)
|
||||
{
|
||||
unsigned int size = width * height * depth * sizeof(T);
|
||||
T* hData = (T*) malloc(size);
|
||||
memset(hData, 0, size);
|
||||
|
||||
for (int i = 0; i < depth; i++) {
|
||||
for (int j = 0; j < height; j++) {
|
||||
for (int k = 0; k < width; k++) {
|
||||
hData[i*width*height + j*width +k] = i*width*height + j*width + k;
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("test- sizeof(T) =%d\n", sizeof(T));
|
||||
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(T)*8, 0, 0, 0, formatKind);
|
||||
hipArray *arr,*arr1;
|
||||
|
||||
HIPCHECK(hipMalloc3DArray(&arr, &channelDesc, make_hipExtent(width, height, depth), hipArrayDefault));
|
||||
HIPCHECK(hipMalloc3DArray(&arr1, &channelDesc, make_hipExtent(width, height, depth), hipArrayDefault));
|
||||
hipMemcpy3DParms myparms = {0};
|
||||
myparms.srcPos = make_hipPos(0,0,0);
|
||||
myparms.dstPos = make_hipPos(0,0,0);
|
||||
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(T), width, height);
|
||||
myparms.dstArray = arr;
|
||||
myparms.extent = make_hipExtent(width , height, depth);
|
||||
#ifdef __HIP_PLATFORM_NVCC__
|
||||
myparms.kind = cudaMemcpyHostToDevice;
|
||||
#else
|
||||
myparms.kind = hipMemcpyHostToDevice;
|
||||
#endif
|
||||
HIPCHECK(hipMemcpy3D(&myparms));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
//Array to Array
|
||||
memset(&myparms,0x0, sizeof(hipMemcpy3DParms));
|
||||
myparms.srcPos = make_hipPos(0,0,0);
|
||||
myparms.dstPos = make_hipPos(0,0,0);
|
||||
myparms.srcArray = arr;
|
||||
myparms.dstArray = arr1;
|
||||
myparms.extent = make_hipExtent(width, height, depth);
|
||||
#ifdef __HIP_PLATFORM_NVCC__
|
||||
myparms.kind = cudaMemcpyDeviceToDevice;
|
||||
#else
|
||||
myparms.kind = hipMemcpyDeviceToDevice;
|
||||
#endif
|
||||
HIPCHECK(hipMemcpy3D(&myparms));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
T *hOutputData = (T*) malloc(size);
|
||||
memset(hOutputData, 0, size);
|
||||
//Device to host
|
||||
memset(&myparms,0x0, sizeof(hipMemcpy3DParms));
|
||||
myparms.srcPos = make_hipPos(0,0,0);
|
||||
myparms.dstPos = make_hipPos(0,0,0);
|
||||
myparms.dstPtr = make_hipPitchedPtr(hOutputData, width * sizeof(T), width, height);
|
||||
myparms.srcArray = arr1;
|
||||
myparms.extent = make_hipExtent(width, height, depth);
|
||||
#ifdef __HIP_PLATFORM_NVCC__
|
||||
myparms.kind = cudaMemcpyDeviceToHost;
|
||||
#else
|
||||
myparms.kind = hipMemcpyDeviceToHost;
|
||||
#endif
|
||||
HIPCHECK(hipMemcpy3D(&myparms));
|
||||
HIPCHECK(hipDeviceSynchronize());
|
||||
|
||||
// Check result
|
||||
HipTest::checkArray(hData,hOutputData,width,height,depth);
|
||||
hipFreeArray(arr);
|
||||
hipFreeArray(arr1);
|
||||
free(hData);
|
||||
free(hOutputData);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
for(int i=1;i<25;i++)
|
||||
{
|
||||
runTest<float>(i,i,i, hipChannelFormatKindFloat);
|
||||
runTest<int>(i+1,i,i, hipChannelFormatKindSigned);
|
||||
runTest<char>(i,i+1,i, hipChannelFormatKindSigned);
|
||||
}
|
||||
passed();
|
||||
}
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
Copyright (c) 2015-Present 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 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.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../../test_common.cpp NVCC_OPTIONS -std=c++11
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
|
||||
#include "hip/hip_runtime.h"
|
||||
#include "hip/hip_runtime_api.h"
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define LEN 64
|
||||
#define SIZE LEN << 2
|
||||
#define THREADS 2
|
||||
#define MAX_THREADS 16
|
||||
|
||||
#define FILENAME "vcpy_kernel.code"
|
||||
#define kernel_name "hello_world"
|
||||
|
||||
std::vector<char> load_file()
|
||||
{
|
||||
std::ifstream file(FILENAME, std::ios::binary | std::ios::ate);
|
||||
std::streamsize fsize = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<char> buffer(fsize);
|
||||
if (!file.read(buffer.data(), fsize)) {
|
||||
failed("could not open code object '%s'\n", FILENAME);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
void run(const std::vector<char>& buffer) {
|
||||
hipDevice_t device;
|
||||
HIPCHECK(hipDeviceGet(&device, 0));
|
||||
hipCtx_t context;
|
||||
HIPCHECK(hipCtxCreate(&context, 0, device));
|
||||
|
||||
hipModule_t Module;
|
||||
hipFunction_t Function;
|
||||
HIPCHECK(hipModuleLoadData(&Module, &buffer[0]));
|
||||
HIPCHECK(hipModuleGetFunction(&Function, Module, kernel_name));
|
||||
|
||||
float *A, *B, *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;
|
||||
}
|
||||
|
||||
HIPCHECK(hipMalloc((void**)&Ad, SIZE));
|
||||
HIPCHECK(hipMalloc((void**)&Bd, SIZE));
|
||||
|
||||
HIPCHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
|
||||
HIPCHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
|
||||
|
||||
hipStream_t stream;
|
||||
HIPCHECK(hipStreamCreate(&stream));
|
||||
|
||||
struct {
|
||||
void* _Ad;
|
||||
void* _Bd;
|
||||
} args;
|
||||
args._Ad = (void*) Ad;
|
||||
args._Bd = (void*) Bd;
|
||||
size_t size = sizeof(args);
|
||||
|
||||
void* config[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args, HIP_LAUNCH_PARAM_BUFFER_SIZE, &size,
|
||||
HIP_LAUNCH_PARAM_END};
|
||||
HIPCHECK(hipModuleLaunchKernel(Function, 1, 1, 1, LEN, 1, 1, 0, stream, NULL, (void**)&config));
|
||||
|
||||
HIPCHECK(hipStreamDestroy(stream));
|
||||
|
||||
HIPCHECK(hipModuleUnload(Module));
|
||||
|
||||
HIPCHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
|
||||
|
||||
for (uint32_t i = 0; i < LEN; i++) {
|
||||
assert(A[i] == B[i]);
|
||||
}
|
||||
|
||||
hipFree(Ad);
|
||||
hipFree(Bd);
|
||||
delete A;
|
||||
delete B;
|
||||
hipCtxDestroy(context);
|
||||
|
||||
}
|
||||
|
||||
struct joinable_thread : std::thread
|
||||
{
|
||||
template <class... Xs>
|
||||
joinable_thread(Xs&&... xs) : std::thread(std::forward<Xs>(xs)...) // NOLINT
|
||||
{
|
||||
}
|
||||
|
||||
joinable_thread& operator=(joinable_thread&& other) = default;
|
||||
joinable_thread(joinable_thread&& other) = default;
|
||||
|
||||
~joinable_thread()
|
||||
{
|
||||
if(this->joinable())
|
||||
this->join();
|
||||
}
|
||||
};
|
||||
|
||||
void run_multi_threads(uint32_t n, const std::vector<char>& buffer) {
|
||||
|
||||
std::vector<joinable_thread> threads;
|
||||
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
threads.emplace_back(std::thread{[&, buffer] {
|
||||
run(buffer);
|
||||
}});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
||||
HIPCHECK(hipInit(0));
|
||||
auto buffer = load_file();
|
||||
run_multi_threads(min(THREADS * std::thread::hardware_concurrency(), MAX_THREADS), buffer);
|
||||
|
||||
passed();
|
||||
}
|
||||
@@ -37,10 +37,12 @@ int p_tests = -1; /*which tests to run. Interpretation is left to each test. de
|
||||
const char* HIP_VISIBLE_DEVICES_STR = "HIP_VISIBLE_DEVICES=";
|
||||
const char* CUDA_VISIBLE_DEVICES_STR = "CUDA_VISIBLE_DEVICES=";
|
||||
const char* PATH_SEPERATOR_STR = "\\";
|
||||
const char* NULL_DEVICE = "NUL:";
|
||||
#else
|
||||
const char* HIP_VISIBLE_DEVICES_STR = "HIP_VISIBLE_DEVICES";
|
||||
const char* CUDA_VISIBLE_DEVICES_STR = "CUDA_VISIBLE_DEVICES";
|
||||
const char* PATH_SEPERATOR_STR = "/";
|
||||
const char* NULL_DEVICE = "/dev/null";
|
||||
#endif
|
||||
|
||||
namespace HipTest {
|
||||
|
||||
@@ -105,6 +105,10 @@ THE SOFTWARE.
|
||||
#define pclose(x) _pclose(x)
|
||||
#define setenv(x,y,z) _putenv_s(x,y)
|
||||
#define unsetenv _putenv
|
||||
#define fileno(x) _fileno(x)
|
||||
#define dup(x) _dup(x)
|
||||
#define dup2(x,y) _dup2(x,y)
|
||||
#define close(x) _close(x)
|
||||
#else
|
||||
#define aligned_free(x) free(x)
|
||||
#endif
|
||||
@@ -124,6 +128,7 @@ extern int p_tests;
|
||||
extern const char* HIP_VISIBLE_DEVICES_STR;
|
||||
extern const char* CUDA_VISIBLE_DEVICES_STR;
|
||||
extern const char* PATH_SEPERATOR_STR;
|
||||
extern const char* NULL_DEVICE;
|
||||
|
||||
// ********************* CPP section *********************
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -21,7 +21,7 @@ THE SOFTWARE.
|
||||
*/
|
||||
|
||||
/* HIT_START
|
||||
* BUILD: %t %s ../test_common.cpp
|
||||
* BUILD: %t %s ../test_common.cpp EXCLUDE_HIP_PLATFORM vdi
|
||||
* TEST: %t
|
||||
* HIT_END
|
||||
*/
|
||||
@@ -66,7 +66,7 @@ void runTest(int width,int height,int num_layers,texture<T, hipTextureType2DLaye
|
||||
myparms.srcPtr = make_hipPitchedPtr(hData, width * sizeof(T), width, height);
|
||||
myparms.dstArray = arr;
|
||||
myparms.extent = make_hipExtent(width , height, num_layers);
|
||||
myparms.kind = hipMemcpyHostToDevice;
|
||||
//myparms.kind = hipMemcpyHostToDevice;
|
||||
HIPCHECK(hipMemcpy3D(&myparms));
|
||||
|
||||
// set texture parameters
|
||||
|
||||
@@ -84,10 +84,10 @@ void runTest(int width,int height,int depth,texture<T, hipTextureType3D, hipRead
|
||||
}
|
||||
|
||||
// Allocate array and copy image data
|
||||
hipChannelFormatDesc channelDesc = tex->channelDesc;
|
||||
hipChannelFormatDesc channelDesc = hipCreateChannelDesc(sizeof(T)*8, 0, 0, 0, hipChannelFormatKindSigned);
|
||||
hipArray *arr;
|
||||
|
||||
HIPCHECK(hipMalloc3DArray(&arr, &channelDesc, make_hipExtent(width, height, depth), hipArrayDefault));
|
||||
HIPCHECK(hipMalloc3DArray(&arr, &channelDesc, make_hipExtent(width, height, depth), hipArrayCubemap));
|
||||
hipMemcpy3DParms myparms = {0};
|
||||
myparms.srcPos = make_hipPos(0,0,0);
|
||||
myparms.dstPos = make_hipPos(0,0,0);
|
||||
@@ -100,7 +100,6 @@ void runTest(int width,int height,int depth,texture<T, hipTextureType3D, hipRead
|
||||
// set texture parameters
|
||||
tex->addressMode[0] = hipAddressModeWrap;
|
||||
tex->addressMode[1] = hipAddressModeWrap;
|
||||
tex->addressMode[2] = hipAddressModeWrap;
|
||||
tex->filterMode = hipFilterModePoint;
|
||||
tex->normalized = false;
|
||||
|
||||
|
||||
Referens i nytt ärende
Block a user