Skip to content

Instantly share code, notes, and snippets.

View dmikushin's full-sized avatar
🤓

Dmitry Mikushin dmikushin

🤓
View GitHub Profile
@dmikushin
dmikushin / jis2utf
Created January 28, 2025 23:06
Convert files from JIS (Japanese ASCII) to UTF-8 encoding
#!/usr/bin/env python3
import chardet
import argparse
import mimetypes
import sys
def is_text_file(file_path):
mime_type, _ = mimetypes.guess_type(file_path)
return mime_type is not None and mime_type.startswith('text')
@dmikushin
dmikushin / Makefile
Last active January 27, 2025 12:38
OpenMP target offload with fallback to OpenMP multithreading
LLVM_VERSION=19
ifeq ($(LLVM_VERSION),19)
CC=LIBRARY_PATH=/usr/lib/llvm-$(LLVM_VERSION)/lib clang-$(LLVM_VERSION)
else
CC=clang-$(LLVM_VERSION)
endif
.PHONY: test_gpu test_cpu
all: offload-fallback
@dmikushin
dmikushin / Makefile
Last active January 27, 2025 12:01
OpenMP target offload for multiple NVIDIA architectures
LLVM_VERSION=19
ifeq ($(LLVM_VERSION),19)
CC=LIBRARY_PATH=/usr/lib/llvm-$(LLVM_VERSION)/lib clang-$(LLVM_VERSION)
else
CC=clang-$(LLVM_VERSION)
endif
.PHONY: test
all: multi_sm_test
@dmikushin
dmikushin / encode2utf
Created January 15, 2025 08:36
Fix source file character encoding
#!/bin/bash
set -e
set -x
# Check if file name is provided
if [ -z "$1" ]
then
echo "No file name provided"
exit 1
fi
@dmikushin
dmikushin / bzr2git.sh
Created November 8, 2024 10:38
Simple Bzr to Git repository converter
#!/bin/bash
for rev in $(bzr log | grep '^revno:' | awk '{print $2}' | tac); do
bzr revert -r $rev
committer=$(bzr log -v -r$rev | grep "committer:.*" | sed "s/committer:\s*//g")
timestamp=$(bzr log -v -r$rev | grep "timestamp:.*" | sed "s/timestamp:\s*//g")
commit_message=$(bzr log -v -r$rev | sed -ne "N;s/message:\s*\n/message:/;P;D" | grep "message:.*" | sed "s/message:\s*//g")
git add .
git commit --author="$committer" --date="$timestamp" -m "$commit_message"
done
@dmikushin
dmikushin / Makefile
Created October 22, 2024 09:26
OpenMP status tests
all: test1 test2 test3
test1: openmp_check_enabled.c
gcc $< -o $@ && ./test1
test2: openmp_check_enabled.c
gcc -fopenmp $< -o $@ && ./test2
test3: openmp_check_enabled.c
gcc -fopenmp $< -o $@ && OMP_NUM_THREADS=1 ./test3
@dmikushin
dmikushin / matrix_as_graph.ipynb
Created January 29, 2024 16:48 — forked from V0XNIHILI/matrix_as_graph.ipynb
Matrix multiplication in graph form
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmikushin
dmikushin / cppminify.py
Created January 2, 2024 12:24
Minify C++ code
import re
import sys
def minify_cpp_code(code):
# Remove comments:
# Turn single-line comments into multi-line comments
code = re.sub(re.compile(r'//(.*?)\n'), '/*\\1*/', code)
# Remove multi-line comments
code = re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', code)
# Preprocessing directives must remain on separate lines.
@dmikushin
dmikushin / README.md
Created December 18, 2023 09:43
Example of using .branchtargets in PTX

Example of using .branchtargets in PTX

This code snippet demonstrates how to jump to a label by its index with brx.idx instruction.

Unlike the regular if (a == 2) { ... } else { ... } code (as well as switch (...) { ... }), the brx.idx solution avoids multiple setp.ne.s32 comparisons.

Building

> make
@dmikushin
dmikushin / match_nested.py
Created December 4, 2023 14:34
A simple python program showing how to use regular expressions to write a paren-matching recursive parser.
"""
A simple python program showing how to use regular
expressions to write a paren-matching recursive parser.
This parser recognises items enclosed by parens, brackets,
braces and <> symbols, but is adaptable to any set of
open/close patterns. This is where the re package greatly
assists in parsing.
Published by Gene Olson at