-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
testBaseCUDA.h
80 lines (66 loc) · 2.47 KB
/
testBaseCUDA.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* Base class for tests.
*
* Author: Marcel Rieger
*/
#ifndef PHYSICSTOOLS_TENSORFLOW_TEST_TESTBASECUDA_H
#define PHYSICSTOOLS_TENSORFLOW_TEST_TESTBASECUDA_H
#include <boost/filesystem.hpp>
#include <filesystem>
#include <cppunit/extensions/HelperMacros.h>
#include <stdexcept>
#include "catch.hpp"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
#include "FWCore/ParameterSetReader/interface/ParameterSetReader.h"
#include "FWCore/PluginManager/interface/PluginManager.h"
#include "FWCore/PluginManager/interface/standard.h"
#include "FWCore/ServiceRegistry/interface/Service.h"
#include "FWCore/ServiceRegistry/interface/ServiceRegistry.h"
#include "FWCore/ServiceRegistry/interface/ServiceToken.h"
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/Utilities/interface/ResourceInformation.h"
#include "HeterogeneousCore/CUDAServices/interface/CUDAInterface.h"
#include "HeterogeneousCore/CUDAUtilities/interface/requireDevices.h"
class testBaseCUDA : public CppUnit::TestFixture {
public:
std::string dataPath_;
void setUp();
void tearDown();
std::string cmsswPath(std::string path);
virtual void test() = 0;
virtual std::string pyScript() const = 0;
};
void testBaseCUDA::setUp() {
dataPath_ =
cmsswPath("/test/" + std::string(std::getenv("SCRAM_ARCH")) + "/" + boost::filesystem::unique_path().string());
// create the graph
std::string testPath = cmsswPath("/src/PhysicsTools/TensorFlow/test");
std::string cmd = "python3 -W ignore " + testPath + "/" + pyScript() + " " + dataPath_;
std::array<char, 128> buffer;
std::string result;
std::shared_ptr<FILE> pipe(popen(cmd.c_str(), "r"), pclose);
if (!pipe) {
throw std::runtime_error("popen() failed!");
}
while (!feof(pipe.get())) {
if (fgets(buffer.data(), 128, pipe.get()) != NULL) {
result += buffer.data();
}
}
std::cout << std::endl << result << std::endl;
}
void testBaseCUDA::tearDown() {
if (std::filesystem::exists(dataPath_)) {
std::filesystem::remove_all(dataPath_);
}
}
std::string testBaseCUDA::cmsswPath(std::string path) {
if (path.size() > 0 && path.substr(0, 1) != "/") {
path = "/" + path;
}
std::string base = std::string(std::getenv("CMSSW_BASE"));
std::string releaseBase = std::string(std::getenv("CMSSW_RELEASE_BASE"));
return (std::filesystem::exists(base.c_str()) ? base : releaseBase) + path;
}
#endif // PHYSICSTOOLS_TENSORFLOW_TEST_TESTBASECUDA_H