Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions src/amd_detail/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ using namespace hipFile;
bool
Configuration::fastpath() const noexcept
{
HIPFILE_STATIC bool fastpath_env{!Environment::force_compat_mode().value_or(false)};
HIPFILE_STATIC bool readExists{!!getHipAmdFileReadPtr()};
HIPFILE_STATIC bool writeExists{!!getHipAmdFileWritePtr()};
bool fastpath_env{!Environment::force_compat_mode().value_or(false)};
bool readExists{!!getHipAmdFileReadPtr()};
bool writeExists{!!getHipAmdFileWritePtr()};
return readExists && writeExists && m_fastpath_override.value_or(fastpath_env);
}

Expand All @@ -30,7 +30,7 @@ Configuration::fastpath(bool enabled) noexcept
bool
Configuration::fallback() const noexcept
{
HIPFILE_STATIC bool fallback_env{Environment::allow_compat_mode().value_or(true)};
bool fallback_env{Environment::allow_compat_mode().value_or(true)};
return m_fallback_override.value_or(fallback_env);
}

Expand All @@ -43,6 +43,6 @@ Configuration::fallback(bool enabled) noexcept
unsigned int
Configuration::statsLevel() const noexcept
{
HIPFILE_STATIC unsigned int stats_level_env{Environment::stats_level().value_or(0)};
unsigned int stats_level_env{Environment::stats_level().value_or(0)};
return stats_level_env;
}
12 changes: 3 additions & 9 deletions src/amd_detail/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@

#include "context.h"
#include "hip.h"
#include "hipfile-warnings.h"
#include "state.h"
#include "stats.h"
#include "sys.h"

namespace hipFile {

HipFileInit::HipFileInit()
void
hipFileInit()
{
Context<Hip>::get();
Context<Sys>::get();
Context<StatsServer>::get();
Context<IStatsServer>::get();
Context<DriverState>::get();
}

HIPFILE_WARN_NO_GLOBAL_CTOR_OFF
HIPFILE_WARN_NO_EXIT_DTOR_OFF
static HipFileInit *hipfile_init = Context<HipFileInit>::get();
HIPFILE_WARN_NO_EXIT_DTOR_ON
HIPFILE_WARN_NO_GLOBAL_CTOR_ON

}
25 changes: 17 additions & 8 deletions src/amd_detail/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#pragma once

#include "hipfile-warnings.h"
#include "stats.h"

