Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <cstdint>
#include <cstdio>
#include <fstream>
#include <filesystem>
#include <string>

#include <hip/hip_runtime_api.h>
Expand All @@ -17,13 +18,14 @@
namespace {
constexpr size_t kByteCount = 64;

// Builds a unique temporary file path for the exported dot graph so concurrent
// test binaries do not collide on a shared filename.
// Use the temp directory because installed test directories may be read-only.
std::string UniqueDotPath() {
int device = 0;
HIP_CHECK(hipGetDevice(&device));
return std::string("hip_contract_graph_debug_") + std::to_string(device) + "_" +
std::to_string(static_cast<long long>(reinterpret_cast<intptr_t>(&device))) + ".dot";
return (std::filesystem::temp_directory_path() /
(std::string("hip_contract_graph_debug_") + std::to_string(device) + "_" +
std::to_string(static_cast<long long>(reinterpret_cast<intptr_t>(&device))) + ".dot"))
Comment thread
iassiour marked this conversation as resolved.
Resolved
.string();
}

hipMemsetParams MakeByteMemsetParams(void* device_ptr, unsigned int value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#include <hip/hiprtc.h>
#include <hip_test_common.hh>

#include <cstdint>
#include <cstdio>
#include <fstream>
#include <filesystem>
#include <string>
#include <vector>

Expand Down Expand Up @@ -68,15 +70,20 @@ bool CompileLibrarySource(std::vector<char>& code) {
return true;
}

// Compiles the library source and writes it to a unique per-test file in the
// current working directory, returning the path. Skips when HIPRTC is
// unavailable. The caller must remove the file when done.
// Compile to a temp file: installed test directories may be read-only.
// Returns the path; the caller must remove the file.
std::string WriteCodeObjectFile(const char* suffix) {
std::vector<char> code;
if (!CompileLibrarySource(code)) {
HIP_SKIP_TEST("HIPRTC compilation is not supported by this device/runtime path.");
}
const std::string path = std::string("hip-contract-library-file-") + suffix + ".code";
// Add an address token to reduce collisions in the shared temp directory.
const std::string token =
std::to_string(static_cast<long long>(reinterpret_cast<intptr_t>(&code)));
Comment thread
iassiour marked this conversation as resolved.
Resolved
const std::string path =
(std::filesystem::temp_directory_path() /
(std::string("hip-contract-library-file-") + suffix + "-" + token + ".code"))
.string();
std::ofstream out(path, std::ios::binary);
REQUIRE(out.is_open());
out.write(code.data(), static_cast<std::streamsize>(code.size()));
Expand Down
Loading