From: Alok Hota Date: Thu, 20 Sep 2018 03:23:15 +0000 (-0500) Subject: swr/rast: Store cached files in multiple subdirs X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=187a6506a3e39ab613a9085fe01b23fb42f9aa6b;p=mesa.git swr/rast: Store cached files in multiple subdirs This improves cache filesystem performance, especially during CI tests Also updated jitcache magic number due to codegen parameter changes Removed 2 `if constexpr` to prevent C++17 requirement --- diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp index 1b2b570318c..a549721f147 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.cpp @@ -582,7 +582,7 @@ struct JitCacheFileHeader uint64_t GetObjectCRC() const { return m_objCRC; } private: - static const uint64_t JC_MAGIC_NUMBER = 0xfedcba9876543211ULL + 4; + static const uint64_t JC_MAGIC_NUMBER = 0xfedcba9876543210ULL + 6; static const size_t JC_STR_MAX_LEN = 32; static const uint32_t JC_PLATFORM_KEY = (LLVM_VERSION_MAJOR << 24) | (LLVM_VERSION_MINOR << 16) | (LLVM_VERSION_PATCH << 8) | @@ -634,6 +634,15 @@ JitCache::JitCache() { mCacheDir = KNOB_JIT_CACHE_DIR; } + + // Create cache dir at startup to allow jitter to write debug.ll files + // to that directory. + if (!llvm::sys::fs::exists(mCacheDir.str()) && + llvm::sys::fs::create_directories(mCacheDir.str())) + { + SWR_INVALID("Unable to create directory: %s", mCacheDir.c_str()); + } + } int ExecUnhookedProcess(const std::string& CmdLine, std::string* pStdOut, std::string* pStdErr) @@ -641,6 +650,26 @@ int ExecUnhookedProcess(const std::string& CmdLine, std::string* pStdOut, std::s return ExecCmd(CmdLine, "", pStdOut, pStdErr); } +/// Calculate actual directory where module will be cached. +/// This is always a subdirectory of mCacheDir. Full absolute +/// path name will be stored in mCurrentModuleCacheDir +void JitCache::CalcModuleCacheDir() +{ + mModuleCacheDir.clear(); + + llvm::SmallString moduleDir = mCacheDir; + + // Create 4 levels of directory hierarchy based on CRC, 256 entries each + uint8_t* pCRC = (uint8_t*)&mCurrentModuleCRC; + for (uint32_t i = 0; i < 4; ++i) + { + llvm::sys::path::append(moduleDir, std::to_string((int)pCRC[i])); + } + + mModuleCacheDir = moduleDir; +} + + /// notifyObjectCompiled - Provides a pointer to compiled code for Module M. void JitCache::notifyObjectCompiled(const llvm::Module* M, llvm::MemoryBufferRef Obj) { @@ -650,16 +679,22 @@ void JitCache::notifyObjectCompiled(const llvm::Module* M, llvm::MemoryBufferRef return; } - if (!llvm::sys::fs::exists(mCacheDir.str()) && - llvm::sys::fs::create_directories(mCacheDir.str())) + if (!mModuleCacheDir.size()) { - SWR_INVALID("Unable to create directory: %s", mCacheDir.c_str()); + SWR_INVALID("Unset module cache directory"); + return; + } + + if (!llvm::sys::fs::exists(mModuleCacheDir.str()) && + llvm::sys::fs::create_directories(mModuleCacheDir.str())) + { + SWR_INVALID("Unable to create directory: %s", mModuleCacheDir.c_str()); return; } JitCacheFileHeader header; - llvm::SmallString filePath = mCacheDir; + llvm::SmallString filePath = mModuleCacheDir; llvm::sys::path::append(filePath, moduleID); llvm::SmallString objPath = filePath; @@ -699,12 +734,14 @@ std::unique_ptr JitCache::getObject(const llvm::Module* M) return nullptr; } - if (!llvm::sys::fs::exists(mCacheDir)) + CalcModuleCacheDir(); + + if (!llvm::sys::fs::exists(mModuleCacheDir)) { return nullptr; } - llvm::SmallString filePath = mCacheDir; + llvm::SmallString filePath = mModuleCacheDir; llvm::sys::path::append(filePath, moduleID); llvm::SmallString objFilePath = filePath; diff --git a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h index 5659191525d..bb7ca8b4a3e 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h +++ b/src/gallium/drivers/swr/rasterizer/jitter/JitManager.h @@ -113,9 +113,15 @@ public: private: std::string mCpu; llvm::SmallString mCacheDir; + llvm::SmallString mModuleCacheDir; uint32_t mCurrentModuleCRC = 0; JitManager* mpJitMgr = nullptr; llvm::CodeGenOpt::Level mOptLevel = llvm::CodeGenOpt::None; + + /// Calculate actual directory where module will be cached. + /// This is always a subdirectory of mCacheDir. Full absolute + /// path name will be stored in mCurrentModuleCacheDir + void CalcModuleCacheDir(); }; ////////////////////////////////////////////////////////////////////////// diff --git a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp index 65eec4e4c68..24b733a28ae 100644 --- a/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp +++ b/src/gallium/drivers/swr/rasterizer/jitter/builder_misc.cpp @@ -774,13 +774,6 @@ namespace SwrJit { SWR_ASSERT((numIntBits + numFracBits) <= 32, "Can only handle 32-bit fixed-point values"); Value* fixed = nullptr; - if constexpr (false) // This doesn't work for negative numbers!! - { - fixed = FP_TO_SI(VROUND(FMUL(vFloat, VIMMED1(float(1 << numFracBits))), - C(_MM_FROUND_TO_NEAREST_INT)), - mSimdInt32Ty); - } - else { // Do round to nearest int on fractional bits first // Not entirely perfect for negative numbers, but close enough @@ -844,35 +837,13 @@ namespace SwrJit { SWR_ASSERT((numIntBits + numFracBits) <= 32, "Can only handle 32-bit fixed-point values"); Value* fixed = nullptr; - if constexpr (true) // KNOB_SIM_FAST_MATH? Below works correctly from a precision - // standpoint... + // KNOB_SIM_FAST_MATH? Below works correctly from a precision + // standpoint... { fixed = FP_TO_UI(VROUND(FMUL(vFloat, VIMMED1(float(1 << numFracBits))), C(_MM_FROUND_TO_NEAREST_INT)), mSimdInt32Ty); } - else - { - // Do round to nearest int on fractional bits first - vFloat = VROUND(FMUL(vFloat, VIMMED1(float(1 << numFracBits))), - C(_MM_FROUND_TO_NEAREST_INT)); - vFloat = FMUL(vFloat, VIMMED1(1.0f / float(1 << numFracBits))); - - // TODO: Handle INF, NAN, overflow / underflow, etc. - - Value* vSgn = FCMP_OLT(vFloat, VIMMED1(0.0f)); - Value* vFloatInt = BITCAST(vFloat, mSimdInt32Ty); - Value* vFixed = AND(vFloatInt, VIMMED1((1 << 23) - 1)); - vFixed = OR(vFixed, VIMMED1(1 << 23)); - - Value* vExp = LSHR(SHL(vFloatInt, VIMMED1(1)), VIMMED1(24)); - vExp = SUB(vExp, VIMMED1(127)); - - Value* vExtraBits = SUB(VIMMED1(23 - numFracBits), vExp); - - fixed = LSHR(vFixed, vExtraBits, name); - } - return fixed; }