Giter Site home page Giter Site logo

mtlpp's People

Contributors

devnulpavel avatar naleksiev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mtlpp's Issues

Triangle Example prints all zeros

Assuming the intended output is something more interesting?

randallr-mac:macos_10.12 randallr$ ./02_triangle
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

Assistance getting started with basic kernel function for parallel computation

Hi, thank you so much for your brilliant library. I’m just trying to get up and running with a very basic example. My ultimate goal will be using Metal through your library to move some computationally expensive (and “embarrassingly parallel”) operations in C++ from the CPU to the GPU.

Here is the function I have attempted to put together using your library.

void SampleMetal(){

    //SET UP METAL - device, library, command queue, command buffer, command encoder
    mtlpp::Library device = mtlpp::Device::CreateSystemDefaultDevice();
    mtlpp::Device library = device.NewDefaultLibrary();
    mtlpp::CommandQueue commandQueue = device.NewCommandQueue();
    mtlpp::CommandBuffer commandBuffer = commandQueue.CommandBuffer();
    assert(device);
    assert(library);
    assert(commandQueue);
    assert(commandBuffer);
    
    //SET UP SHADER - create function, make compute pipeline
    ns::String functionName = "doubleInputValues";
    mtlpp::Function kernelFunction =  library.NewFunction(functionName);
    assert(kernelFunction);
    ns::Error error;
    mtlpp::ComputePipelineState pipelineState = device.NewComputePipelineState(kernelFunction, &error);
    assert(pipelineState);
    
    // CREATE INPUT & OUTPUT
    int i = 50;
    std::vector<int> inputVector(i);
    mtlpp::Buffer inputBuffer = device.NewBuffer(&inputVector, sizeof(inputVector), mtlpp::ResourceOptions::CpuCacheModeDefaultCache); 
    std::vector<int> outputVector(i, 0); 
    mtlpp::Buffer outputBuffer = device.NewBuffer(&outputVector, sizeof(outputVector), mtlpp::ResourceOptions::CpuCacheModeDefaultCache); 
    assert(inputBuffer);
    assert(outputBuffer);
    
    // Create COMPUTE COMMAND CODER
    mtlpp::ComputeCommandEncoder commandEncoder = commandBuffer.ComputeCommandEncoder();
    commandEncoder.SetBuffer(inputBuffer,0,0);
    commandEncoder.SetBuffer(outputBuffer,0,1);
    assert(commandEncoder);
    commandEncoder.SetComputePipelineState(pipelineState);
    
    // Find max number of parallel threads & set up on GPU
    int threadExecutionWidth = pipelineState.GetThreadExecutionWidth();
    mtlpp::Size threadsPerGroup = mtlpp::Size(threadExecutionWidth,1,1);
    mtlpp::Size numThreadGroups = mtlpp::Size(((uint32_t)inputVector.size()+threadExecutionWidth)/threadExecutionWidth,1,1); 
    commandEncoder.DispatchThreadgroups(numThreadGroups, threadsPerGroup);
    
    //finalise
    commandEncoder.EndEncoding();
    commandBuffer.Commit();
    commandBuffer.WaitUntilCompleted();
    
    //output??
    std::string outputString((char *) outputBuffer.GetContents());
    std::cout << "output string: “ << outputString;

}

And here is the shader function:

kernel void doubleInputValues(const device float *inVector [[ buffer(0) ]], device float *outVector [[ buffer(1) ]], uint id [[ thread_position_in_grid ]]) {
    outVector[id] = 2*inVector[id];
}

I have some questions I was hoping you’d be able to help with:

  1. I can’t seem to get the right output as I couldn’t find how to parse the bytes data from your examples (as they’re all for textures as opposed to computation) - would you mind pointing me in the right direction? It currently outputs some garbage values like \360\323 and I’m not entirely sure what I’m doing wrong although I’m sure the issue is probably in the GetContents() line at the end of the SampleMetal() function.

  2. I’d be using the function as part of processing video in real time, am I supposed to set up Metal, set up the Shader etc for every frame or are there parts that only need to be created once like setting up Metal and the Shader and then just assigning input and output vectors for each video frame? I did try doing this but got a crash of EXC_BAD_ACCESS on the computeCommandEncoder pointer so wasn’t sure if it’s possible. (I know this is more of a Metal API question but I wasn’t sure if the issue was related to my incorrect implementation of your library).

  3. The entire function runs in about 4 milliseconds on an iPhone 6 plus, is that supposed to be correct or is there something I’m doing horribly inefficiently as I would have thought simply running a doubling operation on 50 values should be much less time. I’m trying to get some CPU work offloaded onto the GPU to get video processing nearer to 60fps so would like some insight on how to make this as fast as possible before I start building more complicated shaders.

