--

User defined. What I typically do is 1) add some sensible defaults to the top of my shader code so that I can use a precompiled library if I choose:

#ifndef THREADS_PER_THREADGROUP

#define THREADS_PER_THREADGROUP (256)

#endif

#ifndef VALUES_PER_THREAD

#define VALUES_PER_THREAD (4)

#endif

and 2) when I want to compile a custom library at compile time, do that via compilation options:

MTLCompileOptions* options = [[MTLCompileOptions alloc] init];

options.preprocessorMacros = @{@"THREADS_PER_THREADGROUP" : @(threadsPerThreadgroup),

@"VALUES_PER_THREAD" : @(valuesPerThread)};

id<MTLLibrary> library = [self.device newLibraryWithSource:sourceString options:options error:&error];

This way, I can have a different, optimized set of parameters if I am on an architecture where 256X4 isn't the fastest...

Thanks for reading!

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Matthew Kieber-Emmons
Matthew Kieber-Emmons

Written by Matthew Kieber-Emmons

Building teams, catalysts, software, and supportive/inclusive environments. Currently a chemistry prof at Cedar Crest College.

Responses (1)

Write a response