This gist demonstrates how to setup a python project that process a numpy array from C language.
To compile the project, run
make all
To test it, run
make test
| //c++11 | |
| #include <cmath> | |
| #include <iostream> | |
| #include <map> | |
| #include <vector> | |
| #include <assert.h> | |
| #include <ctime> | |
| #include <cstdio> | |
| #include <functional> |
| #!/bin/bash | |
| # install CUDA Toolkit v8.0 | |
| # instructions from https://developer.nvidia.com/cuda-downloads (linux -> x86_64 -> Ubuntu -> 16.04 -> deb (network)) | |
| CUDA_REPO_PKG="cuda-repo-ubuntu1604_8.0.61-1_amd64.deb" | |
| wget http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1604/x86_64/${CUDA_REPO_PKG} | |
| sudo dpkg -i ${CUDA_REPO_PKG} | |
| sudo apt-get update | |
| sudo apt-get -y install cuda |
| // Really awesome code taken from: http://apangborn.com/2011/05/pixel-processing-using-arm-assembly/ | |
| inline static void neon_rgba_to_bgra(unsigned char *src, unsigned char *dst, int numPixels) | |
| { | |
| #ifdef __ARM_NEON__ | |
| int simd_pixels = numPixels & ~7; // round down to nearest 8 | |
| int simd_iterations = simd_pixels >> 3; | |
| int col; | |
| if(simd_iterations) { // make sure at least 1 iteration | |
| __asm__ __volatile__ ("1: \n\t" | |
| // structured load of 8 pixels into d0-d3 (64-bit) NEON registers |
| from torch.utils.data import DataLoader | |
| class InfiniteDataLoader(DataLoader): | |
| def __init__(self, *args, **kwargs): | |
| super().__init__(*args, **kwargs) | |
| # Initialize an iterator over the dataset. | |
| self.dataset_iterator = super().__iter__() | |
| def __iter__(self): |
| # Recursive dictionary merge | |
| # Copyright (C) 2016 Paul Durivage <pauldurivage+github@gmail.com> | |
| # | |
| # This program is free software: you can redistribute it and/or modify | |
| # it under the terms of the GNU General Public License as published by | |
| # the Free Software Foundation, either version 3 of the License, or | |
| # (at your option) any later version. | |
| # | |
| # This program is distributed in the hope that it will be useful, | |
| # but WITHOUT ANY WARRANTY; without even the implied warranty of |
This gist demonstrates how to setup a python project that process a numpy array from C language.
To compile the project, run
make all
To test it, run
make test
| """ | |
| Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy) | |
| BSD License | |
| """ | |
| import numpy as np | |
| # data I/O | |
| data = open('input.txt', 'r').read() # should be simple plain text file | |
| chars = list(set(data)) | |
| data_size, vocab_size = len(data), len(chars) |