Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make codebase portable #167

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/yacx/Exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ inline void __checkNvrtcResultError_LOG(const nvrtcResult error,
std::string exception =
nvrtcGetErrorString(error); // method to get the error name from NVIDIA
exception = exception + "\n->occoured in file <" + file + " in line " +
std::to_string(line) + "\n m_log: " + m_log + "\n\n";
std::to_string(line) + "\n log: " + m_log + "\n\n";
throw nvrtcResultException(error, exception);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Exception.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// Copyright 2019 André Hodapp
#include "yacx/Exception.hpp"
#if _MSC_VER
#define popen _popen
Expand Down
12 changes: 11 additions & 1 deletion test/test_device.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#if _MSC_VER
#define popen _popen
#define pclose _pclose
#endif

#include "yacx/Devices.hpp"
#include "yacx/Exception.hpp"

Expand Down Expand Up @@ -27,9 +32,14 @@ std::string exec(const char *cmd) {

TEST_CASE("Device can be constructed", "[yacx::device]") {
try {
#if defined(_MSC_VER)
std::string name = exec("powershell -command \"wmic path win32_VideoController get name | "
"Select-String -Pattern 'NVIDIA ([a-zA-Z0-9\-]+)' "
"-AllMatches | % { $_.matches.groups[1].value }\"");
#else
Comment on lines +35 to +39
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not exactly the same regex pattern, but I really don't remember why I used a lookahead stuff or w/e there. idk seems to work like this.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think powershell regex supports lookahead/behind

std::string name =
exec("lspci | grep -Poi \"nvidia.+\\[\\K[a-zA-Z0-9 ]+(?=\\])\"");

#endif
name.erase(std::remove(name.begin(), name.end(), '\n'), name.end());

SECTION("first device") {
Expand Down
10 changes: 3 additions & 7 deletions test/test_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,13 @@ TEST_CASE(
args.emplace_back(KernelArg(&datasize));

Headers headers;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I could have just removed the Headers headers as well, but seems fine to me like this.

headers.insert(Header{"cuda_runtime.h"});

// A2. Preparing the output for kernel-compilation
int *hostCompareOutput = new int[10]{7, 9, 11, 13, 15, 17, 19, 21, 23, 25};

// B1. A Kernel must be created in a controlled manner.
SECTION("1. A Kernel must be created in a controlled manner.") {
Source source{"#include \"cuda_runtime.h\"\n"
"extern \"C\"\n"
Source source{"extern \"C\"\n"
"__global__ void cuda_add(int *x, int *y, int *out, int "
"datasize) {\n"
" int i = threadIdx.x;\n"
Expand All @@ -67,8 +65,7 @@ TEST_CASE(
// dimensions.
SECTION("2B. The created kernel is launched using proper block and grid "
"dimensions.") {
Source source{"#include \"cuda_runtime.h\"\n"
"extern \"C\"\n"
Source source{"extern \"C\"\n"
"__global__ void cuda_add(int *x, int *y, int *out, int "
"datasize) {\n"
" int i = threadIdx.x;\n"
Expand Down Expand Up @@ -127,8 +124,7 @@ TEST_CASE(
SECTION("2C. The created kernel is launched using different block and grid "
"dimensions.") {
// B2C1. Declaration of all necessary kernel function inputs.
Source source{"#include \"cuda_runtime.h\"\n"
"extern \"C\"\n"
Source source{"extern \"C\"\n"
"__global__ void cuda_add(int *x, int *y, int *out, int "
"datasize) {\n"
" int i = threadIdx.x;\n"
Expand Down
4 changes: 1 addition & 3 deletions test/test_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ SCENARIO("Various programs are created and compiled under the following "
error_String.erase(0, 2);

Headers headers;
headers.insert(Header{"cuda_runtime.h"});

// A2. Using the same source program for all conditions of source program
// compilation using various options
Source source1{"#include \"cuda_runtime.h\"\n"
"extern \"C\"\n"
Source source1{"extern \"C\"\n"
"__global__ void cuda_add(int *x, int *y, int *out, int "
"datasize) {\n"
" int i = threadIdx.x;\n"
Expand Down
10 changes: 1 addition & 9 deletions test/test_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,13 @@ SCENARIO("Various sources of kernels are created and through them are created"
args.emplace_back(KernelArg(&datasize));

Headers headers_default;
headers_default.insert(Header{"cuda_runtime.h"});

// A2. Preparing the output for kernel-compilation
int *hostCompareOutput_Controlled = new int[5]{7, 9, 11, 13, 15};
int *hostCompareOutput_1 = new int[5]{12, 14, 16, 18, 20};
int *hostCompareOutput_2 = new int[5]{6, 14, 24, 36, 50};

Source source{"#include \"cuda_runtime.h\"\n"
"extern \"C\"\n"
Source source{"extern \"C\"\n"
"__global__ void cuda_add(int *x, int *y, int *out, int "
"datasize) {\n"
" int i = threadIdx.x;\n"
Expand All @@ -64,14 +62,12 @@ SCENARIO("Various sources of kernels are created and through them are created"
// simulated.
WHEN("More than one headers are used.") {
Headers headersNew1;
headersNew1.insert(Header{"cuda_runtime.h"});
headersNew1.insert(Header{"test_compare.hpp"});

/*B2. Compilation of Kernels through the creation of a
program from kernel - source*/
THEN("The results are consistent with the given controlled output.") {
Source sourceNew1{
"#include \"cuda_runtime.h\"\n"
"#include \"test_compare.hpp\"\n"
"extern \"C\"\n"
"__global__ void cuda_add_with_header(int *x, int *y, int *out, int"
Expand Down Expand Up @@ -103,7 +99,6 @@ SCENARIO("Various sources of kernels are created and through them are created"
*/
WHEN("More one functions in a kernel-code are used.") {
Headers headersNew2;
headersNew2.insert(Header{"cuda_runtime.h"});

// C2. Compilation of Kernels through the creation of a program from
// kernel - source
Expand All @@ -120,7 +115,6 @@ SCENARIO("Various sources of kernels are created and through them are created"
args.emplace_back(KernelArg(&datasize));

Source sourceNew2{
"#include \"cuda_runtime.h\"\n"
"extern \"C\"\n"
"__global__ void cuda_add_normal(int *x, int *y, int *out, int "
"datasize) {\n"
Expand Down Expand Up @@ -184,7 +178,6 @@ SCENARIO("Various sources of kernels are created and through them are created"
args.emplace_back(KernelArg(&datasize));

Headers headersNew3;
headersNew3.insert(Header{"cuda_runtime.h"});

/*D3. Compilation of Kernels through the creation of a
program from kernel - source*/
Expand All @@ -193,7 +186,6 @@ SCENARIO("Various sources of kernels are created and through them are created"
const CUresult error{CUDA_ERROR_NOT_FOUND};

Source sourceNew3{
"#include \"cuda_runtime.h\"\n"
"extern \"C\"\n"
"__global__ void cuda_multiply(int *x, int *y, int *out, int"
" datasize) {\n"
Expand Down
9 changes: 9 additions & 0 deletions test/test_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ TEST_CASE("Displays the type of a variable", "[yacx::type_of]") {
unsigned long long llui;
yacx::Options options;

#if defined(__clang__)
#elif defined(__GNUC__) || defined(__GNUG__)
REQUIRE(type_of(vec) == "std::vector<int, std::allocator<int> >");
REQUIRE(type_of(options) == "yacx::Options");
REQUIRE(type_of(llui) == "unsigned long long");
#elif defined(_MSC_VER)
REQUIRE(type_of(vec) == "class std::vector<int,class std::allocator<int> >");
REQUIRE(type_of(options) == "class yacx::Options");
REQUIRE(type_of(llui) == "unsigned __int64");
#endif


}

TEST_CASE("load file to std::string", "[yacx::load]") {
Expand Down