Every few months the open-source community mints another AI framework. Most of them wrap Python bindings around heavy C++ kernels, or they stack abstraction layers so high that the runtime alone weighs more than the models they serve. CatAI moves in the opposite direction. It is a native AI engine written entirely in C++, built from the tensor math upward. The point is not to create yet another friendly skin over PyTorch. The point is to own every byte of memory and every cycle of compute, starting at the hardware boundary.
Why Another Engine?
If you have shipped anything to production, you already know the pain. Pull a standard deep-learning stack into a container and watch the image bloat to multiple gigabytes. Dependencies fight each other. The Python interpreter adds latency. The dispatcher that routes ops to CUDA or CPU introduces subtle overhead that becomes impossible to profile once it disappears into a dozen nested frameworks. For edge devices, embedded robotics, or latency-sensitive backends, that tax is real. A pure C++ engine eliminates the middleman. It talks to the operating system and the silicon directly, with no garbage collection, no global interpreter lock, and no serialization dance between languages.
CatAI treats this as a feature, not a compromise. The project is being written from scratch in C++ because the author wants to decide exactly how tensors live in RAM, how they move through cache hierarchies, and how kernels are scheduled across threads. That is not masochism. It is the only way to guarantee that behavior is predictable when you are squeezing performance out of limited hardware.
What “From Scratch” Actually Means
In most modern frameworks, tensor math is handled by opaque calls into vendor libraries like cuDNN, oneMKL, or MPS. That is perfectly sensible for shipping fast, but it hides the mechanics of the operation. CatAI is writing its own core tensor math and memory layouts. That means designing the fundamental data structures that hold multi-dimensional arrays, choosing how strides and offsets are calculated, and deciding whether to store data in row-major, column-major, or custom tiled formats depending on the access pattern.
This is deep systems work. When you write a matrix-multiply kernel by hand, you stop thinking in terms of torch.matmul and start thinking about L1 cache lines, register pressure, and loop tiling. You decide whether to block for 32x32 tiles or 64x64 based on the SIMD width of the target CPU. You align allocations to 64-byte boundaries so AVX-512 loads do not cross cache lines. You question whether std::vector is the right container for tensor storage, or whether a custom arena allocator gives you better locality and zero fragmentation across an entire inference graph.
Memory layout is equally critical. A naive naïve n-dimensional array can kill performance if the channels-last image data is accessed in a channels-first pattern. In CatAI, these layouts are first-class citizens, not afterthoughts handled by a graph optimizer running at export time.
The Optimization Mindset
Bare-metal optimization sounds like a buzzword until you start counting nanoseconds. It means fusing operations so intermediate results never leave the CPU registers or L1 cache. It means implementing a layer-norm followed by a GELU as a single kernel, saving an entire round-trip to DRAM. It means writing your own thread pool instead of leaning on OpenMP defaults, because you know your workload is bursty and you do not want the runtime spawning and joining threads every forward pass.
It also means understanding when not to write assembly. Sometimes the compiler vectorizes a loop better than hand-written intrinsics. The discipline ismeasurement: profile, hypothesize, change one variable, and profile again. This engine is being built by people who enjoy that grind. If you have ever spent an afternoon rewriting a convolution loop to shave two milliseconds off a batch, you already understand the culture.
Who We Need
This is not a one-person show. Building a backend from zero requires distinct skills that rarely overlap in a single brain. If you are reading this and considering whether to jump in, here is where you might fit:
C++ ডেভেলপার যারা আধুনিক স্ট্যান্ডার্ড সম্পর্কে জানেন কিন্তু টেমপ্লেট কীভাবে কম্পাইলেশন ব্লট (compilation bloat) তৈরি করতে পারে তাও বোঝেন। প্রয়োজনে আপনি র (raw) পয়েন্টার এবং যেখানে উপযুক্ত সেখানে স্মার্ট পয়েন্টার ব্যবহারে স্বাচ্ছন্দ্যবোধ করবেন এবং সিনট্যাক্স সুগারের মতোই বাইনারি সাইজ নিয়ে সচেতন থাকবেন।
গণিত বিশেষজ্ঞ যারা নন-স্ট্যান্ডার্ড অ্যাক্টিভেশনের জন্য ব্যাকওয়ার্ড-পাস গ্রেডিয়েন্ট (backward-pass gradients) নির্ণয় করতে পারেন, মিক্সড-প্রিসিশন ট্রেনিংয়ে নিউমেরিক্যাল স্ট্যাবিলিটি নিয়ে যুক্তি দিতে পারেন এবং কোড করার আগেই অ্যালগরিদম অপ্টিমাইজ করতে পারেন। আপনি যদি ব্যাখ্যা করতে পারেন কেন একটি log-sum-exp ট্রিক গুরুত্বপূর্ণ, তবে আপনি সঠিক মানসিক প্রস্তুতি সম্পন্ন।
লো-লেভেল মেমরি বিশেষজ্ঞ যারা অ্যালোকেটর, পেজ ফল্ট এবং NUMA টপোলজি নিয়ে চিন্তা করেন। গ্রাফ এক্সিকিউশনের জন্য ইঞ্জিনের মেমরি পুল, কার্নেলের জন্য স্ক্র্যাচ বাফার এবং লিক বা ফ্র্যাগমেন্টেশন ছাড়াই ট্রেনিং স্টেপগুলোর মধ্যে টেনসর স্টোরেজ পুনরায় ব্যবহারের কৌশল প্রয়োজন।
সিস্টেম ইঞ্জিনিয়ার যারা বোঝেন কীভাবে একটি ভুল syscall পুরো ট্রেনিং লুপকে থামিয়ে দিতে পারে। শিডিউলিং, I/O এবং সিনক্রোনাইজেশন প্রিমিটিভস হলো সেই আঠা যা গণিতকে একত্রিত করে রাখে।
আপনাকে এই চারটি ক্ষেত্রেই বিশ্বমানের বিশেষজ্ঞ হতে হবে না। বেশিরভাগ অবদানকারী একটি কার্নেল বা একটি অ্যালোকেটর দিয়ে কাজ শুরু করবেন এবং আর্কিটেকচারটি সুসংগঠিত হওয়ার সাথে সাথে বাকিগুলো শিখে নেবেন।
আর্কিটেকচার এবং কাস্টম ম্যাথ
ব্যাকএন্ড লজিকটি যৌথভাবে তৈরি করা হচ্ছে এবং এর শুরু হচ্ছে আর্কিটেকচার সংক্রান্ত বিতর্ক দিয়ে। ইঞ্জিনটি কি একটি স্ট্যাটিক কম্পিউটেশন গ্রাফ ব্যবহার করবে, যেখানে রানটাইমের আগে পুরো মডেলটি সংজ্ঞায়িত এবং অপ্টিমাইজ করা হয়? নাকি এটি অটোমেটিক ডিফারেন্সিয়েশনের জন্য একটি টেপসহ ইগার এক্সিকিউশন (eager execution) সমর্থন করবে? autodiff কীভাবে উপস্থাপন করা হবে—অপারেটর ওভারলোডিং, সোর্স ট্রান্সফরমেশন, নাকি একটি গ্রাফ IR? এই সিদ্ধান্তগুলো সবকিছুকে প্রভাবিত করবে।
কাস্টম নিউরাল নেট ম্যাথ মানে শুধু স্ট্যান্ডার্ড লেয়ারগুলো পুনরায় ইমপ্লিমেন্ট করা নয়। এর মানে হলো নতুন লেয়ার উদ্ভাবন করার স্বাধীনতা। আপনি যদি একটি নন-স্ট্যান্ডার্ড স্পার্স কার্নেল সহ কনভলিউশন ভেরিয়েন্ট বা এমন কোনো অ্যাক্টিভেশন ফাংশন চান যার কোনো নাম নেই, তবে আপনি C++ ফরোয়ার্ড এবং ব্যাকওয়ার্ড পাস লিখবেন এবং সরাসরি ইঞ্জিনে যুক্ত করবেন। এখানে লড়াই করার মতো কোনো Python API নেই, কোনো monkey-patching করার প্রয়োজন নেই। গণিতই হলো কোড, আর কোডই হলো ইন্টারফেস।
কীভাবে যুক্ত হবেন
যদি এটি আপনার ভালো লাগে, তবে প্রজেক্টের সম্পূর্ণ বিবরণ এবং বর্তমান রোডম্যাপ লেখকের Dev.to পোস্টে বিস্তারিতভাবে নথিভুক্ত করা আছে। আপনি সেখান থেকে সুনির্দিষ্ট বিষয়গুলো পড়তে পারেন, এখন পর্যন্ত কী কী তৈরি করা হয়েছে তা দেখতে পারেন এবং ঠিক কোথায় সাহায্যের প্রয়োজন তা বুঝতে পারেন।
প্রজেক্টের বিবরণ: https://dev.to/banana_cool/building-a-native-c-ai-engine-catai-from-scratch-looking-for-collaborators-l8m
যারা সাথে থাকতে চান, প্রশ্ন করতে চান বা অবিলম্বে কোনো pull request না দিয়ে প্রজেক্টের অগ্রগতি দেখতে চান, তাদের জন্য একটি টেলিগ্রাম গ্রুপ রয়েছে।
কমিউনিটি: https://t.me/GyaanSetuAi
আসল শিক্ষা
আধুনিক AI স্ট্যাক একটি ব্ল্যাক বক্স হয়ে দাঁড়িয়েছে। আমরা ফ্রেমওয়ার্কগুলোকে জাদুকরী যন্ত্রের মতো দেখি: ডেটা ইনপুট দেওয়া হয়, মডেল আউটপুট আসে, এবং আমরা আশা করি যে এই অস্পষ্টতা আমাদের ডেপ্লয়মেন্টের সময় সমস্যায় ফেলবে না। CatAI সেই আরাম প্রত্যাখ্যান করে। এভাবে তৈরি করা ধীরগতির। আপনাকে আরও বেশি কোড লিখতে হবে, আরও বেশি segfault ডিবাগ করতে হবে এবং উচ্চ-স্তরের ফ্রেমওয়ার্কগুলো যা আপনার কাছ থেকে লুকিয়ে রাখে সেই ধারণাগুলো নিয়ে পুনরায় ভাবতে হবে। কিন্তু আপনি এটাও বুঝতে পারবেন কেন মেশিনটি এভাবে আচরণ করে। এমন একটি শিল্পে যেখানে সবাই হার্ডওয়্যারকে অ্যাবস্ট্রাক্ট করার প্রতিযোগিতায় লিপ্ত, সেখানে উল্টো দিকে গিয়ে সরাসরি হার্ডওয়্যারের (touching the metal) সাথে কাজ করার প্রকৃত মূল্য রয়েছে। এই উপলব্ধিই একজন API কলকারী এবং একজন সিস্টেম নির্মাতা—এই দুইয়ের মধ্যে পার্থক্য তৈরি করে।