#include <stdexcept>
#ifdef AIS_TESTING
#include <mutex>
Expand All @@ -15,7 +17,17 @@ namespace hipFile {

template <typename T> struct ContextOverride;

template <typename T> struct ContextDefaultImpl {
using type = T;
};

template <> struct ContextDefaultImpl<IStatsServer> {
using type = StatsServer;
};

template <typename T> struct Context {
using DefaultImpl = typename ContextDefaultImpl<T>::type;
static_assert(std::is_base_of_v<T, DefaultImpl>, "ContextDefaultImpl<T>::type must derive from T");
Context() = delete;
Context(const Context &) = delete;
Context(Context &&) = delete;
Expand All @@ -31,11 +43,11 @@ template <typename T> struct Context {
static T *get()
{
std::lock_guard<std::mutex> lock{m};
HIPFILE_WARN_NO_EXIT_DTOR_OFF
static T standard{};
HIPFILE_WARN_NO_EXIT_DTOR_ON
if (replacement)
return replacement;
HIPFILE_WARN_NO_EXIT_DTOR_OFF
static DefaultImpl standard{};
HIPFILE_WARN_NO_EXIT_DTOR_ON
return &standard;
}

Expand Down Expand Up @@ -67,7 +79,7 @@ template <typename T> struct Context {
static T *get()
{
HIPFILE_WARN_NO_EXIT_DTOR_OFF
static T context{};
static DefaultImpl context{};
HIPFILE_WARN_NO_EXIT_DTOR_ON
return &context;
}
Expand All @@ -92,9 +104,6 @@ template <typename T> struct ContextOverride {
};
#endif

class HipFileInit {
HipFileInit();
friend struct Context<HipFileInit>;
};
void hipFileInit();

}
4 changes: 2 additions & 2 deletions src/amd_detail/hip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ catch (...) {
hipAmdFileRead_t
getHipAmdFileReadPtr()
{
HIPFILE_STATIC hipAmdFileRead_t hipAmdFileReadPtr{
hipAmdFileRead_t hipAmdFileReadPtr{
reinterpret_cast<hipAmdFileRead_t>(hipGetProcAddressHelper("hipAmdFileRead"))};
return hipAmdFileReadPtr;
}

hipAmdFileWrite_t
getHipAmdFileWritePtr()
{
HIPFILE_STATIC hipAmdFileWrite_t hipAmdFileWritePtr{
hipAmdFileWrite_t hipAmdFileWritePtr{
reinterpret_cast<hipAmdFileWrite_t>(hipGetProcAddressHelper("hipAmdFileWrite"))};
return hipAmdFileWritePtr;
}
Expand Down
29 changes: 29 additions & 0 deletions src/amd_detail/hipfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ ensureDriverInit()
hipFileError_t
hipFileHandleRegister(hipFileHandle_t *fh, hipFileDescr_t *descr)
try {
hipFileInit();
if (fh == nullptr || descr == nullptr) {
return {hipFileInvalidValue, hipSuccess};
}
Expand All @@ -95,6 +96,7 @@ catch (...) {
void
hipFileHandleDeregister(hipFileHandle_t fh)
try {
hipFileInit();
if (fh == nullptr) {
return;
}
Expand All @@ -109,6 +111,7 @@ catch (...) {
hipFileError_t
hipFileBufRegister(const void *buffer_base, size_t length, int flags)
try {
hipFileInit();
Context<DriverState>::get()->registerBuffer(buffer_base, length, flags);
return {hipFileSuccess, hipSuccess};
}
Expand Down Expand Up @@ -137,6 +140,7 @@ catch (...) {
hipFileError_t
hipFileBufDeregister(const void *buffer_base)
try {
hipFileInit();
Context<DriverState>::get()->deregisterBuffer(buffer_base);
return {hipFileSuccess, hipSuccess};
}
Expand Down Expand Up @@ -221,6 +225,7 @@ catch (...) {
ssize_t
hipFileRead(hipFileHandle_t fh, void *buffer_base, size_t size, hoff_t file_offset, hoff_t buffer_offset)
{
hipFileInit();
auto result =
hipFileIo(IoType::Read, fh, buffer_base, size, file_offset, buffer_offset, getCachedBackends());

Expand All @@ -236,6 +241,7 @@ ssize_t
hipFileWrite(hipFileHandle_t fh, const void *buffer_base, size_t size, hoff_t file_offset,
hoff_t buffer_offset)
{
hipFileInit();
auto result =
hipFileIo(IoType::Write, fh, buffer_base, size, file_offset, buffer_offset, getCachedBackends());

Expand All @@ -250,6 +256,7 @@ hipFileWrite(hipFileHandle_t fh, const void *buffer_base, size_t size, hoff_t fi
hipFileError_t
hipFileDriverOpen()
try {
hipFileInit();
Context<DriverState>::get()->incrRefCount();

return {hipFileSuccess, hipSuccess};
Expand All @@ -261,6 +268,7 @@ catch (...) {
hipFileError_t
hipFileDriverClose()
try {
hipFileInit();
if (Context<DriverState>::get()->getRefCount() > 0) {
Context<DriverState>::get()->decrRefCount();
return {hipFileSuccess, hipSuccess};
Expand All @@ -276,6 +284,7 @@ catch (...) {
int64_t
hipFileUseCount()
try {
hipFileInit();
return Context<DriverState>::get()->getRefCount();
}
catch (...) {
Expand All @@ -285,6 +294,7 @@ catch (...) {
hipFileError_t
hipFileDriverGetProperties(hipFileDriverProps_t *props)
try {
hipFileInit();
(void)props;

throw std::runtime_error("Not Implemented");
Expand All @@ -296,6 +306,7 @@ catch (...) {
hipFileError_t
hipFileDriverSetPollMode(bool poll, size_t poll_threshold_size)
try {
hipFileInit();
(void)poll;
(void)poll_threshold_size;

Expand All @@ -308,6 +319,7 @@ catch (...) {
hipFileError_t
hipFileDriverSetMaxDirectIOSize(size_t max_direct_io_size)
try {
hipFileInit();
(void)max_direct_io_size;

throw std::runtime_error("Not Implemented");
Expand All @@ -319,6 +331,7 @@ catch (...) {
hipFileError_t
hipFileDriverSetMaxCacheSize(size_t max_cache_size)
try {
hipFileInit();
(void)max_cache_size;

throw std::runtime_error("Not Implemented");
Expand All @@ -330,6 +343,7 @@ catch (...) {
hipFileError_t
hipFileDriverSetMaxPinnedMemSize(size_t max_pinned_size)
try {
hipFileInit();
(void)max_pinned_size;

throw std::runtime_error("Not Implemented");
Expand All @@ -341,6 +355,7 @@ catch (...) {
hipFileError_t
hipFileBatchIOSetUp(hipFileBatchHandle_t *batch_idp, unsigned max_nr)
try {
hipFileInit();
if (batch_idp == nullptr) {
return {hipFileInvalidValue, hipSuccess};
}
Expand All @@ -359,6 +374,7 @@ catch (...) {
hipFileError_t
hipFileBatchIOSubmit(hipFileBatchHandle_t batch_idp, unsigned nr, hipFileIOParams_t *iocbp, unsigned flags)
try {
hipFileInit();
(void)flags; // Unused at this time.

std::shared_ptr<IBatchContext> batch_context = Context<DriverState>::get()->getBatchContext(batch_idp);
Expand All @@ -377,6 +393,7 @@ hipFileError_t
hipFileBatchIOGetStatus(hipFileBatchHandle_t batch_idp, unsigned min_nr, unsigned *nr,
hipFileIOEvents_t *iocbp, struct timespec *timeout)
try {
hipFileInit();
(void)batch_idp;
(void)min_nr;
(void)nr;
Expand All @@ -392,6 +409,7 @@ catch (...) {
hipFileError_t
hipFileBatchIOCancel(hipFileBatchHandle_t batch_idp)
try {
hipFileInit();
(void)batch_idp;

throw std::runtime_error("Not Implemented");
Expand All @@ -403,6 +421,7 @@ catch (...) {
void
hipFileBatchIODestroy(hipFileBatchHandle_t batch_idp)
try {
hipFileInit();
(void)batch_idp;

throw std::runtime_error("Not Implemented");
Expand Down Expand Up @@ -449,6 +468,7 @@ hipFileError_t
hipFileReadAsync(hipFileHandle_t fh, void *buffer_base, size_t *size_p, hoff_t *file_offset_p,
hoff_t *buffer_offset_p, ssize_t *bytes_read_p, hipStream_t stream)
{
hipFileInit();
return hipFileIOAsync(IoType::Read, fh, buffer_base, size_p, file_offset_p, buffer_offset_p, bytes_read_p,
stream);
}
Expand All @@ -457,13 +477,15 @@ hipFileError_t
hipFileWriteAsync(hipFileHandle_t fh, void *buffer_base, size_t *size_p, hoff_t *file_offset_p,
hoff_t *buffer_offset_p, ssize_t *bytes_written_p, hipStream_t stream)
{
hipFileInit();
return hipFileIOAsync(IoType::Write, fh, buffer_base, size_p, file_offset_p, buffer_offset_p,
bytes_written_p, stream);
}

hipFileError_t
hipFileStreamRegister(hipStream_t stream, unsigned flags)
try {
hipFileInit();
Context<DriverState>::get()->registerStream(stream, flags);
return {hipFileSuccess, hipSuccess};
}
Expand All @@ -477,6 +499,7 @@ catch (...) {
hipFileError_t
hipFileStreamDeregister(hipStream_t stream)
try {
hipFileInit();
Context<DriverState>::get()->deregisterStream(stream);
return {hipFileSuccess, hipSuccess};
}
Expand All @@ -494,6 +517,7 @@ catch (...) {
hipFileError_t
hipFileGetParameterSizeT(hipFileSizeTConfigParameter_t param, size_t *value)
try {
hipFileInit();
(void)param;
(void)value;

Expand All @@ -506,6 +530,7 @@ catch (...) {
hipFileError_t
hipFileGetParameterBool(hipFileBoolConfigParameter_t param, bool *value)
try {
hipFileInit();
(void)param;
(void)value;

Expand All @@ -518,6 +543,7 @@ catch (...) {
hipFileError_t
hipFileGetParameterString(hipFileStringConfigParameter_t param, char *desc_str, int len)
try {
hipFileInit();
(void)param;
(void)desc_str;
(void)len;
Expand All @@ -531,6 +557,7 @@ catch (...) {
hipFileError_t
hipFileSetParameterSizeT(hipFileSizeTConfigParameter_t param, size_t value)
try {
hipFileInit();
(void)param;
(void)value;

Expand All @@ -543,6 +570,7 @@ catch (...) {
hipFileError_t
hipFileSetParameterBool(hipFileBoolConfigParameter_t param, bool value)
try {
hipFileInit();
(void)param;
(void)value;

Expand All @@ -555,6 +583,7 @@ catch (...) {
hipFileError_t
hipFileSetParameterString(hipFileStringConfigParameter_t param, const char *desc_str)
try {
hipFileInit();
(void)param;
(void)desc_str;

Expand Down
Loading
Loading