Skip to content

Commit

Permalink
Fix Windows build and check for test data (#167)
Browse files Browse the repository at this point in the history
* Fix Windows build (#162)

* Check for test data relative to running executable (#165)

* Check for test data relative to running executable

* Format check
  • Loading branch information
tfalders authored Jun 13, 2023
1 parent e667d28 commit 9909362
Show file tree
Hide file tree
Showing 10 changed files with 275 additions and 102 deletions.
1 change: 1 addition & 0 deletions clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ if( BUILD_CLIENTS_TESTS OR BUILD_CLIENTS_BENCHMARKS )
$<$<PLATFORM_ID:Linux>:stdc++fs>
)
set(common_source_files
common/clients_utility.cpp
common/hipsolver_datatype2string.cpp
common/lapack_host_reference.cpp
common/utility.cpp
Expand Down
127 changes: 127 additions & 0 deletions clients/common/clients_utility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/* ************************************************************************
* Copyright (C) 2023 Advanced Micro Devices, Inc.
* ************************************************************************ */

#include <cstdlib>
#include <cstring>
#include <string>

#include "hipsolver.h"

#include "../rocblascommon/clients_utility.hpp"

#ifdef _WIN32

#define WIN32_LEAN_AND_MEAN
#include <windows.h>

#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#else
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#endif

#else
#include <fcntl.h>
#endif

// Return the path to the currently running executable
std::string hipsolver_exepath()
{
#ifdef _WIN32

std::vector<TCHAR> result(MAX_PATH + 1);
DWORD length = 0;
for(;;)
{
length = GetModuleFileNameA(nullptr, result.data(), result.size());
if(length < result.size() - 1)
{
result.resize(length + 1);
break;
}
result.resize(result.size() * 2);
}

fs::path exepath(result.begin(), result.end());
exepath = exepath.remove_filename();
exepath += exepath.empty() ? "" : "/";
return exepath.string();

#else
std::string pathstr;
char* path = realpath("/proc/self/exe", 0);
if(path)
{
char* p = strrchr(path, '/');
if(p)
{
p[1] = 0;
pathstr = path;
}
free(path);
}
return pathstr;
#endif
}

/* ============================================================================================ */
/* device query and print out their ID and name; return number of compute-capable devices. */
int query_device_property()
{
int device_count;
hipsolverStatus_t count_status = (hipsolverStatus_t)hipGetDeviceCount(&device_count);
if(count_status != HIPSOLVER_STATUS_SUCCESS)
{
printf("Query device error: cannot get device count \n");
return -1;
}
else
{
printf("Query device success: there are %d devices \n", device_count);
}

for(int i = 0; i < device_count; i++)
{
hipDeviceProp_t props;
hipsolverStatus_t props_status = (hipsolverStatus_t)hipGetDeviceProperties(&props, i);
if(props_status != HIPSOLVER_STATUS_SUCCESS)
{
printf("Query device error: cannot get device ID %d's property\n", i);
}
else
{
printf("Device ID %d : %s ------------------------------------------------------\n",
i,
props.name);
printf("with %3.1f GB memory, clock rate %dMHz @ computing capability %d.%d \n",
props.totalGlobalMem / 1e9,
(int)(props.clockRate / 1000),
props.major,
props.minor);
printf(
"maxGridDimX %d, sharedMemPerBlock %3.1f KB, maxThreadsPerBlock %d, warpSize %d\n",
props.maxGridSize[0],
props.sharedMemPerBlock / 1e3,
props.maxThreadsPerBlock,
props.warpSize);

printf("-------------------------------------------------------------------------\n");
}
}

return device_count;
}

/* set current device to device_id */
void set_device(int device_id)
{
hipsolverStatus_t status = (hipsolverStatus_t)hipSetDevice(device_id);
if(status != HIPSOLVER_STATUS_SUCCESS)
{
printf("Set device error: cannot set device ID %d, there may not be such device ID\n",
(int)device_id);
}
}
61 changes: 1 addition & 60 deletions clients/common/utility.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ************************************************************************
* Copyright (C) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (C) 2020-2023 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
Expand Down Expand Up @@ -109,65 +109,6 @@ double get_time_us_sync(hipStream_t stream)
return get_time_us_no_sync();
}

/* ============================================================================================ */
/* device query and print out their ID and name; return number of compute-capable devices. */
int query_device_property()
{
int device_count;
hipsolverStatus_t count_status = (hipsolverStatus_t)hipGetDeviceCount(&device_count);
if(count_status != HIPSOLVER_STATUS_SUCCESS)
{
printf("Query device error: cannot get device count \n");
return -1;
}
else
{
printf("Query device success: there are %d devices \n", device_count);
}

for(int i = 0; i < device_count; i++)
{
hipDeviceProp_t props;
hipsolverStatus_t props_status = (hipsolverStatus_t)hipGetDeviceProperties(&props, i);
if(props_status != HIPSOLVER_STATUS_SUCCESS)
{
printf("Query device error: cannot get device ID %d's property\n", i);
}
else
{
printf("Device ID %d : %s ------------------------------------------------------\n",
i,
props.name);
printf("with %3.1f GB memory, clock rate %dMHz @ computing capability %d.%d \n",
props.totalGlobalMem / 1e9,
(int)(props.clockRate / 1000),
props.major,
props.minor);
printf(
"maxGridDimX %d, sharedMemPerBlock %3.1f KB, maxThreadsPerBlock %d, warpSize %d\n",
props.maxGridSize[0],
props.sharedMemPerBlock / 1e3,
props.maxThreadsPerBlock,
props.warpSize);

printf("-------------------------------------------------------------------------\n");
}
}

return device_count;
}

/* set current device to device_id */
void set_device(int device_id)
{
hipsolverStatus_t status = (hipsolverStatus_t)hipSetDevice(device_id);
if(status != HIPSOLVER_STATUS_SUCCESS)
{
printf("Set device error: cannot set device ID %d, there may not be such device ID\n",
(int)device_id);
}
}

#ifdef __cplusplus
}
#endif
4 changes: 2 additions & 2 deletions clients/gtest/hipsolver_gtest_main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ************************************************************************
* Copyright (C) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (C) 2020-2023 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
Expand Down Expand Up @@ -28,7 +28,7 @@
#include <gtest/gtest.h>
#include <hipsolver.h>

#include "utility.hpp"
#include "clientcommon.hpp"

#define STRINGIFY(s) STRINGIFY_HELPER(s)
#define STRINGIFY_HELPER(s) #s
Expand Down
3 changes: 2 additions & 1 deletion clients/include/clientcommon.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ************************************************************************
* Copyright (C) 2020-2022 Advanced Micro Devices, Inc. All rights reserved.
* Copyright (C) 2020-2023 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
Expand All @@ -23,6 +23,7 @@

#pragma once

#include "../rocblascommon/clients_utility.hpp"
#include "../rocblascommon/rocblas_vector.hpp"
#include "../rocsolvercommon/norm.hpp"
#include "../rocsolvercommon/rocsolver_arguments.hpp"
Expand Down
28 changes: 14 additions & 14 deletions clients/include/testing_csrrf_refactlu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,39 +126,39 @@ void csrrf_refactlu_initData(hipsolverRfHandle_t handle,

// read-in A
file = testcase / "ptrA";
read_matrix(file, 1, n + 1, hptrA.data(), 1);
read_matrix(file.string(), 1, n + 1, hptrA.data(), 1);
file = testcase / "indA";
read_matrix(file, 1, nnzA, hindA.data(), 1);
read_matrix(file.string(), 1, nnzA, hindA.data(), 1);
file = testcase / "valA";
read_matrix(file, 1, nnzA, hvalA.data(), 1);
read_matrix(file.string(), 1, nnzA, hvalA.data(), 1);

// read-in L
file = testcase / "ptrL";
read_matrix(file, 1, n + 1, hptrL.data(), 1);
read_matrix(file.string(), 1, n + 1, hptrL.data(), 1);
file = testcase / "indL";
read_matrix(file, 1, nnzL, hindL.data(), 1);
read_matrix(file.string(), 1, nnzL, hindL.data(), 1);
file = testcase / "valL";
read_matrix(file, 1, nnzL, hvalL.data(), 1);
read_matrix(file.string(), 1, nnzL, hvalL.data(), 1);

// read-in U
file = testcase / "ptrU";
read_matrix(file, 1, n + 1, hptrU.data(), 1);
read_matrix(file.string(), 1, n + 1, hptrU.data(), 1);
file = testcase / "indU";
read_matrix(file, 1, nnzU, hindU.data(), 1);
read_matrix(file.string(), 1, nnzU, hindU.data(), 1);
file = testcase / "valU";
read_matrix(file, 1, nnzU, hvalU.data(), 1);
read_matrix(file.string(), 1, nnzU, hvalU.data(), 1);

// read-in T
file = testcase / "valT";
read_matrix(file, 1, nnzT, hvalT.data(), 1);
read_matrix(file.string(), 1, nnzT, hvalT.data(), 1);

// read-in P
file = testcase / "P";
read_matrix(file, 1, n, hpivP.data(), 1);
read_matrix(file.string(), 1, n, hpivP.data(), 1);

// read-in Q
file = testcase / "Q";
read_matrix(file, 1, n, hpivQ.data(), 1);
read_matrix(file.string(), 1, n, hpivQ.data(), 1);
}

if(GPU)
Expand Down Expand Up @@ -426,10 +426,10 @@ void testing_csrrf_refactlu(Arguments& argus)
testcase = get_sparse_data_dir() / folder;

file = testcase / "ptrL";
read_last(file, &nnzL);
read_last(file.string(), &nnzL);

file = testcase / "ptrU";
read_last(file, &nnzU);
read_last(file.string(), &nnzU);
}

