Skip to content

Instantly share code, notes, and snippets.

View ThomasParistech's full-sized avatar
🚴

Thomas Rouch ThomasParistech

🚴
View GitHub Profile
import time
from multiprocessing.sharedctypes import Synchronized
from multiprocessing.synchronize import Event as EventClass
import nvidia_smi # nvidia-ml-py3
from medium_utils import get_pid_ram_used_bytes
from medium_utils import get_total_ram_available_bytes
from medium_utils import get_total_ram_used_bytes
import inspect
import os
from functools import wraps
from typing import Any
from typing import Callable
from typing import cast
from typing import TypeVar
def get_function_name(func: Callable) -> str:
import os
from multiprocessing import Event
from multiprocessing import Process
from multiprocessing import Value
from multiprocessing.sharedctypes import Synchronized
from typing import Optional
class MemoryScope:
"""Use as context `with MemoryScope(name):`."""
def bytes2human(number: int, decimal_unit: bool = True) -> str:
"""Convert number of bytes in a human readable string.
>>> bytes2human(10000, True)
'10.00 KB'
>>> bytes2human(10000, False)
'9.77 KiB'
Args:
number (int): Number of bytes
from functools import lru_cache
import nvidia_smi
@lru_cache()
def is_gpu_available() -> bool:
"""Check if nvidia-smi is available."""
try:
nvidia_smi.nvmlInit()
nvidia_smi.nvmlShutdown()
import nvidia_smi
nvidia_smi.nvmlInit()
assert nvidia_smi.nvmlDeviceGetCount() == 1 # Assume a single GPU
handle = nvidia_smi.nvmlDeviceGetHandleByIndex(0)
gpu_info = nvidia_smi.nvmlDeviceGetMemoryInfo(handle)
total_vram = int(gpu_info.total)
used_vram = int(gpu_info.used)
import psutil
def get_total_ram_available_bytes() -> int:
"""Return the total number of bytes available on the platform."""
return int(psutil.virtual_memory().total)
def get_total_ram_used_bytes() -> int:
"""Return the number of bytes currently used on the platform."""
#include <glm/glm.hpp>
#include <GLFW/glfw3.h>
void draw_boid(const glm::vec3& position, const glm::vec3& speed) {
const glm::vec3& speed_dir = glm::normalize(speed);
const glm::vec3 color (0.5 * (1 + speed_dir.x),
0.5 * (1 + speed_dir.y),
0.5 * (1 + speed_dir.z));
glPushMatrix();
glTranslatef(position.x, position.y, position.z);
void draw_box(const glm::vec3 &scale, const glm::vec3 &color) {
glColor3f(color[0], color[1], color[2]);
glLineWidth(2.0);
glBegin(GL_QUAD_STRIP);
glNormal3f(0, 0, 1); // Face Z
glVertex3f(-scale[0], -scale[1], scale[2]);
glVertex3f(scale[0], -scale[1], scale[2]);
glVertex3f(-scale[0], scale[1], scale[2]);
glVertex3f(scale[0], scale[1], scale[2]);
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset) {
if (yoffset!=0)
camera.zoom(-yoffset);
}
void mouseButton(GLFWwindow* window, int button, int action, int mods) {
ImGuiIO& io = ImGui::GetIO();
if (io.WantCaptureMouse)
return;