Skip to content

Instantly share code, notes, and snippets.

View yashi's full-sized avatar

Yasushi SHOJI yashi

View GitHub Profile
@yashi
yashi / gist:31c0fbc9d56b44712a0ce5503715ad92
Created September 20, 2024 07:52
OpenCL Hello World with ROCm specific options
#include <stdio.h>
#include <stdlib.h>
#include <CL/cl.h>
#define VECTOR_SIZE 1024
// OpenCL kernel which is run for every work item created.
const char *saxpy_kernel =
"__kernel \n"
"void saxpy_kernel(float alpha, \n"
/*
* You need pty setup: socat -d -d pty,raw,echo=0,link=/tmp/pty1 pty,raw,echo=0,link=/tmp/pty2
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <pthread.h>
/*
* You need pty setup: socat -d -d pty,raw,echo=0,link=/tmp/pty1 pty,raw,echo=0,link=/tmp/pty2
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <pthread.h>
@yashi
yashi / CMakeLists.txt
Last active February 21, 2024 02:32
CMakeLists.txt for Python C Extension module
cmake_minimum_required(VERSION 3.20)
project(python_module)
find_package(Python3 COMPONENTS Development.Module)
#Python_add_library(hello MODULE hello.c)
add_library(hello SHARED hello.c)
target_include_directories(hello PRIVATE ${Python_INCLUDE_DIRS})
target_link_libraries(hello Python3::Module)
set_target_properties(hello PROPERTIES PREFIX "")
# When you build ROS by yourself, do NOT have multiple version of
# Python development packages (libpython3.XX-dev).
#
# Because packages in ROS use either
#
# find_package(Python3 REQUIRED COMPONENTS Development)
# or
# find_package(Python3 REQUIRED COMPONENTS Interpreter)
#
# These two give you a different version if you have a different
@yashi
yashi / boost-rolling-mean.cpp
Created January 16, 2024 04:16
Take rolling mean by using boost::accumulators
#include <iostream>
#include <vector>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>
#include <boost/accumulators/statistics/stats.hpp>
namespace ba = boost::accumulators;
int main() {
static int _zbus_message_acc_data_chan = { 42 };
static struct zbus_channel_data _zbus_chan_data_acc_data_chan = {
.observers_start_idx = -1,
.observers_end_idx = -1
};
static struct k_mutex _zbus_mutex_acc_data_chan = {
.wait_q = { { {(&(&_zbus_mutex_acc_data_chan.wait_q)->waitq)}, {(&(&_zbus_mutex_acc_data_chan.wait_q)->waitq)} } },
.owner = NULL,
#include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include <zephyr/zbus/zbus.h>
LOG_MODULE_REGISTER(app);
ZBUS_CHAN_DEFINE(acc_data_chan,
int,
NULL,
NULL, /* User data */
ZBUS_OBSERVERS(my_listener, my_subscriber),
static int foo(void)
{
return 42;
}
int main(void)
{
int val = {
foo()
};
&spi4 {
pinctrl-0 = <&spi4_sck_pe2 &spi4_miso_pe5 &spi4_mosi_pe6>;
pinctrl-names = "default";
cs-gpios = <&gpioe 4 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>;
status = "okay";
};
&spi4_sck_pe2 {
bias-pull-up;
};