// determine sizes
Expand Down
30 changes: 15 additions & 15 deletions clients/include/testing_csrrf_solve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,48 +114,48 @@ void csrrf_solve_initData(hipsolverRfHandle_t handle,

// read-in A
file = testcase / "ptrA";
read_matrix(file, 1, n + 1, hptrA.data(), 1);
read_matrix(file.string(), 1, n + 1, hptrA.data(), 1);
file = testcase / "indA";
read_matrix(file, 1, nnzA, hindA.data(), 1);
read_matrix(file.string(), 1, nnzA, hindA.data(), 1);
file = testcase / "valA";
read_matrix(file, 1, nnzA, hvalA.data(), 1);
read_matrix(file.string(), 1, nnzA, hvalA.data(), 1);

// read-in L
file = testcase / "ptrL";
read_matrix(file, 1, n + 1, hptrL.data(), 1);
read_matrix(file.string(), 1, n + 1, hptrL.data(), 1);
file = testcase / "indL";
read_matrix(file, 1, nnzL, hindL.data(), 1);
read_matrix(file.string(), 1, nnzL, hindL.data(), 1);
file = testcase / "valL";
read_matrix(file, 1, nnzL, hvalL.data(), 1);
read_matrix(file.string(), 1, nnzL, hvalL.data(), 1);

// read-in U
file = testcase / "ptrU";
read_matrix(file, 1, n + 1, hptrU.data(), 1);
read_matrix(file.string(), 1, n + 1, hptrU.data(), 1);
file = testcase / "indU";
read_matrix(file, 1, nnzU, hindU.data(), 1);
read_matrix(file.string(), 1, nnzU, hindU.data(), 1);
file = testcase / "valU";
read_matrix(file, 1, nnzU, hvalU.data(), 1);
read_matrix(file.string(), 1, nnzU, hvalU.data(), 1);

// read-in P
file = testcase / "P";
read_matrix(file, 1, n, hpivP.data(), 1);
read_matrix(file.string(), 1, n, hpivP.data(), 1);

// read-in Q
file = testcase / "Q";
read_matrix(file, 1, n, hpivQ.data(), 1);
read_matrix(file.string(), 1, n, hpivQ.data(), 1);

// read-in B
filename = std::string("B_") + std::to_string(nrhs);
file = testcase / filename;
read_matrix(file, n, nrhs, hB.data(), ldb);
read_matrix(file.string(), n, nrhs, hB.data(), ldb);

// get results (matrix X) if validation is required
if(test)
{
// read-in X
filename = std::string("X_") + std::to_string(nrhs);
file = testcase / filename;
read_matrix(file, n, nrhs, hX.data(), ldb);
read_matrix(file.string(), n, nrhs, hX.data(), ldb);
}
}

Expand Down Expand Up @@ -400,10 +400,10 @@ void testing_csrrf_solve(Arguments& argus)
testcase = get_sparse_data_dir() / folder;

file = testcase / "ptrL";
read_last(file, &nnzL);
read_last(file.string(), &nnzL);

file = testcase / "ptrU";
read_last(file, &nnzU);
read_last(file.string(), &nnzU);
}

// determine existing right-hand-side
Expand Down
7 changes: 0 additions & 7 deletions clients/include/utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,6 @@ inline void
extern "C" {
#endif

/* ============================================================================================ */
/* device query and print out their ID and name */
int query_device_property();

/* set current device to device_id */
void set_device(int device_id);

/* ============================================================================================ */
/* timing: HIP only provides very limited timers function clock() and not general;
hipsolver sync CPU and device and use more accurate CPU timer*/
Expand Down
Loading

0 comments on commit 9909362

Please sign in to comment.