This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In-Place Memory Pinning in PyTorch | |
# See # https://github.com/pytorch/pytorch/issues/32167#issuecomment-753551842 | |
# | |
# Copyright 2023 Carlos Alberto da Costa Filho <[email protected]> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the “Software”), to | |
# deal in the Software without restriction, including without limitation the | |
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | |
# sell copies of the Software, and to permit persons to whom the Software is |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pytest | |
# Test multiple dtypes at once | |
@pytest.mark.parametrize( | |
"dtype", ["int8", "int16", "float16", "float32", "float64", "float128"] | |
) | |
def test_zero(dtype): | |
# Set random seed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Tuple | |
import numpy as np | |
from numpy.core.multiarray import normalize_axis_index | |
from numpy.typing import NDArray | |
def sobel(arr: NDArray, axes: Tuple[int, int] = (-2, -1)) -> NDArray: | |
"""Compute the Sobel filter of an image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Decorator to monitor memory of CUDA kernels | |
# Good read: | |
# https://github.com/numba/nvidia-cuda-tutorial/#session-5-memory-management | |
import gc | |
import numpy as np | |
from numba import cuda | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "destroyed-operations", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import matplotlib.pyplot as plt\n", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using LinearMaps | |
using Test | |
function f1(source) | |
dest = zeros(9) | |
tmp = reshape(source, 5, 2) | |
return dest | |
end | |
function f2(source) | |
dest = zeros(6) | |
tmp = reshape(source, 3, 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BenchmarkTools | |
using Statistics | |
using Plots | |
_flags(A::Array) = unsafe_load(convert(Ptr{UInt16}, pointer_from_objref(A)), 9) | |
_isshared(A::Array) = !(_flags(A) & 0x4000 == 0x0000) | |
function create_and_resize_flag(n) | |
a = Array{Float64}(undef, 1000) | |
if !_isshared(a) |
NewerOlder