Skip to content

Instantly share code, notes, and snippets.

View cako's full-sized avatar
🐢

Carlos da Costa cako

🐢
View GitHub Profile
# In-Place Memory Pinning in PyTorch
# See # https://github.com/pytorch/pytorch/issues/32167#issuecomment-753551842
#
# Copyright 2023 Carlos Alberto da Costa Filho <c.dacostaf@gmail.com>
#
# 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
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
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
# 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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "destroyed-operations",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
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)
@cako
cako / benchmark_LinearMaps_change.jl
Last active October 24, 2018 02:36
Benchmark pull request introduced to LinearMaps
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)