Skip to content

Instantly share code, notes, and snippets.

View dfukunaga's full-sized avatar
🐨
(^o^)

Daisuke Fukunaga dfukunaga

🐨
(^o^)
View GitHub Profile
@dfukunaga
dfukunaga / warp_sum_scan.cu
Last active September 3, 2022 19:13
CUDA Warp's Sum and Scan
#include <stdio.h>
#include <thrust/device_vector.h>
#include <thrust/sequence.h>
__global__
void warpSum(int *data) {
int idx = blockIdx.x * blockDim.x + threadIdx.x;
int value = data[idx];
#pragma unroll
@dfukunaga
dfukunaga / radix.c
Created November 30, 2017 14:05
Select k-th (from LSB) radix of the number.
// Select k-th (from LSB) radix of the number.
// Author: dfukunaga (https://github.com/dfukunaga)
int radix1bit(int number, int k) {
return (number >> k) & 0b1;
}
int radix4bit(int number, int k) {
return (number >> (k << 2)) & 0xF;
}
@dfukunaga
dfukunaga / cudpp_hash_sample.cc
Created November 11, 2017 02:41
Example of CUDPP Hash Table
#include <stdio.h>
#include <cuda_runtime_api.h>
#include <cudpp_hash.h>
int main() {
const int N = 10;
// ハッシュテーブルに格納するデータ
int keys[N] = {1, 6, 4, 9, 0, 3, 7, 2, 5, 8};
int vals[N] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
@dfukunaga
dfukunaga / etcd_join.sh
Created April 27, 2017 15:08
join new member to etcd cluster
#!/bin/bash -eu
: $1 $2
LOCAL_IP=$1
REMOTE_IP=$2
set -o pipefail
INITIAL_CLUSTER=$( \
curl -s http://${REMOTE_IP}:2379/v2/members \
@dfukunaga
dfukunaga / etcd_start.sh
Created April 27, 2017 15:07
start new etcd cluster
#!/bin/bash -eu
: $1
LOCAL_IP=$1
./etcd --name ${LOCAL_IP} \
--initial-advertise-peer-urls http://${LOCAL_IP}:2380 \
--listen-peer-urls http://0.0.0.0:2380 \
--advertise-client-urls http://${LOCAL_IP}:2379 \
--listen-client-urls http://0.0.0.0:2379 \
@dfukunaga
dfukunaga / get_src_addr.cc
Last active April 16, 2017 15:39
get route source address
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <string>
std::string get_src_addr_popen(const std::string& addr) {
// assemble command string
char command[64];
@dfukunaga
dfukunaga / get_sock_addr.cc
Last active April 12, 2017 14:38
get socket's local address and foreign address
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <string>
std::string get_local_addr(int sockfd) {
struct sockaddr_in sin;
socklen_t len = sizeof(sin);
int rc = getsockname(sockfd, (struct sockaddr*)&sin, &len);
if (rc != 0) {
#include <zmq.h>
#include <chrono>
#include <iostream>
#include <string>
#include <thread>
int main(int argc, char** argv) {
if (argc != 3) {
std::cout << "Usage: " << argv[0] << " [type] [address]" << std::endl;
return 1;
@dfukunaga
dfukunaga / zmq_heartbeat_check.cc
Last active April 28, 2020 04:00
zeromq heartbeat test
#include <zmq.h>
#include <atomic>
#include <iostream>
#include <thread>
class socket_monitor {
public:
socket_monitor(void* ctx, void* socket) {
// Start monitoring
zmq_socket_monitor(socket, "inproc://monitor", ZMQ_EVENT_ALL);
@dfukunaga
dfukunaga / zmq_socket_monitor.cc
Last active March 12, 2017 04:42
zeromq socket monitor test
#include <zmq.h>
#include <atomic>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <string>
#include <thread>
double elapsed() {
static auto begin = std::chrono::system_clock::now();