Skip to content

Instantly share code, notes, and snippets.

View sandeepkumar-skb's full-sized avatar
:octocat:
Get comfortable being uncomfortable

Sandeep Kumar Behera sandeepkumar-skb

:octocat:
Get comfortable being uncomfortable
View GitHub Profile
#include <iostream>
#include <stdio.h>
#define BLOCK_SIZE 16
inline void gpuAssert(cudaError_t err, const char *file, int line)
{
if (err != cudaSuccess){
printf("%s in %s at line %d\n", cudaGetErrorString(err), file, line);
exit(EXIT_FAILURE);
@sandeepkumar-skb
sandeepkumar-skb / cuda_error_check.txt
Last active January 29, 2021 23:29
cuda error check
inline void gpuAssert(cudaError_t err, const char *file, int line)
{
if (err != cudaSuccess){
printf("%s in %s at line %d\n", cudaGetErrorString(err), file, line);
exit(EXIT_FAILURE);
}
}
#define gpuErrchk(ans) \
{ \
gpuAssert((ans), __FILE__, __LINE__); \
@sandeepkumar-skb
sandeepkumar-skb / conv_bn_folding.py
Last active January 10, 2021 21:17
Folding BN into convolution
import torch
import torch.nn as nn
import copy
import torchvision.models as models
class BN_Folder():
def fold(self, model):
mymodel = copy.deepcopy(model)
mymodel.eval()
#include "omp.h"
#include <thread>
#include <iostream>
#include <vector>
#include <chrono>
void doNothing(){
int count =0;
for (int i=0; i<1000; ++i)
@sandeepkumar-skb
sandeepkumar-skb / set_thread_priority.cpp
Created November 6, 2020 01:09
Setting priority of a std::thread
#include <thread>
#include <pthread.h>
#include <iostream>
#include <cstring>
class thread : public std::thread
{
public:
static void setScheduling(std::thread &th, int priority) {
sched_param sch;
import torch
import torch.nn as nn
import time
from torch import Tensor
class Net(nn.Module):
def __init__(self, features):
super().__init__()
self.fc_layers = [nn.Linear(features, features) for _ in range(100)]
self.layers = nn.Sequential(*self.fc_layers)
@sandeepkumar-skb
sandeepkumar-skb / pybind11_example.cpp
Created October 20, 2020 03:34
PYBIND11 example
#include <pybind11/pybind11.h>
int add(int i, int j){
return i+j;
}
PYBIND11_MODULE(pybind11_example, m) {
m.doc() = "pybind11 example to add 2 integers";
m.def("add", &add, "A function to add 2 integers");
}
@sandeepkumar-skb
sandeepkumar-skb / pointwise_multi_thread_multi_stream.cu
Last active October 10, 2020 00:30
Multi-Streaming Experiments
#include <stdio.h>
#include <thread>
#include <chrono>
#include <iostream>
const int N = 1 << 20;
__global__ void kernel(float *x, int n)
{
int tid = threadIdx.x + blockIdx.x * blockDim.x;
@sandeepkumar-skb
sandeepkumar-skb / pyt_groupnorm.py
Last active October 8, 2020 20:42
GroupNorm implementation in Pytorch
import torch
import torch.nn as nn
class GroupNorm(nn.Module):
def __init__(self, num_groups, num_features, eps=1e-5):
super(GroupNorm, self).__init__()
self.weight = nn.Parameter(torch.ones(1,num_features,1,1))
self.bias = nn.Parameter(torch.zeros(1,num_features,1,1))
self.num_groups = num_groups
#include <chrono>
#include <iostream>
#include <vector>
#include <thread>
__global__ void do_nothing(int time_us, int clock_rate) {
clock_t start = clock64();
clock_t end;
for (;;) {
end = clock64();