Thank you very much for your help and for building this library!

Any chance for a Cmake based example?

Hi,
I am using Clion, with Cmake. I can build and execute your examples from the command line, and I added the required dependency as follows:
arget_link_libraries(DeepSleepUITarget ${OPENGL_LIBRARIES} ${CMAKE_CURRENT_SOURCE_DIR}/libs/mtlpp.o ${ARMADILLO_LIBRARIES} ${GLFW_LIB} ${Boost_LIBRARIES}

However, during runtime, I get lots of errors such as:
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Volumes/1tb-ext/2019/db/stan/Dropbox/dev2/cpp/DeepSleepGUI --target DeepSleepUITarget -- -j 8 [ 25%] Linking CXX executable DeepSleepUITarget Undefined symbols for architecture x86_64: "_CFRelease", referenced from: __ZN2ns6ObjectD2Ev in mtlpp.o __ZN2ns6ObjectaSERKS0_ in mtlpp.o __ZN2ns6ObjectaSEOS0_ in mtlpp.o "_CFRetain", referenced from: __ZN2ns6ObjectC2ERKNS_6HandleE in mtlpp.o __ZN2ns6ObjectC2ERKS0_ in mtlpp.o __ZN2ns6ObjectaSERKS0_ in mtlpp.o "_MTLCopyAllDevices", referenced from: __ZN5mtlpp6Device14CopyAllDevicesEv in mtlpp.o "_MTLCreateSystemDefaultDevice", referenced from:

I understand that I have missing flags, but not sure how/what to add them in Cmake.

Thanks,

Python wrapper

Hi,

Love the project. I was trying to wrap your code so I could use it in Python with my ML projects. Here's what I have so far: https://github.com/mattpaletta/PyMetal At the moment I believe the issue is it fails to link the metal library.

Any suggestions or improvements?
Thanks.

NSError init issue

I'm getting the message

[NSError init] called; this results in an invalid NSError instance. It will raise an exception in a future release. Please call errorWithDomain:code:userInfo: or initWithDomain:code:userInfo:. This message shown only once.

whenever I create an ns::Error and the application will crash upon calling an error member function

arc errors

If you enable arc via -fobjc-arc you get a bunch of the following errors:

../mtlpp.mm:1349:17: error: pointer to non-const type 'NSError ' with no explicit ownership
NSError
* nsErrorPtr = error ? &nsError : nullptr;

[Question] Glfw support

I was just wondering if there is GLFW support? If so is there any example code to use with glfw?

Windowed Metal App

Not sure I understand the comments about toll-free bridging? What's the best way to create a fairly minimal windowed Metal app with a render loop? The 99_view_controller.mm example seems to be missing some header files.

Integrate Unreal Engine mtlpp enhancements

Hi,
seeing commits in Unreal master branch I see:

Initial extensions to mtlpp:
- Fixed over retention of alloc-init'd objects.
- Added 10_13 & 11_0 availablity macros.
- Started, but have not yet finished adding new Metal API function wrappers.

so just saying if these will be avaiable in your repo as could be brought from Unreal mtlpp source code..

Cannot build mtlpp

I've been trying to build mtlpp with CMake and i've gotten close, but unfortunately i keep getting those weird errors :

error: expected '(' for function-style cast or type construction
            return Handle{ GetItem(index) };

There are plenty of them everywhere, any idea of why this is happening?

how to show video in metal c++

it's amazing that you did this project with metal c++ so early. now i also need to coding with metal c++, but now i get in trouble beacause there is few example(metal c++), my project is get MTLTexture from video decode by ffmpeg haedware, but i didn't find
CVPixelBufferRef in metal C++,can you give some advice?
截图

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.