CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
102 lines
2.4 KiB
C++
102 lines
2.4 KiB
C++
/* Copyright (c) Advanced Micro Devices, Inc. All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "hipfile.h"
|
|
#include "magic-word.h"
|
|
|
|
#include <cerrno>
|
|
#include <cstdint>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
#include <random>
|
|
#include <stdexcept>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
|
|
constexpr hipFileError_t
|
|
HipFileOpError(hipFileOpError_t err)
|
|
{
|
|
return {err, hipSuccess};
|
|
}
|
|
|
|
constexpr hipFileError_t
|
|
HipFileDriverError(hipError_t err)
|
|
{
|
|
return {hipFileHipDriverError, err};
|
|
}
|
|
|
|
inline bool
|
|
operator==(const hipFileError_t &lhs, const hipFileError_t &rhs)
|
|
{
|
|
return lhs.err == rhs.err && lhs.hip_drv_err == rhs.hip_drv_err;
|
|
}
|
|
|
|
static std::ostream &
|
|
operator<<(std::ostream &os, const hipFileError_t &hfe)
|
|
{
|
|
return os << "hipFileError_t{ err: " << hfe.err << ", hip_drv_err: " << hfe.hip_drv_err << " }";
|
|
}
|
|
|
|
// Convenience "success" value
|
|
inline constexpr hipFileError_t HIPFILE_SUCCESS{hipFileSuccess, hipSuccess};
|
|
|
|
inline void
|
|
rfill(void *buffer, uint64_t len, uint32_t seed = 97)
|
|
{
|
|
std::mt19937 gen(seed);
|
|
std::uniform_int_distribution<uint16_t> dist(0, 255);
|
|
|
|
for (uint64_t i = 0; i < len; i++) {
|
|
static_cast<uint8_t *>(buffer)[i] = static_cast<uint8_t>(dist(gen));
|
|
}
|
|
}
|
|
|
|
struct Tmpfile {
|
|
int fd;
|
|
std::string path;
|
|
|
|
Tmpfile() : Tmpfile{"."}
|
|
{
|
|
}
|
|
|
|
/*!
|
|
* \warning The constructor is NOT thread-safe and can result in
|
|
* interleaved calls to `umask()`
|
|
*/
|
|
Tmpfile(std::string directory) : path{std::move(directory)}
|
|
{
|
|
// Security analyzers will be sad if you don't set umask 0077
|
|
// before creating temporary files
|
|
mode_t old_umask = umask(S_IRWXG | S_IRWXO);
|
|
|
|
path += "/hipFile.XXXXXX";
|
|
if ((fd = mkstemp(path.data())) == -1) {
|
|
int mkstemp_err{errno};
|
|
umask(old_umask);
|
|
throw std::runtime_error("Could not create temporary file " + path + ": " +
|
|
std::string(std::strerror(mkstemp_err)));
|
|
}
|
|
|
|
umask(old_umask);
|
|
|
|
#ifdef __HIP_PLATFORM_AMD__
|
|
if (unlink(path.c_str()) == -1) {
|
|
close(fd);
|
|
throw std::runtime_error("Could not unlink temporary file");
|
|
}
|
|
#endif
|
|
}
|
|
|
|
~Tmpfile()
|
|
{
|
|
#ifdef __HIP_PLATFORM_NVIDIA__
|
|
unlink(path.c_str());
|
|
#endif
|
|
close(fd);
|
|
}
|
|
};
|