Skip to content

Instantly share code, notes, and snippets.

View apowers313's full-sized avatar

Adam Powers apowers313

View GitHub Profile
@apowers313
apowers313 / env_prefix_bug.py
Last active January 22, 2025 05:35
Reproduction of a Pydantic Setting bug where environment variables don't parse variables without prefixes
import os
from pydantic import BaseModel, ValidationError
from pydantic_settings import BaseSettings, SettingsConfigDict
class Config(BaseSettings):
model_config = SettingsConfigDict(env_prefix='my_prefix_', env_file=".env", extra="forbid")
foo: list[str]
@apowers313
apowers313 / attr_bug.py
Created October 20, 2024 23:53
CUDA Python cuDeviceGetAttribute can't get attribute CU_DEVICE_ATTRIBUTE_D3D12_CIG_SUPPORTED
from cuda import cuda
# Error checking helper
def checkCudaErrors(result):
def _cudaGetErrorEnum(error):
if isinstance(error, cuda.CUresult):
err, name = cuda.cuGetErrorName(error)
return name if err == cuda.CUresult.CUDA_SUCCESS else "<unknown>"
elif isinstance(error, nvrtc.nvrtcResult):
@apowers313
apowers313 / graph_lost_memory.py
Last active October 13, 2024 14:39
Demonstration of Running a CUDA Python Graph Glitch (Bug?)
# type: ignore
import ctypes
from typing import Any
import numpy as np
from cuda import cuda, cudart, nvrtc
do_bug = True
@apowers313
apowers313 / graph_two_node.py
Created October 10, 2024 14:23
CUDA Python Two Node Graph - Memcpy and Kernel with Arguments
import ctypes
from typing import Any
import numpy as np
from cuda import cuda, cudart, nvrtc
cuda_code = """
extern "C" __global__ void simple(char *str) {
printf("this is a test\\n");
printf("passed argument was: %s\\n", str);
@apowers313
apowers313 / simple_graph_with_arg.py
Created October 10, 2024 14:20
CUDA Python Simple Graph With Argument
import ctypes
from typing import Any
import numpy as np
from cuda import cuda, cudart, nvrtc
cuda_code = """
extern "C" __global__ void simple(char *str) {
printf("this is a test\\n");
printf("passed argument was: %s\\n", str);
@apowers313
apowers313 / simple_graph.py
Created October 10, 2024 14:19
CUDA Python Simple Graph
from typing import Any
import numpy as np
from cuda import cuda, cudart, nvrtc
cuda_code = """
extern "C" __global__ void simple() {
printf("this is a test\\n");
}
"""
@apowers313
apowers313 / simple_kernel_with_arg.py
Created October 10, 2024 14:19
CUDA Python Simple Kernel With Argument
import ctypes
from typing import Any
import numpy as np
from cuda import cuda, cudart, nvrtc
cuda_code = """
extern "C" __global__ void simple(char *str) {
printf("this is a test\\n");
printf("passed argument was: %s\\n", str);
@apowers313
apowers313 / example.py
Created October 10, 2024 14:17
CUDA Python Example
# type: ignore
import numpy as np
from cuda import cuda, nvrtc
def _cudaGetErrorEnum(error):
if isinstance(error, cuda.CUresult):
err, name = cuda.cuGetErrorName(error)
return name if err == cuda.CUresult.CUDA_SUCCESS else "<unknown>"
@apowers313
apowers313 / simple_kernel.py
Created October 10, 2024 14:17
CUDA Python Simple Kernel
from typing import Any
import numpy as np
from cuda import cuda, cudart, nvrtc
cuda_code = """
extern "C" __global__ void simple() {
printf("this is a test\\n");
}
"""
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.