Skip to content
Open
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
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2200,6 +2200,7 @@ add_library(vllm_shared SHARED "${_vllm_shared_stub}")
add_library(vllm::shared ALIAS vllm_shared)
set_target_properties(vllm_shared PROPERTIES
OUTPUT_NAME vllm
ARCHIVE_OUTPUT_NAME vllm_shared
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
CXX_VISIBILITY_PRESET hidden
Expand All @@ -2212,7 +2213,11 @@ target_include_directories(vllm_shared PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# Force-link the whole `vllm` archive (the C ABI + engine + the CPU-backend
# static registrar) and inherit its PUBLIC deps (CUDA::cudart, Threads, ...).
target_link_libraries(vllm_shared PRIVATE vllm)
# On Windows the packaged shared target also needs the vendored BLAKE3 archive
# explicitly on its own link line; relying on the static archive's usage
# requirements is not sufficient once the C ABI DLL is assembled via
# /WHOLEARCHIVE.
target_link_libraries(vllm_shared PRIVATE vllm blake3_vendored)
# Export only the C ABI: `vllm_*` stays global, everything else is localized.
# UNLIKE the force-link guard above, `UNIX AND NOT APPLE` is CORRECT here: a
# linker version script is a GNU-ld/ELF feature with no ld64 spelling (ld64 uses
Expand Down
5 changes: 4 additions & 1 deletion examples/laguna_gen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "vllm/model_executor/model_loader/gguf_reader.h"
#include "vllm/model_executor/model_loader/safetensors_reader.h"
#include "vllm/model_executor/models/laguna.h"
#include "vllm/support/platform_compat.h"
#include "vllm/tokenizer/tokenizer.h"
#include "vllm/transformers_utils/hf_config.h"
#include "vt/backend.h" // vt::GetBackend / CreateQueue (--gpu: GEMMs on the GB10)
Expand Down Expand Up @@ -201,7 +202,9 @@ int main(int argc, char** argv) {
// s/tok (2×; 2.56 → 5.0 tok/s), coherent + near-tie. `setenv(...,0)` respects an
// explicit `VT_NVFP4_FP4_NATIVE=0` override. Scoped to this Laguna driver (the
// 27B/35B use the separate DirectD cutlass path, untouched).
setenv("VT_NVFP4_FP4_NATIVE", "1", 0);
if (std::getenv("VT_NVFP4_FP4_NATIVE") == nullptr) {
(void)vllm::support::SetEnvVar("VT_NVFP4_FP4_NATIVE", "1");
}
const std::string config_path = (fs::path(model) / "config.json").string();
const std::string tok_path = (fs::path(model) / "tokenizer.json").string();
std::fprintf(stderr, "[gen] NVFP4 safetensors dir %s\n", model.c_str());
Expand Down
13 changes: 13 additions & 0 deletions examples/minimax_h3_gen/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@
// pipeline and are gone with it; the capabilities they probed are gated by
// test_minimax_h3 / test_minimax_h3_video_fold, and multi-image ref2va remains
// reachable through the C++ seam (a named residual of the ABI's first slice).
#if defined(_WIN32)
#include <process.h>
#else
#include <sys/wait.h>
#include <unistd.h>
#endif

#include <cstdint>
#include <cstdio>
Expand All @@ -55,6 +59,14 @@ int RunFfmpeg(const std::vector<std::string>& args) {
argv.reserve(args.size() + 1);
for (const std::string& a : args) argv.push_back(const_cast<char*>(a.c_str()));
argv.push_back(nullptr);
#if defined(_WIN32)
const intptr_t rc = _spawnvp(_P_WAIT, argv[0], argv.data());
if (rc == -1) {
std::fprintf(stderr, "error: _spawnvp failed\n");
return -1;
}
return static_cast<int>(rc);
#else
const pid_t pid = fork();
if (pid < 0) {
std::fprintf(stderr, "error: fork failed\n");
Expand All @@ -74,6 +86,7 @@ int RunFfmpeg(const std::vector<std::string>& args) {
return -1;
}
return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
#endif
}

const char* Need(int argc, char** argv, int i, const char* flag) {
Expand Down
13 changes: 13 additions & 0 deletions examples/minimax_h3_mux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
// --audio omitted => a silent clip
// --print-only print the argv and exit WITHOUT spawning (lets the argv be
// inspected, diffed or run by hand on a box with no ffmpeg).
#if defined(_WIN32)
#include <process.h>
#else
#include <sys/wait.h>
#include <unistd.h>
#endif

#include <cstdio>
#include <cstdlib>
Expand All @@ -46,6 +50,14 @@ int RunFfmpeg(const std::vector<std::string>& args) {
}
c_args.push_back(nullptr);

#if defined(_WIN32)
const intptr_t rc = _spawnvp(_P_WAIT, c_args[0], c_args.data());
if (rc == -1) {
std::fprintf(stderr, "error: _spawnvp failed\n");
return -1;
}
return static_cast<int>(rc);
#else
const pid_t pid = fork();
if (pid < 0) {
std::fprintf(stderr, "error: fork failed\n");
Expand All @@ -67,6 +79,7 @@ int RunFfmpeg(const std::vector<std::string>& args) {
return -1;
}
return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
#endif
}

const char* Need(int argc, char** argv, int i, const char* flag) {
Expand Down
21 changes: 19 additions & 2 deletions examples/video_studio/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,16 @@
#include <mutex>
#include <sstream>
#include <string>
#include <sys/wait.h>
#include <thread>
#include <unistd.h>
#include <vector>

#if defined(_WIN32)
#include <process.h>
#else
#include <sys/wait.h>
#include <unistd.h>
#endif

#include <httplib/httplib.h>
#include <nlohmann/json.hpp>

Expand Down Expand Up @@ -94,6 +99,17 @@ bool RunMux(char** argv, int argc, std::string* err) {
std::string ff = g_ffmpeg;
a[0] = ff.data();
a.push_back(nullptr);
#if defined(_WIN32)
const intptr_t rc = _spawnvp(_P_WAIT, a[0], a.data());
if (rc == -1) {
*err = "_spawnvp failed";
return false;
}
if (rc == 0) return true;
*err = "ffmpeg exited " + std::to_string(static_cast<int>(rc)) +
" (is it installed? --ffmpeg PATH)";
return false;
#else
const pid_t pid = fork();
if (pid < 0) {
*err = "fork failed";
Expand All @@ -110,6 +126,7 @@ bool RunMux(char** argv, int argc, std::string* err) {
*err = "ffmpeg exited " + std::to_string(WIFEXITED(st) ? WEXITSTATUS(st) : -1) +
" (is it installed? --ffmpeg PATH)";
return false;
#endif
}

// ── the worker: ONE render at a time ─────────────────────────────────────────
Expand Down
180 changes: 180 additions & 0 deletions include/vllm/support/platform_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
#pragma once

#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <limits>

#if defined(_WIN32)
#ifndef NOMINMAX
#define NOMINMAX
#endif
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <io.h>
#include <malloc.h>
#include <windows.h>
#else
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
#endif

namespace vllm::support {

inline constexpr double kPi = 3.141592653589793238462643383279502884;

#if defined(_WIN32)

inline constexpr int kWindowsBinaryOpenFlag = 0x8000;

#ifndef O_CLOEXEC
#define O_CLOEXEC 0
#endif

#ifndef O_NOFOLLOW
#define O_NOFOLLOW 0
#endif

inline int OpenFile(const char* path, int flags) {
return _open(path, flags | kWindowsBinaryOpenFlag);
}

inline int OpenFile(const char* path, int flags, int mode) {
return _open(path, flags | kWindowsBinaryOpenFlag, mode);
}

inline int CloseFile(int fd) { return _close(fd); }

inline std::intptr_t ReadFile(int fd, void* buffer, std::size_t size) {
const auto chunk = static_cast<unsigned int>(
std::min<std::size_t>(size,
static_cast<std::size_t>(
std::numeric_limits<unsigned int>::max())));
return _read(fd, buffer, chunk);
}

inline std::intptr_t WriteFile(int fd, const void* buffer, std::size_t size) {
const auto chunk = static_cast<unsigned int>(
std::min<std::size_t>(size,
static_cast<std::size_t>(
std::numeric_limits<unsigned int>::max())));
return _write(fd, buffer, chunk);
}

inline void* MapReadOnlyFile(int fd, std::size_t size) {
if (size == 0) {
return nullptr;
}
const auto os_handle = _get_osfhandle(fd);
if (os_handle == -1) {
return nullptr;
}
HANDLE mapping = CreateFileMappingA(
reinterpret_cast<HANDLE>(os_handle), nullptr, PAGE_READONLY,
static_cast<DWORD>(static_cast<std::uint64_t>(size) >> 32),
static_cast<DWORD>(static_cast<std::uint64_t>(size) & 0xffffffffu),
nullptr);
if (mapping == nullptr) {
return nullptr;
}
void* view = MapViewOfFile(mapping, FILE_MAP_READ, 0, 0, size);
CloseHandle(mapping);
return view;
}

inline int UnmapFile(void* address, std::size_t /*size*/) {
if (address == nullptr) {
return 0;
}
return UnmapViewOfFile(address) ? 0 : -1;
}

inline long HostPageSize() {
SYSTEM_INFO system_info{};
GetSystemInfo(&system_info);
return system_info.dwPageSize > 0
? static_cast<long>(system_info.dwPageSize)
: 4096L;
}

inline int CurrentProcessId() { return static_cast<int>(::GetCurrentProcessId()); }

inline int FileDescriptorFromFile(std::FILE* file) { return _fileno(file); }

inline bool TruncateFile(int fd, std::uint64_t size) { return _chsize_s(fd, size) == 0; }

inline bool SetEnvVar(const char* name, const char* value) {
return _putenv_s(name, value) == 0;
}

inline bool UnsetEnvVar(const char* name) { return _putenv_s(name, "") == 0; }

inline void* AlignedAlloc(std::size_t alignment, std::size_t size) {
return _aligned_malloc(size, alignment);
}

inline void AlignedFree(void* pointer) { _aligned_free(pointer); }

#else

inline int OpenFile(const char* path, int flags) { return ::open(path, flags); }

inline int OpenFile(const char* path, int flags, int mode) {
return ::open(path, flags, mode);
}

inline int CloseFile(int fd) { return ::close(fd); }

inline ssize_t ReadFile(int fd, void* buffer, std::size_t size) {
return ::read(fd, buffer, size);
}

inline ssize_t WriteFile(int fd, const void* buffer, std::size_t size) {
return ::write(fd, buffer, size);
}

inline void* MapReadOnlyFile(int fd, std::size_t size) {
void* mapped = ::mmap(nullptr, size, PROT_READ, MAP_PRIVATE, fd, 0);
return mapped == MAP_FAILED ? nullptr : mapped;
}

inline int UnmapFile(void* address, std::size_t size) {
if (address == nullptr) {
return 0;
}
return ::munmap(address, size);
}

inline long HostPageSize() {
const long page_size = ::sysconf(_SC_PAGESIZE);
return page_size > 0 ? page_size : 4096L;
}

inline int CurrentProcessId() { return ::getpid(); }

inline int FileDescriptorFromFile(std::FILE* file) { return ::fileno(file); }

inline bool TruncateFile(int fd, std::uint64_t size) {
return ::ftruncate(fd, static_cast<off_t>(size)) == 0;
}

inline bool SetEnvVar(const char* name, const char* value) {
return ::setenv(name, value, 1) == 0;
}

inline bool UnsetEnvVar(const char* name) { return ::unsetenv(name) == 0; }

inline void* AlignedAlloc(std::size_t alignment, std::size_t size) {
return std::aligned_alloc(alignment, size);
}

inline void AlignedFree(void* pointer) { std::free(pointer); }

#endif

} // namespace vllm::support
57 changes: 57 additions & 0 deletions include/vllm/support/test_platform_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once

#include <exception>
#include <ostream>
#include <stdexcept>
#include <string>

#include "vllm/support/platform_compat.h"

#if defined(_WIN32)

inline int setenv(const char* name, const char* value, int /*overwrite*/) {
return vllm::support::SetEnvVar(name, value) ? 0 : -1;
}

inline int unsetenv(const char* name) {
return vllm::support::UnsetEnvVar(name) ? 0 : -1;
}

inline int getpid() { return vllm::support::CurrentProcessId(); }

#endif

namespace vllm::support::test {

inline void SetEnvOrThrow(const char* name, const char* value) {
if (!vllm::support::SetEnvVar(name, value)) {
throw std::runtime_error(std::string("SetEnvVar failed: ") + name);
}
}

inline void UnsetEnvOrThrow(const char* name) {
if (!vllm::support::UnsetEnvVar(name)) {
throw std::runtime_error(std::string("UnsetEnvVar failed: ") + name);
}
}

class ScopedEnvVar {
public:
ScopedEnvVar(const char* name, const char* value) : name_(name) {
SetEnvOrThrow(name_.c_str(), value);
}

~ScopedEnvVar() {
if (!vllm::support::UnsetEnvVar(name_.c_str())) {
std::terminate();
}
}

ScopedEnvVar(const ScopedEnvVar&) = delete;
ScopedEnvVar& operator=(const ScopedEnvVar&) = delete;

private:
std::string name_;
};

} // namespace vllm::support::test
Loading