Skip to content

Instantly share code, notes, and snippets.

View hayunjong83's full-sized avatar

hayunjong83

  • Seoul National University
  • Seoul
View GitHub Profile
#include <stdio.h>
#include <stdint.h>
static __device__ __inline__ uint32_t __mysmid(){
uint32_t smid;
asm volatile("mov.u32 %0, %%smid;" : "=r"(smid));
return smid;
}
static __device__ __inline__ uint32_t __mywarpid(){
@hayunjong83
hayunjong83 / asyncAPI.cu
Last active November 1, 2019 10:11
cuda sdk sample code : 0_Simple/asyncAPI.cu
#include <stdio.h>
#include <cuda_duntime.h>
#include <helper_cuda.h>
#include <helper_functions.h>
__global__ void incermental_kernel(int *g_data, int inc_value)
{
int idx = blockIdx.x * blockDim.x + threadIdx.x;
g_data[idx] = g_data[idx] + inc_value;
}
@hayunjong83
hayunjong83 / matrixMul.cu
Created November 5, 2019 04:02
cuda sdk sample code : 0_Simple/matrixMul.cu
#include <stdio.h>
#include <assert.h>
#include <cuda_runtime.h>
#include <helper_function.h>
#include <helper_cuda.h>
template <int BLOCK_SIZE> __global__ void MatrixMulCUDA(float *C, float *A,
float *B, int wA, int wB){
//Block index
int bx = blockIdx.x;
@hayunjong83
hayunjong83 / leetcode11a.cpp
Created December 23, 2019 10:30
/leetcode 11/ container with most water - brute force : O(n^2)
class Solution{
public:
int maxArea(vector<int>& height){
int max = 0;
for(int i = 0; i < height.size()-1 ; i++){
for(int j = i+1; j < height.size() ; j++){
int vertical = 0;
if(height[i] < height[j])
vertical = height[i];
else
@hayunjong83
hayunjong83 / leetcode11b.cpp
Created December 23, 2019 10:55
/leetcode 11/ container with most water - Two Pointer Approach : O(n)
class Solution{
public:
int maxArea(verctor<int>& height){
int max = 0;
int left = 0, right = height.size()-1;
while(left < right){
max = std::max( max, std::min(height[left], height[right]) * (right - left));
if(height[left] < height[right])
left++;
else
struct Compare
{
bool operator() (ListNode* a, ListNode* b){
return a->val > b->val;
}
};
class Solution{
public:
ListNode* mergeKLists( vector<ListNode*>& lists){
@hayunjong83
hayunjong83 / first_webapp.go
Created January 9, 2020 12:26
hello world go web application
package main
import (
"fmt"
"net/http"
)
func handler(writer http.ResponseWriter, request *http.Request) {
fmt.Fprintf(writer, "Hello Go World, %s!", request.URL.Path[1:])
}
@hayunjong83
hayunjong83 / open_webcam.cpp
Last active February 14, 2020 10:26
Show live webcam by OpenCV c++.
#include <opencv2/opencv.hpp>
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main(int argv, char** argc)
{
Mat frame;
@hayunjong83
hayunjong83 / saxpy.cu
Created March 3, 2020 13:40
simple SAXPY operation
__global__ void saxpy(int n, float a, float *__restrict__ x, float *__restrict__ y)
{
int i = blockIdx.x * blockDim.x + threadIdx.x;
if( i < n )
y[i] = a * x[i] + y[i];
}
int main()
{
int N = 1 << 16;
@hayunjong83
hayunjong83 / saxpy_cublas.cu
Created March 3, 2020 14:37
SAXPY implementation with cublas library
#include <cublas.h>
int main()
{
int N = 1 << 16;
int size = N * sizeof(float);
float *h_x = (float*)malloc(size);
float *h_y = (float*)malloc(size);